]> gitweb.factorcode.org Git - factor.git/blob - basis/dlists/dlists-docs.factor
Factor source files should not be executable
[factor.git] / basis / dlists / dlists-docs.factor
1 USING: help.markup help.syntax kernel quotations
2 deques search-deques hashtables ;
3 IN: dlists
4
5 ARTICLE: "dlists" "Double-linked lists"
6 "A double-linked list is the canonical implementation of a " { $link deque } "."
7 $nl
8 "Double-linked lists form a class:"
9 { $subsections
10     dlist
11     dlist?
12 }
13 "Constructing a double-linked list:"
14 { $subsections <dlist> }
15 "Double-linked lists support all the operations of the deque protocol (" { $link "deques" } ") as well as the following."
16 $nl
17 "Iterating over elements:"
18 { $subsections
19     dlist-each
20     dlist-find
21     dlist-filter
22     dlist-any?
23 }
24 "Deleting a node matching a predicate:"
25 { $subsections
26     delete-node-if*
27     delete-node-if
28 }
29 "Search deque implementation:"
30 { $subsections <hashed-dlist> } ;
31
32 ABOUT: "dlists"
33
34 HELP: <dlist>
35 { $values { "list" dlist } }
36 { $description "Creates a new double-linked list." } ;
37
38 HELP: <hashed-dlist>
39 { $values { "search-deque" search-deque } }
40 { $description "Creates a new " { $link search-deque } " backed by a " { $link dlist } ", with a " { $link hashtable } " for fast membership tests." } ;
41
42 HELP: dlist-find
43 { $values { "dlist" { $link dlist } } { "quot" quotation } { "obj/f" "an object or " { $link f } } { "?" "a boolean" } }
44 { $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." }
45 { $notes "Returns a boolean to allow dlists to store " { $link f } "."
46     $nl
47     "This operation is O(n)."
48 } ;
49
50 HELP: dlist-filter
51 { $values { "dlist" { $link dlist } } { "quot" quotation } { "dlist" { $link dlist } } }
52 { $description "Applies the quotation to each element of the " { $link dlist } " in turn, removing the corresponding nodes if the quotation returns " { $link f } "." }
53 { $side-effects { "dlist" } } ;
54
55 HELP: dlist-any?
56 { $values { "dlist" { $link dlist } } { "quot" quotation } { "?" "a boolean" } }
57 { $description "Just like " { $link dlist-find } " except it doesn't return the object." }
58 { $notes "This operation is O(n)." } ;
59
60 HELP: delete-node-if*
61 { $values { "dlist" { $link dlist } } { "quot" quotation } { "obj/f" "an object or " { $link f } } { "?" "a boolean" } }
62 { $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." }
63 { $notes "This operation is O(n)." } ;
64
65 HELP: delete-node-if
66 { $values { "dlist" { $link dlist } } { "quot" quotation } { "obj/f" "an object or " { $link f } } }
67 { $description "Like " { $link delete-node-if* } " but cannot distinguish from deleting a node whose value is " { $link f } " or not deleting an element." }
68 { $notes "This operation is O(n)." } ;
69
70 HELP: dlist-each
71 { $values { "dlist" { $link dlist } } { "quot" quotation } }
72 { $description "Iterate a " { $link dlist } ", calling quot on each element." } ;