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