]> gitweb.factorcode.org Git - factor.git/blob - core/hashtables/wrapped/wrapped.factor
core: whoops, all these moves got missed.
[factor.git] / core / hashtables / wrapped / wrapped.factor
1 ! Copyright (C) 2011 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: accessors arrays assocs hashtables kernel sequences
5 vocabs.loader ;
6 IN: hashtables.wrapped
7
8 TUPLE: wrapped-hashtable
9     { underlying hashtable read-only } ;
10
11 GENERIC: wrap-key ( key wrapped-hash -- wrapped-key )
12
13 <PRIVATE
14
15 : wrapper@ ( key wrapped-hash -- wrapped-key hash )
16     [ wrap-key ] [ nip underlying>> ] 2bi ; inline
17
18 PRIVATE>
19
20 M: wrapped-hashtable at*
21     wrapper@ at* ; inline
22
23 M: wrapped-hashtable clear-assoc
24     underlying>> clear-assoc ; inline
25
26 M: wrapped-hashtable delete-at
27     wrapper@ delete-at ; inline
28
29 M: wrapped-hashtable assoc-size
30     underlying>> assoc-size ; inline
31
32 M: wrapped-hashtable set-at
33     wrapper@ set-at ; inline
34
35 M: wrapped-hashtable >alist
36     underlying>> >alist [
37         [ 0 swap [ underlying>> ] change-nth ] each
38     ] keep ;
39
40 M: wrapped-hashtable keys
41     underlying>> keys [ underlying>> ] map! ;
42
43 M: wrapped-hashtable values
44     underlying>> values ;
45
46 M: wrapped-hashtable equal?
47     over wrapped-hashtable? [ [ underlying>> ] same? ] [ 2drop f ] if ;
48
49 INSTANCE: wrapped-hashtable assoc
50
51 { "hashtables.wrapped" "prettyprint" } "hashtables.wrapped.prettyprint" require-when