speed up set intersect
This commit is contained in:
parent
0cf75e3850
commit
4ce28b58cb
Notes:
git
2019-12-31 20:53:05 +09:00
@ -464,7 +464,15 @@ class Set
|
|||||||
# Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}>
|
# Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}>
|
||||||
def &(enum)
|
def &(enum)
|
||||||
n = self.class.new
|
n = self.class.new
|
||||||
|
if enum.is_a?(Set)
|
||||||
|
if enum.size > size
|
||||||
|
each { |o| n.add(o) if enum.include?(o) }
|
||||||
|
else
|
||||||
|
enum.each { |o| n.add(o) if include?(o) }
|
||||||
|
end
|
||||||
|
else
|
||||||
do_with_enum(enum) { |o| n.add(o) if include?(o) }
|
do_with_enum(enum) { |o| n.add(o) if include?(o) }
|
||||||
|
end
|
||||||
n
|
n
|
||||||
end
|
end
|
||||||
alias intersection &
|
alias intersection &
|
||||||
|
Loading…
x
Reference in New Issue
Block a user