Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
f0e54df4
Commit
f0e54df4
authored
Apr 23, 2018
by
Tomoyuki Sahara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sort method should not consume system stack.
parent
2213deee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
mrblib/array.rb
mrblib/array.rb
+18
-14
No files found.
mrblib/array.rb
View file @
f0e54df4
...
...
@@ -197,24 +197,28 @@ class Array
# left : the beginning of sort region
# right : the end of sort region
def
__sort_sub__
(
left
,
right
,
&
block
)
if
left
<
right
i
=
left
j
=
right
pivot
=
self
[
i
+
(
j
-
i
)
/
2
]
while
true
while
((
block
)?
block
.
call
(
self
[
i
],
pivot
):
(
self
[
i
]
<=>
pivot
))
<
0
stack
=
[
[
left
,
right
]
]
until
stack
.
empty?
left
,
right
=
stack
.
pop
if
left
<
right
i
=
left
j
=
right
pivot
=
self
[
i
+
(
j
-
i
)
/
2
]
while
true
while
((
block
)?
block
.
call
(
self
[
i
],
pivot
):
(
self
[
i
]
<=>
pivot
))
<
0
i
+=
1
end
while
((
block
)?
block
.
call
(
pivot
,
self
[
j
]):
(
pivot
<=>
self
[
j
]))
<
0
j
-=
1
end
break
if
(
i
>=
j
)
tmp
=
self
[
i
];
self
[
i
]
=
self
[
j
];
self
[
j
]
=
tmp
;
i
+=
1
end
while
((
block
)?
block
.
call
(
pivot
,
self
[
j
]):
(
pivot
<=>
self
[
j
]))
<
0
j
-=
1
end
break
if
(
i
>=
j
)
tmp
=
self
[
i
];
self
[
i
]
=
self
[
j
];
self
[
j
]
=
tmp
;
i
+=
1
j
-=
1
stack
.
push
[
left
,
i
-
1
]
stack
.
push
[
j
+
1
,
right
]
end
__sort_sub__
(
left
,
i
-
1
,
&
block
)
__sort_sub__
(
j
+
1
,
right
,
&
block
)
end
end
# private :__sort_sub__
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment