1 ! Copyright (C) 2011 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3 USING: accessors assocs hashtables kernel sequences
7 TUPLE: wrapped-hashtable
8 { underlying hashtable read-only } ;
10 GENERIC: wrap-key ( key wrapped-hash -- wrapped-key )
14 : wrapper@ ( key wrapped-hash -- wrapped-key hash )
15 [ wrap-key ] [ nip underlying>> ] 2bi ; inline
19 M: wrapped-hashtable at*
22 M: wrapped-hashtable clear-assoc
23 underlying>> clear-assoc ; inline
25 M: wrapped-hashtable delete-at
26 wrapper@ delete-at ; inline
28 M: wrapped-hashtable assoc-size
29 underlying>> assoc-size ; inline
31 M: wrapped-hashtable set-at
32 wrapper@ set-at ; inline
34 M: wrapped-hashtable >alist
36 [ 0 swap [ underlying>> ] change-nth ] each
39 M: wrapped-hashtable keys
40 underlying>> keys [ underlying>> ] map! ;
42 M: wrapped-hashtable values
45 M: wrapped-hashtable equal?
46 over wrapped-hashtable? [ [ underlying>> ] same? ] [ 2drop f ] if ;
48 INSTANCE: wrapped-hashtable assoc
50 { "hashtables.wrapped" "prettyprint" } "hashtables.wrapped.prettyprint" require-when
52 ! USE-WHEN-LOADED: hashtables.wrapped.prettyprint { "hashtables.wrapped" "prettyprint" }