1 ! Copyright (C) 2013 John Benediktsson.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors hash-sets hash-sets.wrapped kernel parser
4 sequences sets sets.private vocabs.loader ;
9 TUPLE: identity-wrapper
10 { underlying read-only } identity-hashcode ;
12 : <identity-wrapper> ( wrapped-key -- identity-wrapper )
13 dup identity-hashcode identity-wrapper boa ; inline
15 M: identity-wrapper equal?
16 over identity-wrapper?
17 [ [ underlying>> ] bi@ eq? ]
18 [ 2drop f ] if ; inline
20 M: identity-wrapper hashcode* nip identity-hashcode>> ; inline
24 TUPLE: identity-hash-set < wrapped-hash-set ;
26 : <identity-hash-set> ( n -- ihash-set )
27 <hash-set> identity-hash-set boa ; inline
29 M: identity-hash-set wrap-key drop <identity-wrapper> ;
31 M: identity-hash-set clone
32 underlying>> clone identity-hash-set boa ; inline
34 : >identity-hash-set ( members -- ihash-set )
35 [ <identity-wrapper> ] map >hash-set identity-hash-set boa ; inline
37 M: identity-hash-set set-like
38 drop dup identity-hash-set? [ ?members >identity-hash-set ] unless ; inline
40 SYNTAX: IHS{ \ } [ >identity-hash-set ] parse-literal ;
42 USE-WHEN-LOADED: hash-sets.identity.prettyprint { "hash-sets.identity" "prettyprint" }