]> gitweb.factorcode.org Git - factor.git/blob - core/hash-sets/hash-sets.factor
Moving new-sets to sets
[factor.git] / core / hash-sets / hash-sets.factor
1 ! Copyright (C) 2010 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs hashtables kernel sets
4 sequences parser ;
5 QUALIFIED: sets
6 IN: hash-sets
7
8 ! In a better implementation, less memory would be used
9 TUPLE: hash-set { table hashtable read-only } ;
10
11 : <hash-set> ( members -- hash-set )
12     [ dup ] H{ } map>assoc hash-set boa ;
13
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
19 M: hash-set set-like
20     drop dup hash-set? [ members <hash-set> ] unless ;
21 M: hash-set clone
22     table>> clone hash-set boa ;
23
24 M: sequence fast-set <hash-set> ;
25 M: f fast-set drop H{ } clone hash-set boa ;
26
27 M: sequence duplicates
28     HS{ } clone [ [ in? ] [ adjoin ] 2bi ] curry filter ;