((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/vlist" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "egg")) (section 2 "vlist" (p "Implementation of vlists, a functional list-like  data structure.") (toc)) (section 2 "Usage" (p "(require-extension vlist)")) (section 2 "Documentation" (p "The " (tt "vlist") " library provides an implementations of vlists, a functional list-like data structure described by Phil Bagwell in \"Fast Functional Lists, Hash-Lists, Dequeues and Variable-Length Arrays\", EPFL Technical Report, 2002.") (p "The idea is to store vlist elements in increasingly large contiguous blocks (implemented as vectors here).  These blocks are linked to one another using a pointer to the next block (called `block-base' here) and an offset within that block (`block-offset' here).  The size of these blocks form a geometric series with ratio `block-growth-factor'.") (p "In the best case (e.g., using a vlist returned by `list->vlist'), elements from the first half of an N-element vlist are accessed in O(1) (assuming `block-growth-factor' is 2), and `vlist-length' takes only O(ln(N)).  Furthermore, the data structure improves data locality since vlist elements are adjacent, which plays well with caches.") (section 3 "List procedures" (def (sig (procedure "vlist? x -> boolean" (id vlist?))) (p "Returns " (tt "#t") " if " (tt "x") " is a vlist, " (tt "#f") " otherwise.")) (def (sig (procedure "vlist-cons item vlist -> vlist" (id vlist-cons))) (p "Creates a new vlist with " (tt "item") " as its head and " (tt "vlist") " as its tail.")) (def (sig (procedure "vlist-head vlist -> value" (id vlist-head))) (p "Returns the head of " (tt "vlist") ".")) (def (sig (procedure "vlist-tail vlist -> vlist" (id vlist-tail))) (p "Return the tail of " (tt "vlist") ".")) (def (sig (procedure "vlist-null? vlist -> boolean" (id vlist-null?))) (p "Returns true if " (tt "vlist") " is empty, false otherwise.")) (def (sig (procedure "list->vlist lst" (id list->vlist))) (p "Returns a new vlist whose contents correspond to " (tt "lst") ".")) (def (sig (procedure "vlist-fold proc init vlist" (id vlist-fold))) (p "Fold over " (tt "vlist") ", calling " (tt "proc") " for each element.")) (def (sig (procedure "vlist-fold-right proc init vlist" (id vlist-fold-right))) (p "Fold over " (tt "vlist") ", calling " (tt "proc") " for each element, starting from the last element.")) (def (sig (procedure "vlist-reverse vlist" (id vlist-reverse))) (p "Returns a new " (tt "vlist") " whose content are those of " (tt "vlist") " in reverse order.")) (def (sig (procedure "vlist-map proc vlist" (id vlist-map))) (p "Maps " (tt "proc") " over the elements of " (tt "vlist") " and return a new vlist.")) (def (sig (procedure "vlist->list vlist -> list" (id vlist->list))) (p "Return a new list containing the elements of " (tt "vlist") ".")) (def (sig (procedure "vlist-ref vlist index -> value" (id vlist-ref))) (p "Returns the element at index " (tt "index") " in " (tt "vlist") ".")) (def (sig (procedure "vlist-drop vlist count -> vlist" (id vlist-drop))) (p "Returns a new vlist that does not contain the " (tt "count") " first elements of " (tt "vlist") ".")) (def (sig (procedure "vlist-take vlist count -> vlist" (id vlist-take))) (p "Returns a new vlist that contains only the " (tt "count") " first elements of " (tt "vlist") ".")) (def (sig (procedure "vlist-filter pred vlist -> vlist" (id vlist-filter))) (p "Returns a new vlist containing all the elements from " (tt "vlist") " that satisfy " (tt "pred") ".")) (def (sig (procedure "vlist-delete x vlist [equal?] -> vlist" (id vlist-delete))) (p "Returns a new vlist corresponding to " (tt "vlist") " without the elements " (tt "equal?") " to " (tt "x") ".")) (def (sig (procedure "vlist-length vlist -> number" (id vlist-length))) (p "Returns the length of " (tt "vlist") ".")) (def (sig (procedure "vlist-unfold p f g seed [tail-gen] -> vlist" (id vlist-unfold))) (p "vlist constructor.  Analogous to SRFI-1 `unfold'.")) (def (sig (procedure "vlist-unfold-right p f g seed [tail] -> vlist" (id vlist-unfold-right))) (p "vlist constructor.  Analogous to SRFI-1 `unfold-right'.")) (def (sig (procedure "vlist-append vlists1 .. vlistn -> vlist" (id vlist-append))) (p "Appends the given vlists.")) (def (sig (procedure "vlist-for-each proc vlist -> unspecified" (id vlist-for-each))) (p "Calls " (tt "proc") " on each element of " (tt "vlist") "."))) (section 3 "Hash list procedures" (p "Hash vlists are analogous to association lists.") (def (sig (procedure "vhash? obj -> boolean" (id vhash?))) (p "Returns true if " (tt "obj") " is a hash vlist, false otherwise.")) (def (sig (procedure "vhash-cons key value vhash [hash] -> vhash" (id vhash-cons)) (procedure "vhash-consq key value vhash [hash] -> vhash" (id vhash-consq)) (procedure "vhash-consv key value vhash [hash] -> vhash" (id vhash-consv))) (p "Return a new hash list based on " (tt "vhash") " where " (tt "key") " is associated with " (tt "value") ".  Use " (tt "hash") " to compute " (tt "key") "'s hash.")) (def (sig (procedure "vhash-fold* proc init key vhash -> value" (id vhash-fold*))) (p "Folds over all the values associated with " (tt "key") " in " (tt "vhash") ", with each call to " (tt "proc") " having the form " (tt "(proc value result)") ", where " (tt "result") " is the result of the previous call to " (tt "proc") " and " (tt "init") " the value of " (tt "result") " for the first call to " (tt "proc") ".")) (def (sig (procedure "vhash-foldq* proc init key vhash -> value" (id vhash-foldq*))) (p "Same as " (tt "vhash-fold*") ", but using " (tt "eq?-hash") " and " (tt "eq?") ".")) (def (sig (procedure "vhash-foldv* proc init key vhash -> value" (id vhash-foldv*))) (p "Same as " (tt "vhash-fold*") ", but using " (tt "eqv?-hash") " and " (tt "eqv?") ".")) (def (sig (procedure "vhash-assoc key vhash [equal?] [hash] -> (key . value)" (id vhash-assoc))) (p "Returns the first key/value pair from " (tt "vhash") " whose key is equal to " (tt "key") " according to the " (tt "equal?") " equality predicate.")) (def (sig (procedure "vhash-assq key vhash -> (key . value)" (id vhash-assq))) (p "Returns the first key/value pair from " (tt "vhash") " whose key is " (tt "eq?") " to " (tt "key") ".")) (def (sig (procedure "vhash-assv key vhash -> (key . value)" (id vhash-assv))) (p "Returns the first key/value pair from " (tt "vhash") " whose key is " (tt "eqv?") " to " (tt "key") ".")) (def (sig (procedure "vhash-delete key vhash [equal?] [hash] -> vhash" (id vhash-delete)) (procedure "vhash-delq key vhash [equal?] [hash] -> vhash" (id vhash-delq)) (procedure "vhash-delv key vhash [equal?] [hash] -> vhash" (id vhash-delv))) (p "Removes all associations from " (tt "vhash") " with " (tt "key") ", comparing keys with " (tt "equal?") ".")) (def (sig (procedure "vhash-fold proc init vhash" (id vhash-fold))) (p "Folds over the key/pair elements of " (tt "vhash") " from left to right, with each call to " (tt "proc") " having the form " (tt "(proc key value result)") ", where " (tt "result") " is the result of the previous call to " (tt "proc") " and " (tt "init") " the value of " (tt "result") " for the first call to " (tt "proc") ".")) (def (sig (procedure "vhash-fold-right proc init vhash" (id vhash-fold-right))) (p "Folds over the key/pair elements of " (tt "vhash") " from right to left, with each call to " (tt "proc") " having the form " (tt "(proc key value result)") ", where " (tt "result") " is the result of the previous call to " (tt "proc") " and " (tt "init") " the value of " (tt "result") " for the first call to " (tt "proc") ".")) (def (sig (procedure "alist->vhash alist [hash] -> vhash" (id alist->vhash))) (p "Returns the vhash corresponding to " (tt "alist") ", an association list.")))) (section 2 "Examples") (section 2 "About this egg" (section 3 "Author" (p (int-link "/users/ivan-raikov" "Ivan Raikov"))) (section 3 "Version history" (dl (dt "1.0") (dd "Initial release"))) (section 3 "License" (pre "The vlist library was written by Ludovic Courtès and adapted for\nChicken Scheme by Ivan Raikov.\n\n Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.\n Chicken Scheme modifications Copyright 2012 Ivan Raikov.\n\nThis library is free software; you can redistribute it and/or\nmodify it under the terms of the GNU Lesser General Public\nLicense as published by the Free Software Foundation; either\nversion 3 of the License, or (at your option) any later version.") (pre "This library is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\nLesser General Public License for more details.\n\nA full copy of the Lesser GPL license can be found at\n<http://www.gnu.org/licenses/>."))))