A VList is a data structure very similar to a normal Scheme List but the
corresponding operations are significantly faster for most of the List
operations. Indexing and length operations have a running time of
O(1) and O(lg N) respectively compared to
O(N) in lists. The data structure has been described in the
paper Fast Functional Lists, Hash-Lists, vlists and
Variable Length Arrays by Phil Bagwell.
VLists implementation internally uses Skew Binary Random Access List.
A vlist type A.
Function
list creates a vlist with the given inputs.
Example:
#(struct:Base ((U (Base Positive-Byte) Null) (Listof Positive-Byte)))
In the above example, the vlist obtained will have 1 as its first element.
An empty vlist.
Function
empty? checks if the given vlist is empty or not.
Examples:
Function
cons takes an element and a vlist and adds
the given element to the vlist.
Example:
#(struct:Base ((U (Base Positive-Byte) Null) (Listof Positive-Byte)))
In the above example, cons adds the element 10 to
(list 123456) and returns (list 10123456).
Function
first takes a vlist and gives the first element
of the given vlist if vlist is not empty else throws an error.
Examples:
- : Integer [more precisely: Positive-Byte]
first: given vlist is empty
Function
last takes a vlist and gives the last element in the
vlist if vlist is not empty else throws an error.
Examples:
- : Integer [more precisely: Positive-Byte]
last: given vlist is empty
Function
rest takes a vlist and returns a vlist without the
first element if the given vlist is not empty. Else throws an error.
Examples:
#(struct:Base ((U (Base Positive-Byte) Null) (Listof Positive-Byte)))
rest: given vlist is empty
In the above example, (rest (list 123456)), removes the head
and returns (list 23456).
Function
list-ref takes a vlist and an index(say n) and gives
the nth element of the given vlist
Examples:
- : Integer [more precisely: Positive-Byte]
- : Integer [more precisely: Positive-Byte]
list-ref: given index out of bounds
Function
length takes a vlist and gives the number of elements in
the given vlist.
Examples:
Function
->list takes a vlist and returns a normal
scheme list.
Examples:
- : (Listof Positive-Byte)
Function
reverse takes a vlist and returns a reversed vlist.
Example:
- : (Listof Positive-Byte)
Function
map is similar to
map for lists.
Examples:
- : (Listof Positive-Index)
- : (Listof Positive-Index)
In the above example, (map add1(list 123456)) adds 1 to
each element of the given vlist and returns (list 234567).
(map *(list 123456)(list 123456)) multiplies
corresponding elements in the two vlists
and returns the vlist (list 149162536).
( foldl funcinitvlst1vlst2...)→C
func:(CAB...B->C)
init:C
foldl currently does not produce correct results when the
given function is non-commutative.
Examples:
- : Integer [more precisely: Nonnegative-Integer]
- : Integer [more precisely: Positive-Integer]
( foldr funcinitvlst1vlst2...)→C
func:(CAB...B->C)
init:C
foldr currently does not produce correct results when the
given function is non-commutative.
Examples:
- : Integer [more precisely: Nonnegative-Integer]
- : Integer [more precisely: Positive-Integer]
( andmap funclst1lst2...)→Boolean
func:(AB...B->Boolean)
Examples:
( ormap funclst1lst2...)→Boolean
func:(AB...B->Boolean)
Examples:
size:Natural
func:(Natural->A)
Examples:
- : (Listof Positive-Byte)
Examples:
> (definevlst(list 123456)) - : (Listof Positive-Byte)
- : (Listof Positive-Byte)
- : (Listof Positive-Byte)
Function
second returns the second element of the list.
Example:
1- : Integer [more precisely: Positive-Byte]
Function
third returns the third element of the list.
Example:
2- : Integer [more precisely: Positive-Byte]
Function
fourth returns the fourth element of the list.
Example:
- : Integer [more precisely: Positive-Byte]
Function
fifth returns the fifth element of the list.
Example:
- : Integer [more precisely: Positive-Byte]
Function
sixth returns the sixth element of the list.
Example:
- : Integer [more precisely: Positive-Byte]
Function
seventh returns the seventh element of the list.
Example:
- : Integer [more precisely: Positive-Byte]
Function
eighth returns the eighth element of the list.
Example:
- : Integer [more precisely: Positive-Byte]
Function
ninth returns the ninth element of the list.
Example:
- : Integer [more precisely: Positive-Byte]
Function
tenth returns the tenth element of the list.
Example:
- : Integer [more precisely: Positive-Byte]