2008-06-10 19:32:44 -04:00
USING: help.markup help.syntax kernel quotations
2008-11-16 06:53:25 -05:00
deques search-deques hashtables ;
2007-11-05 02:41:23 -05:00
IN: dlists
2008-06-10 19:32:44 -04:00
ARTICLE: "dlists" "Double-linked lists"
2008-08-19 15:06:20 -04:00
"A double-linked list is the canonical implementation of a " { $link deque } "."
2007-11-05 11:01:11 -05:00
$nl
2008-06-10 19:32:44 -04:00
"Double-linked lists form a class:"
2009-10-01 15:56:36 -04:00
{ $subsections
dlist
dlist?
}
2008-06-10 19:32:44 -04:00
"Constructing a double-linked list:"
2009-10-01 15:56:36 -04:00
{ $subsections <dlist> }
2008-08-19 15:06:20 -04:00
"Double-linked lists support all the operations of the deque protocol (" { $link "deques" } ") as well as the following."
2008-06-10 19:32:44 -04:00
$nl
2007-11-05 11:01:11 -05:00
"Iterating over elements:"
2009-10-01 15:56:36 -04:00
{ $subsections
dlist-each
dlist-find
dlist-filter
dlist-any?
}
2008-01-31 01:52:06 -05:00
"Deleting a node matching a predicate:"
2009-10-01 15:56:36 -04:00
{ $subsections
delete-node-if*
delete-node-if
}
2008-11-16 06:53:25 -05:00
"Search deque implementation:"
2009-10-01 15:56:36 -04:00
{ $subsections <hashed-dlist> } ;
2007-11-05 11:01:11 -05:00
ABOUT: "dlists"
2007-11-05 02:41:23 -05:00
2008-11-16 06:59:14 -05:00
HELP: <dlist>
2008-11-16 08:04:51 -05:00
{ $values { "list" dlist } }
2008-11-16 06:59:14 -05:00
{ $description "Creates a new double-linked list." } ;
HELP: <hashed-dlist>
2008-11-16 06:53:25 -05:00
{ $values { "search-deque" search-deque } }
{ $description "Creates a new " { $link search-deque } " backed by a " { $link dlist } ", with a " { $link hashtable } " for fast membership tests." } ;
2015-10-15 09:16:57 -04:00
HELP: dlist-any?
{ $values { "dlist" { $link dlist } } { "quot" quotation } { "?" boolean } }
{ $description "Just like " { $link dlist-find } " except it doesn't return the object." }
{ $notes "This operation is O(n)." } ;
2007-11-05 02:41:23 -05:00
HELP: dlist-find
2015-05-13 19:09:14 -04:00
{ $values { "dlist" { $link dlist } } { "quot" quotation } { "obj/f" { $maybe object } } { "?" boolean } }
2017-06-05 13:13:54 -04:00
{ $description "Applies the quotation to each element of the " { $link dlist } " in turn, until it outputs a true value or the end of the " { $link dlist } " is reached. Outputs either the object it found or " { $link f } ", and a boolean which is true if an object is found." }
2007-11-05 02:41:23 -05:00
{ $notes "Returns a boolean to allow dlists to store " { $link f } "."
$nl
"This operation is O(n)."
} ;
2009-05-09 21:15:03 -04:00
HELP: dlist-filter
2015-10-15 09:16:57 -04:00
{ $values { "dlist" dlist } { "quot" quotation } { "dlist'" dlist } }
2009-05-09 21:15:03 -04:00
{ $description "Applies the quotation to each element of the " { $link dlist } " in turn, removing the corresponding nodes if the quotation returns " { $link f } "." }
{ $side-effects { "dlist" } } ;
2015-10-15 09:16:57 -04:00
HELP: dlist-length
{ $values { "dlist" dlist } { "n" "a non-negative number" } }
{ $description "Calculates the length of the linked list." }
2007-11-05 02:41:23 -05:00
{ $notes "This operation is O(n)." } ;
2008-01-31 01:52:06 -05:00
HELP: delete-node-if*
2015-05-13 19:09:14 -04:00
{ $values { "dlist" { $link dlist } } { "quot" quotation } { "obj/f" { $maybe object } } { "?" boolean } }
2017-06-05 13:13:54 -04:00
{ $description "Calls " { $link dlist-find } " on the " { $link dlist } " and deletes the node returned, if any. Returns the value of the deleted node and a boolean to allow the deleted value to distinguished from " { $link f } ", for nothing deleted." }
2007-11-05 02:41:23 -05:00
{ $notes "This operation is O(n)." } ;
2008-01-31 01:52:06 -05:00
HELP: delete-node-if
2015-05-13 19:09:14 -04:00
{ $values { "dlist" { $link dlist } } { "quot" quotation } { "obj/f" { $maybe object } } }
2008-01-31 01:52:06 -05:00
{ $description "Like " { $link delete-node-if* } " but cannot distinguish from deleting a node whose value is " { $link f } " or not deleting an element." }
2007-11-05 02:41:23 -05:00
{ $notes "This operation is O(n)." } ;
HELP: dlist-each
2008-03-20 21:14:07 -04:00
{ $values { "dlist" { $link dlist } } { "quot" quotation } }
2007-11-05 02:41:23 -05:00
{ $description "Iterate a " { $link dlist } ", calling quot on each element." } ;