factor/core/hash-sets/hash-sets.factor

29 lines
862 B
Factor
Raw Normal View History

2010-02-26 11:01:57 -05:00
! Copyright (C) 2010 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
2010-02-26 16:01:01 -05:00
USING: accessors assocs hashtables kernel sets
2010-02-26 11:01:57 -05:00
sequences parser ;
QUALIFIED: sets
IN: hash-sets
! In a better implementation, less memory would be used
TUPLE: hash-set { table hashtable read-only } ;
: <hash-set> ( members -- hash-set )
[ dup ] H{ } map>assoc hash-set boa ;
INSTANCE: hash-set set
M: hash-set in? table>> key? ; inline
M: hash-set adjoin table>> dupd set-at ; inline
M: hash-set delete table>> delete-at ; inline
M: hash-set members table>> keys ; inline
M: hash-set set-like
drop dup hash-set? [ members <hash-set> ] unless ;
M: hash-set clone
table>> clone hash-set boa ;
M: sequence fast-set <hash-set> ;
2010-02-26 13:24:26 -05:00
M: f fast-set drop H{ } clone hash-set boa ;
M: sequence duplicates
f fast-set [ [ in? ] [ adjoin ] 2bi ] curry filter ;