[#102393] [Ruby master Feature#17608] Compact and sum in one step — sawadatsuyoshi@...

Issue #17608 has been reported by sawa (Tsuyoshi Sawada).

13 messages 2021/02/04

[#102438] [Ruby master Bug#17619] if false foo=42; end creates a foo local variable set to nil — pkmuldoon@...

Issue #17619 has been reported by pkmuldoon (Phil Muldoon).

10 messages 2021/02/10

[#102631] [Ruby master Feature#17660] Expose information about which basic methods have been redefined — tenderlove@...

Issue #17660 has been reported by tenderlovemaking (Aaron Patterson).

9 messages 2021/02/27

[#102639] [Ruby master Misc#17662] The herdoc pattern used in tests does not syntax highlight correctly in many editors — eregontp@...

Issue #17662 has been reported by Eregon (Benoit Daloze).

13 messages 2021/02/27

[#102652] [Ruby master Bug#17664] Behavior of sockets changed in Ruby 3.0 to non-blocking — ciconia@...

Issue #17664 has been reported by ciconia (Sharon Rosner).

23 messages 2021/02/28

[ruby-core:102476] [Ruby master Misc#15925] Speed up SortedSet#min, #max, #sum etc.?

From: merch-redmine@...
Date: 2021-02-13 07:49:46 UTC
List: ruby-core #102476
Issue #15925 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Assigned to Closed

SortedSet is no longer part of stdlib, so this can be closed.

----------------------------------------
Misc #15925: Speed up SortedSet#min, #max, #sum etc.?
https://bugs.ruby-lang.org/issues/15925#change-90365

* Author: janosch-x (Janosch M=FCller)
* Status: Closed
* Priority: Normal
* Assignee: knu (Akinori MUSHA)
----------------------------------------
this issue is somewhat similar to https://bugs.ruby-lang.org/issues/15807

current situation, using the example of `SortedSet#min` (without `rbtree`):

- `SortedSet#min` calls `Enumerable#min`
- `Enumerable#min` calls `SortedSet#each`
- `SortedSet#each` calls `SortedSet#to_a`
- `#to_a` returns an `Array` which is guaranteed to be sorted
- `Enumerable#min` wastefully goes through this whole `Array` anyway

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 `Ar=
ray`.

for instance, `SortedSet.new(1..1000).to_a.sum` is an order of magnitude fa=
ster than `SortedSet.new(1..1000).sum`.

suggestion:

```
class SortedSet < Set
  # [ ... ]
  # non-rbtree case
  # [ ... ]

  def min
    to_a.first
  end

  def max
    to_a.last
  end

  def minmax
    [min, max]
  end

  def sum
    to_a.sum
  end

  # maybe more?
end
```

---Files--------------------------------
sorted-set-min-max-sum.patch (1.85 KB)


-- =

https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next