{ $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." } ;
+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)." } ;
+
HELP: dlist-find
{ $values { "dlist" { $link dlist } } { "quot" quotation } { "obj/f" { $maybe object } } { "?" boolean } }
{ $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." }
} ;
HELP: dlist-filter
-{ $values { "dlist" { $link dlist } } { "quot" quotation } { "dlist'" { $link dlist } } }
+{ $values { "dlist" dlist } { "quot" quotation } { "dlist'" dlist } }
{ $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" } } ;
-HELP: dlist-any?
-{ $values { "dlist" { $link dlist } } { "quot" quotation } { "?" boolean } }
-{ $description "Just like " { $link dlist-find } " except it doesn't return the object." }
+HELP: dlist-length
+{ $values { "dlist" dlist } { "n" "a non-negative number" } }
+{ $description "Calculates the length of the linked list." }
{ $notes "This operation is O(n)." } ;
HELP: delete-node-if*
! Copyright (C) 2007, 2009 Mackenzie Straight, Doug Coleman,
! Slava Pestov, John Benediktsson.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays combinators combinators.short-circuit
-deques fry hashtables kernel math.order parser search-deques
-sequences summary vocabs.loader ;
+USING: accessors combinators combinators.short-circuit deques fry
+hashtables kernel kernel.private math math.order parser search-deques
+sequences vocabs.loader ;
IN: dlists
TUPLE: dlist-link
M: dlist clear-deque
f >>front f >>back drop ;
+: dlist-length ( dlist -- n )
+ 0 swap [
+ drop { fixnum } declare 1 + f
+ ] dlist-find-node drop ; flushable
+
: dlist-each ( ... dlist quot: ( ... value -- ... ) -- ... )
'[ obj>> @ ] dlist-each-node ; inline