]> gitweb.factorcode.org Git - factor.git/commitdiff
Adding null? word to test if a set is empty
authorDaniel Ehrenberg <littledan@pool-224-36.res.carleton.edu>
Sat, 17 Apr 2010 21:25:51 +0000 (16:25 -0500)
committerDaniel Ehrenberg <littledan@pool-224-36.res.carleton.edu>
Sat, 17 Apr 2010 21:25:51 +0000 (16:25 -0500)
basis/bit-sets/bit-sets-tests.factor
core/hash-sets/hash-sets-tests.factor
core/hash-sets/hash-sets.factor
core/sets/sets-tests.factor
core/sets/sets.factor

index 4e97e703d0017fa939a617c53ad3df071cfb23bb..0d4543f8f2fa3685873e6470dc70888ca291f8d3 100644 (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
index 5b7ffafc8b9500fc4b5973fad873a727eb10080c..ca995a38e62fa69a522afde89b43a7112a2712b0 100644 (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
index 3ca2cce93ca195dc5cf1019a8ee03c6897a8bad8..ac198a2ca2023a3ce4813a991fc125b3c7f9e12d 100644 (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 ;
index e4bc762512285ec1572ffb0d410b0918da89f411..9a48acc4cfc0ef64bb85720f2e3d98a69fc2288a 100644 (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
index d279f036d4fcc8afc3719d0ab95a2fd609f21237..9c1870aa2e57634feee580262f0813bf65771b93 100644 (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 ]