Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0fe977c4
Commit
0fe977c4
authored
Jul 19, 2002
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
binarysort() cleanup: Documented the key invariants, explained why they
imply this is a stable sort, and added some asserts.
parent
326b4487
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
Objects/listobject.c
Objects/listobject.c
+13
-2
No files found.
Objects/listobject.c
View file @
0fe977c4
...
...
@@ -871,14 +871,25 @@ binarysort(PyObject **lo, PyObject **hi, PyObject **start, PyObject *compare)
l
=
lo
;
r
=
start
;
pivot
=
*
r
;
/* Invariants:
* pivot >= all in [lo, l).
* pivot < all in [r, start).
* The second is vacuously true at the start.
*/
assert
(
l
<
r
);
do
{
p
=
l
+
((
r
-
l
)
>>
1
);
IFLT
(
pivot
,
*
p
)
r
=
p
;
else
l
=
p
+
1
;
l
=
p
+
1
;
}
while
(
l
<
r
);
/* Pivot should go at l -- slide over to make room.
assert
(
l
==
r
);
/* The invariants still hold, so pivot >= all in [lo, l) and
pivot < all in [l, start), so pivot belongs at l. Note
that if there are elements equal to pivot, l points to the
first slot after them -- that's why this sort is stable.
Slide over to make room.
Caution: using memmove is much slower under MSVC 5;
we're not usually moving many slots. */
for
(
p
=
start
;
p
>
l
;
--
p
)
...
...
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