1 ! (c)2010 Joe Groff bsd license
2 USING: accessors assocs hashtables hashtables.wrapped kernel
4 IN: hashtables.identity
6 TUPLE: identity-wrapper < wrapped-key identity-hashcode ;
8 : <identity-wrapper> ( wrapped-key -- identity-wrapper )
9 dup identity-hashcode identity-wrapper boa ; inline
11 M: identity-wrapper equal?
12 over identity-wrapper?
13 [ [ underlying>> ] bi@ eq? ]
14 [ 2drop f ] if ; inline
16 M: identity-wrapper hashcode* nip identity-hashcode>> ; inline
18 TUPLE: identity-hashtable < wrapped-hashtable ;
20 : <identity-hashtable> ( n -- ihashtable )
21 <hashtable> identity-hashtable boa ; inline
23 M: identity-hashtable wrap-key drop <identity-wrapper> ;
25 M: identity-hashtable clone
26 underlying>> clone identity-hashtable boa ; inline
28 : identity-associate ( value key -- ihashtable )
29 2 <identity-hashtable> [ set-at ] keep ; inline
31 : >identity-hashtable ( assoc -- ihashtable )
32 [ assoc-size <identity-hashtable> ] keep assoc-union! ;
34 M: identity-hashtable assoc-like
35 drop dup identity-hashtable? [ >identity-hashtable ] unless ; inline
37 M: identity-hashtable new-assoc drop <identity-hashtable> ;
39 SYNTAX: IH{ \ } [ >identity-hashtable ] parse-literal ;
41 { "hashtables.identity" "prettyprint" } "hashtables.identity.prettyprint" require-when
42 { "hashtables.identity" "mirrors" } "hashtables.identity.mirrors" require-when