Skip to content

Commit

Permalink
Optimize SortedSet#filter for speed
Browse files Browse the repository at this point in the history
issue #136
  • Loading branch information
dubek committed Nov 5, 2014
1 parent ecd0602 commit 45fca20
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/hamster/sorted_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ def max
# @return [SortedSet]
def filter
return enum_for(:filter) unless block_given?
reduce(self) { |set, item| yield(item) ? set : set.delete(item) }
items_to_delete = []
each { |item| items_to_delete << item unless yield(item) }
derive_new_sorted_set(@node.bulk_delete(items_to_delete, @comparator))
end

# Invoke the given block once for each item in the set, and return a new
Expand Down

0 comments on commit 45fca20

Please sign in to comment.