Update Unicode docs
[factor/jcg.git] / basis / search-deques / search-deques.factor
blob5546a9766dd86eb48f34ac9538b5a4bcbd286938
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel assocs deques ;
4 IN: search-deques
6 TUPLE: search-deque assoc deque ;
8 C: <search-deque> search-deque
10 M: search-deque deque-empty? deque>> deque-empty? ;
12 M: search-deque peek-front deque>> peek-front ;
14 M: search-deque peek-back deque>> peek-back ;
16 M: search-deque push-front*
17     2dup assoc>> at* [ 2nip ] [
18         drop
19         [ deque>> push-front* ] [ assoc>> ] 2bi
20         [ 2drop ] [ set-at ] 3bi
21     ] if ;
23 M: search-deque push-back*
24     2dup assoc>> at* [ 2nip ] [
25         drop
26         [ deque>> push-back* ] [ assoc>> ] 2bi
27         [ 2drop ] [ set-at ] 3bi
28     ] if ;
30 M: search-deque pop-front*
31     [ [ deque>> peek-front ] [ assoc>> ] bi delete-at ]
32     [ deque>> pop-front* ]
33     bi ;
35 M: search-deque pop-back*
36     [ [ deque>> peek-back ] [ assoc>> ] bi delete-at ]
37     [ deque>> pop-back* ]
38     bi ;
40 M: search-deque delete-node
41     [ deque>> delete-node ]
42     [ [ node-value ] [ assoc>> ] bi* delete-at ] 2bi ;
44 M: search-deque clear-deque
45     [ deque>> clear-deque ] [ assoc>> clear-assoc ] bi ;
47 M: search-deque deque-member?
48     assoc>> key? ;
50 INSTANCE: search-deque deque