diff ( set1 set2 -- set ) (original) (raw)
diff ( set1 set2 -- set )
Factor handbook » The language » Collections » Sets » Operations on sets
Prev: | null? ( set -- ? ) |
---|---|
Next: | intersect ( set1 set2 -- set ) |
Vocabulary
sets
Inputs
set1 | a set |
---|---|
set2 | a set |
Outputs
set | a set |
---|
Word description
Outputs a set consisting of elements present in set1 but not set2, comparing elements for equality.
This word has a default definition which works for all sets, but set implementations may override the default for efficiency.
Examples
USING: sets prettyprint ; { 1 2 3 } { 2 3 4 } diff .
{ 1 }
Definition
GENERIC: diff ( set1 set2 -- set )
Methods
USING: bit-sets bit-sets.private math sets ;
M: bit-set diff [ bitnot bitand ] bit-set-op ;
USING: hash-sets hash-sets.private kernel sets sets.private ;
M: hash-set diff
over hash-set? [
dupd array/tester [ not ] compose
not-tombstones filter-members >hash-set
] [ (diff) >hash-set ] if ;