Project

General

Profile

Actions

Bug #3089

closed

limited size for Array#combination [patch]

Added by marcandre (Marc-Andre Lafortune) over 14 years ago. Updated over 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.2dev (2010-04-03 trunk 27200) [x86_64-darwin10.2.0]
Backport:
[ruby-core:29240]

Description

=begin
I would expect the following to work, but it raises an error

(0..100).to_a.combination(50).first(42)
# => RangeError: too big for combination

There is a limit of 1 << 31 potential results (or 1 <<63, depending on the platform).

Since there is an explicit test for this, I learned the hard way I better ask if there is a valid reason for this artificial limit for #combination ?

If not, and unless there is objection, I'll commit the attached patch.

Note: I noticed this when implementing the block form of #product where a similar limit exists. Since #product without a block needs to return an array of this size, it is sensible that an error is raised in that case.
When an block is given, though, I didn't see why there should be a limit, so the limitation applies only to the form without a block. This does mean, though, that arr.product(...) might not behave the same as arr.to_enum(:product, ...).to_a, at least until Enumerators have a length method (see issue #2673)
=end


Files

combination_unlimited.diff (1.85 KB) combination_unlimited.diff marcandre (Marc-Andre Lafortune), 04/04/2010 05:54 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0