]> gitweb.factorcode.org Git - factor.git/blob - basis/hashtables/identity/identity.factor
core, basis, extra: Remove DOS line endings from files.
[factor.git] / basis / hashtables / identity / identity.factor
1 ! (c)2010 Joe Groff bsd license
2 USING: accessors assocs hashtables hashtables.wrapped kernel
3 parser vocabs.loader ;
4 IN: hashtables.identity
5
6 TUPLE: identity-wrapper < wrapped-key identity-hashcode ;
7
8 : <identity-wrapper> ( wrapped-key -- identity-wrapper )
9     dup identity-hashcode identity-wrapper boa ; inline
10
11 M: identity-wrapper equal?
12     over identity-wrapper?
13     [ [ underlying>> ] bi@ eq? ]
14     [ 2drop f ] if ; inline
15
16 M: identity-wrapper hashcode* nip identity-hashcode>> ; inline
17
18 TUPLE: identity-hashtable < wrapped-hashtable ;
19
20 : <identity-hashtable> ( n -- ihashtable )
21     <hashtable> identity-hashtable boa ; inline
22
23 M: identity-hashtable wrap-key drop <identity-wrapper> ;
24
25 M: identity-hashtable clone
26     underlying>> clone identity-hashtable boa ; inline
27
28 : identity-associate ( value key -- ihashtable )
29     2 <identity-hashtable> [ set-at ] keep ; inline
30
31 : >identity-hashtable ( assoc -- ihashtable )
32     [ assoc-size <identity-hashtable> ] keep assoc-union! ;
33
34 M: identity-hashtable assoc-like
35     drop dup identity-hashtable? [ >identity-hashtable ] unless ; inline
36
37 M: identity-hashtable new-assoc drop <identity-hashtable> ;
38
39 SYNTAX: IH{ \ } [ >identity-hashtable ] parse-literal ;
40
41 { "hashtables.identity" "prettyprint" } "hashtables.identity.prettyprint" require-when
42 { "hashtables.identity" "mirrors" } "hashtables.identity.mirrors" require-when