Adding null? word to test if a set is empty

db4
Daniel Ehrenberg 2010-04-17 16:25:51 -05:00
parent 1ae8cdc587
commit 265fe6208f
5 changed files with 16 additions and 0 deletions

View File

@ -11,6 +11,9 @@ IN: bit-sets.tests
T{ bit-set f ?{ f f t f t f } } intersect
] unit-test
[ f ] [ T{ bit-set f ?{ t f f f t f } } null? ] unit-test
[ t ] [ T{ bit-set f ?{ f f f f f f } } null? ] unit-test
[ T{ bit-set f ?{ t f t f f f } } ] [
T{ bit-set f ?{ t t t f f f } }
T{ bit-set f ?{ f t f f t t } } diff

View File

@ -31,3 +31,6 @@ IN: hash-sets.tests
[ f ] [ HS{ 1 2 3 } HS{ 2 3 } set= ] unit-test
[ HS{ 1 2 } HS{ 1 2 3 } ] [ HS{ 1 2 } clone dup clone [ 3 swap adjoin ] keep ] unit-test
[ t ] [ HS{ } null? ] unit-test
[ f ] [ HS{ 1 } null? ] unit-test

View File

@ -18,6 +18,7 @@ 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: hash-set null? table>> assoc-empty? ;
M: sequence fast-set <hash-set> ;
M: f fast-set drop H{ } clone hash-set boa ;

View File

@ -61,3 +61,6 @@ IN: sets.tests
[ f ] [ HS{ 1 2 3 1 2 1 } duplicates ] unit-test
[ H{ { 3 HS{ 1 2 } } } ] [ H{ } clone 1 3 pick adjoin-at 2 3 pick adjoin-at ] unit-test
[ t ] [ f null? ] unit-test
[ f ] [ { 4 } null? ] unit-test

View File

@ -21,10 +21,13 @@ GENERIC: subset? ( set1 set2 -- ? )
GENERIC: set= ( set1 set2 -- ? )
GENERIC: duplicates ( set -- seq )
GENERIC: all-unique? ( set -- ? )
GENERIC: null? ( set -- ? )
! Defaults for some methods.
! Override them for efficiency
M: set null? members null? ; inline
M: set set-like drop ; inline
M: set union
@ -91,6 +94,9 @@ M: sequence set-like
M: sequence members
[ pruned ] keep like ;
M: sequence null?
empty? ; inline
: combine ( sets -- set )
[ f ]