1 ! Copyright (C) 2011 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: accessors arrays assocs hashtables kernel sequences
10 { underlying read-only } ;
12 TUPLE: wrapped-hashtable
13 { underlying hashtable read-only } ;
15 GENERIC: wrap-key ( key wrapped-hash -- wrapped-key )
19 : wrapper@ ( key wrapped-hash -- wrapped-key hash )
20 [ wrap-key ] [ nip underlying>> ] 2bi ; inline
24 M: wrapped-hashtable at*
27 M: wrapped-hashtable clear-assoc
28 underlying>> clear-assoc ; inline
30 M: wrapped-hashtable delete-at
31 wrapper@ delete-at ; inline
33 M: wrapped-hashtable assoc-size
34 underlying>> assoc-size ; inline
36 M: wrapped-hashtable set-at
37 wrapper@ set-at ; inline
39 M: wrapped-hashtable >alist
40 underlying>> >alist [ [ first underlying>> ] [ second ] bi 2array ] map ;
42 M: wrapped-hashtable equal?
43 over wrapped-hashtable? [ [ underlying>> ] same? ] [ 2drop f ] if ;
45 INSTANCE: wrapped-hashtable assoc
47 { "hashtables.wrapped" "prettyprint" } "hashtables.wrapped.prettyprint" require-when