0
@@ -13,7 +13,7 @@ class Array
0
def total=(n) ; @total = n ; end
0
def tuple=(t) ; @tuple = t ; end
0
def start=(s) ; @start = s ; end
0
# The flow control for many of these methods is
0
@@ -21,13 +21,13 @@ class Array
0
# also a lot of duplication of code due to very
0
# subtle processing differences and, in some
0
# cases, to avoid mutual dependency. Apologies.
0
# Returns a new Array populated with the given objects
0
@@ -38,9 +38,9 @@ class Array
0
# Creates a new Array. Without arguments, an empty
0
# Array is returned. If the only argument is an object
0
- # that responds to +to_ary+, a copy of that Array is
0
+ # that responds to +to_ary+, a copy of that Array is
0
# created. Otherwise the first argument is the size
0
- # of the new Array (default 0.) The second argument
0
+ # of the new Array (default 0.) The second argument
0
# may be an object used to fill the Array up to the
0
# size given (the same object, not a copy.) Alternatively,
0
# a block that takes the numeric index can be given and
0
@@ -53,7 +53,7 @@ class Array
0
if args.size == 1 and (args.first.__kind_of__ Array or args.first.respond_to? :to_ary)
0
ary = Type.coerce_to args.first, Array, :to_ary
0
tuple = Tuple.new(ary.size + 10)
0
tuple.copy_from ary.tuple, ary.start, 0
0
@@ -65,7 +65,7 @@ class Array
0
@tuple = Tuple.new(count + 10)
0
count.times { |i| @tuple.put i, yield(i) }
0
@@ -73,21 +73,21 @@ class Array
0
- # Element reference, returns the element at the given index or
0
- # a subarray starting from the index continuing for length
0
- # elements or returns a subarray from range elements. Negative
0
- # indices count from the end. Returns nil if the index or subarray
0
+ # Element reference, returns the element at the given index or
0
+ # a subarray starting from the index continuing for length
0
+ # elements or returns a subarray from range elements. Negative
0
+ # indices count from the end. Returns nil if the index or subarray
0
# request cannot be completed. Array#slice is synonymous with #[].
0
# Subclasses return instances of themselves.
0
Ruby.primitive :array_aref
0
# Normalise the argument variants
0
start, finish, count, simple, is_range = nil, nil, nil, false, false
0
@@ -97,27 +97,27 @@ class Array
0
start, count = one, Type.coerce_to(two, Fixnum, :to_int)
0
return nil if count < 0 # No need to go further
0
start, finish, simple = one, one, true
0
# Convert negative indices
0
start = Type.coerce_to start, Fixnum, :to_int
0
start += @total if start < 0
0
return nil if start < 0 or start >= @total
0
return @tuple.at(@start + start)
0
# ONE past end only, MRI compat
0
elsif start < 0 or start >= @total
0
finish = Type.coerce_to finish, Fixnum, :to_int if finish
0
finish = (start + count - 1) if count # For non-ranges
0
@@ -126,7 +126,7 @@ class Array
0
finish -= 1 if is_range and one.exclude_end?
0
# Going past the end is ignored (sort of)
0
- finish = (@total - 1) if finish >= @total
0
+ finish = (@total - 1) if finish >= @total
0
return self.class.new if is_range
0
@@ -139,13 +139,13 @@ class Array
0
start.upto(finish) { |i| out << at(i) }
0
alias_method :slice, :[]
0
def []=(idx, ent, *args)
0
Ruby.primitive :array_aset
0
@@ -157,15 +157,15 @@ class Array
0
raise ArgumentError, "Second argument invalid with a range"
0
unless idx.first.respond_to?(:to_int)
0
raise TypeError, "can't convert #{idx.first.class} into Integer"
0
unless idx.last.respond_to?(:to_int)
0
raise TypeError, "can't convert #{idx.last.class} into Integer"
0
@@ -183,9 +183,9 @@ class Array
0
raise IndexError.new("Index #{idx -= @total} out of bounds") if idx < 0
0
@@ -196,7 +196,7 @@ class Array
0
raise IndexError.new("Negative length #{cnt}") if cnt < 0
0
cnt = @total - idx if cnt > @total - idx # MRI seems to be forgiving here!
0
@@ -227,24 +227,24 @@ class Array
0
replacement.each_with_index { |el, i|
0
@tuple.put(@start+idx+i, el)
0
if replacement.size < cnt
0
t = @start + idx + replacement.size
0
# shift fields to the left
0
@tuple.put(t, @tuple.at(f))
0
# unset any extraneous fields
0
while t < @tuple.fields
0
@total -= (cnt - replacement.size)
0
@@ -260,7 +260,7 @@ class Array
0
# Appends the object to the end of the Array.
0
# Returns self so several appends can be chained.
0
@@ -269,7 +269,7 @@ class Array
0
@tuple.put @start + @total, obj
0
# Creates a new Array containing only elements common to
0
# both Arrays, without duplicates. Also known as a 'set
0
@@ -280,7 +280,7 @@ class Array
0
out, set_include = [], {}
0
other.each { |x| set_include[x] = [true, x] }
0
if set_include[x] and set_include[x].last.eql?(x)
0
@@ -288,7 +288,7 @@ class Array
0
# Creates a new Array by combining the two Arrays' items,
0
# without duplicates. Also known as a 'set union.'
0
@@ -296,7 +296,7 @@ class Array
0
other = Type.coerce_to other, Array, :to_ary
0
(self + other).each { |x|
0
@@ -305,8 +305,8 @@ class Array
0
# Repetition operator when supplied a #to_int argument:
0
# returns a new Array as a concatenation of the given number
0
# of the original Arrays. With an argument that responds to
0
@@ -315,7 +315,7 @@ class Array
0
if val.respond_to? :to_str
0
# Aaargh stupid MRI's stupid specific stupid error stupid types stupid
0
val = Type.coerce_to val, Fixnum, :to_int
0
@@ -325,8 +325,8 @@ class Array
0
val.times { out.push(*self) }
0
# Create a concatenation of the two Arrays.
0
other = Type.coerce_to other, Array, :to_ary
0
@@ -336,9 +336,9 @@ class Array
0
other.each { |e| out << e }
0
- # Creates a new Array that contains the items of the original
0
+ # Creates a new Array that contains the items of the original
0
# Array that do not appear in the other Array, effectively
0
# 'deducting' those items. The matching method is Hash-based.
0
@@ -349,8 +349,8 @@ class Array
0
each { |x| out << x unless exclude[x] }
0
# Compares the two Arrays and returns -1, 0 or 1 depending
0
# on whether the first one is 'smaller', 'equal' or 'greater'
0
# in relation to the second. Two Arrays are equal only if all
0
@@ -360,11 +360,11 @@ class Array
0
other = Type.coerce_to other, Array, :to_ary
0
return 1 unless other.size > i
0
diff = at(i) <=> other.at(i)
0
- return diff if diff != 0
0
+ return diff if diff != 0
0
return 1 if size > other.size
0
@@ -373,7 +373,7 @@ class Array
0
# The two Arrays are considered equal only if their
0
- # lengths are the same and each of their elements
0
+ # lengths are the same and each of their elements
0
# are equal according to first_e == second_e . Both
0
# Array subclasses and to_ary objects are accepted.
0
@@ -385,26 +385,26 @@ class Array
0
return false unless size == other.size
0
size.times { |i| return false unless @tuple.at(@start + i) == other.at(i) }
0
- # Assumes the Array contains other Arrays and searches through
0
+ # Assumes the Array contains other Arrays and searches through
0
# it comparing the given object with the first element of each
0
- # contained Array using elem == obj. Returns the first contained
0
+ # contained Array using elem == obj. Returns the first contained
0
# Array that matches (the first 'associated' Array) or nil.
0
# FIX: use break when it works again
0
if found.nil? and elem.kind_of? Array and elem.first == obj
0
found, res = true, elem
0
# Returns the element at the given index. If the
0
# index is negative, counts from the end of the
0
@@ -418,20 +418,20 @@ class Array
0
return nil if idx < 0 or idx >= @total
0
# Removes all elements in the Array and leaves it empty