Actions
Misc #15925
closedSpeed up SortedSet#min, #max, #sum etc.?
Misc #15925:
Speed up SortedSet#min, #max, #sum etc.?
Status:
Closed
Assignee:
Description
this issue is somewhat similar to https://bugs.ruby-lang.org/issues/15807
current situation, using the example of SortedSet#min (without rbtree):
SortedSet#mincallsEnumerable#minEnumerable#mincallsSortedSet#eachSortedSet#eachcallsSortedSet#to_a#to_areturns anArraywhich is guaranteed to be sortedEnumerable#minwastefully goes through this wholeArrayanyway
so complexity can be reduced from O(n) to O(1) for #min/#max/#minmax.
other methods may be sped up by delegating to faster implementations on Array.
for instance, SortedSet.new(1..1000).to_a.sum is an order of magnitude faster than SortedSet.new(1..1000).sum.
suggestion:
Files
Actions