Handbook
Glossary
subset? ( set1 set2 -- ? )
Factor handbook
»
The language
»
Collections
»
Sets
»
Operations on sets
Prev:
intersects? ( set1 set2 -- ? )
Next:
set= ( set1 set2 -- ? )
Vocabulary
sets
Inputs
set1
a
set
set2
a
set
Outputs
?
a
boolean
Word description
Tests if every element of
set1
is contained in
set2
.
Notes
If
set1
is empty, the result is always
t
.
Definition
IN:
sets
GENERIC:
subset?
( set1 set2 -- ? )
Methods
USING:
bit-sets
kernel
sets
;
M:
bit-set
subset?
[
intersect
]
keep
=
;
USING:
generic
hash-sets
hash-sets.private
kernel
math
sequences
sets
;
M:
hash-set
subset?
over
hash-set?
[
2dup
[
cardinality
]
bi@
>
[
2drop
f
]
[
array/tester
and-tombstones
all?
]
if
]
[
M\
hash-set
subset?
(call-next-method)
]
if
;
USING:
generic
kernel
ranges
ranges.private
sequences
sets
;
M:
range
subset?
over
range?
[
over
empty?
[
2drop
t
]
[
dupd
intersect-range
=
]
if
]
[
M\
range
subset?
(call-next-method)
]
if
;
USING:
kernel
math
sets
sets.private
;
M:
set
subset?
2dup
[
cardinality
]
bi@
>
[
2drop
f
]
[
(subset?)
]
if
;