mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
__sort_sub__ is a method defined in Array; fix #3970
Reorganize `__sort_sub__` arguments.
This commit is contained in:
@@ -201,7 +201,7 @@ module Enumerable
|
||||
ary.push([block.call(e), i])
|
||||
}
|
||||
if ary.size > 1
|
||||
__sort_sub__(ary, 0, ary.size - 1) do |a,b|
|
||||
ary.__sort_sub__(0, ary.size - 1) do |a,b|
|
||||
a <=> b
|
||||
end
|
||||
end
|
||||
|
||||
+8
-9
@@ -200,28 +200,27 @@ class Array
|
||||
|
||||
##
|
||||
# Quick sort
|
||||
# a : the array to sort
|
||||
# left : the beginning of sort region
|
||||
# right : the end of sort region
|
||||
def __sort_sub__(a, left, right, &block)
|
||||
def __sort_sub__(left, right, &block)
|
||||
if left < right
|
||||
i = left
|
||||
j = right
|
||||
pivot = a[i + (j - i) / 2]
|
||||
pivot = self[i + (j - i) / 2]
|
||||
while true
|
||||
while ((block)? block.call(a[i], pivot): (a[i] <=> pivot)) < 0
|
||||
while ((block)? block.call(self[i], pivot): (self[i] <=> pivot)) < 0
|
||||
i += 1
|
||||
end
|
||||
while ((block)? block.call(pivot, a[j]): (pivot <=> a[j])) < 0
|
||||
while ((block)? block.call(pivot, self[j]): (pivot <=> self[j])) < 0
|
||||
j -= 1
|
||||
end
|
||||
break if (i >= j)
|
||||
tmp = a[i]; a[i] = a[j]; a[j] = tmp;
|
||||
tmp = self[i]; self[i] = self[j]; self[j] = tmp;
|
||||
i += 1
|
||||
j -= 1
|
||||
end
|
||||
__sort_sub__(a, left, i-1, &block)
|
||||
__sort_sub__(a, j+1, right, &block)
|
||||
__sort_sub__(left, i-1, &block)
|
||||
__sort_sub__(j+1, right, &block)
|
||||
end
|
||||
end
|
||||
# private :__sort_sub__
|
||||
@@ -232,7 +231,7 @@ class Array
|
||||
def sort!(&block)
|
||||
size = self.size
|
||||
if size > 1
|
||||
__sort_sub__(self, 0, size - 1, &block)
|
||||
__sort_sub__(0, size - 1, &block)
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user