1 ! Copyright (C) 2010 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs hashtables kernel sets
8 ! In a better implementation, less memory would be used
9 TUPLE: hash-set { table hashtable read-only } ;
11 : <hash-set> ( members -- hash-set )
12 [ dup ] H{ } map>assoc hash-set boa ;
14 INSTANCE: hash-set set
15 M: hash-set in? table>> key? ; inline
16 M: hash-set adjoin table>> dupd set-at ; inline
17 M: hash-set delete table>> delete-at ; inline
18 M: hash-set members table>> keys ; inline
20 drop dup hash-set? [ members <hash-set> ] unless ;
22 table>> clone hash-set boa ;
24 M: sequence fast-set <hash-set> ;
25 M: f fast-set drop H{ } clone hash-set boa ;
27 M: sequence duplicates
28 HS{ } clone [ [ in? ] [ adjoin ] 2bi ] curry filter ;