1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: fry kernel sequences ;
6 GENERIC: push-front* ( obj deque -- node )
7 GENERIC: push-back* ( obj deque -- node )
8 GENERIC: peek-front* ( deque -- obj ? )
9 GENERIC: peek-back* ( deque -- obj ? )
10 GENERIC: pop-front* ( deque -- )
11 GENERIC: pop-back* ( deque -- )
12 GENERIC: delete-node ( node deque -- )
13 GENERIC: deque-member? ( value deque -- ? )
14 GENERIC: clear-deque ( deque -- )
15 GENERIC: node-value ( node -- value )
16 GENERIC: deque-empty? ( deque -- ? )
20 : peek-front ( deque -- obj )
21 peek-front* [ drop empty-deque ] unless ;
23 : ?peek-front ( deque -- obj/f )
24 peek-front* [ drop f ] unless ;
26 : peek-back ( deque -- obj )
27 peek-back* [ drop empty-deque ] unless ;
29 : ?peek-back ( deque -- obj/f )
30 peek-back* [ drop f ] unless ;
32 : push-front ( obj deque -- )
33 push-front* drop ; inline
35 : push-all-front ( seq deque -- )
36 '[ _ push-front ] each ;
38 : push-back ( obj deque -- )
39 push-back* drop ; inline
41 : push-all-back ( seq deque -- )
42 '[ _ push-back ] each ;
44 : pop-front ( deque -- obj )
45 [ peek-front ] [ pop-front* ] bi ; inline
47 : pop-back ( deque -- obj )
48 [ peek-back ] [ pop-back* ] bi ; inline
50 : slurp-deque ( ... deque quot: ( ... obj -- ... ) -- ... )
51 [ drop '[ _ deque-empty? ] ]