Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BTrees
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
BTrees
Commits
ecccd60f
Commit
ecccd60f
authored
Jan 11, 2017
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename _compat.cmp to _compat.compare to avoid confusion with Python2 cmp
Also removed s stupid non-optimization in compare
parent
269dcdab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
36 deletions
+34
-36
BTrees/_base.py
BTrees/_base.py
+21
-21
BTrees/_compat.py
BTrees/_compat.py
+9
-11
BTrees/check.py
BTrees/check.py
+4
-4
No files found.
BTrees/_base.py
View file @
ecccd60f
...
...
@@ -22,7 +22,7 @@ from persistent import Persistent
from
.Interfaces
import
BTreesConflictError
from
._compat
import
PY3
from
._compat
import
c
mp
from
._compat
import
c
ompare
from
._compat
import
int_types
from
._compat
import
xrange
...
...
@@ -458,8 +458,8 @@ class Bucket(_BucketBase):
it
.
advance
()
while
i_old
.
active
and
i_com
.
active
and
i_new
.
active
:
cmpOC
=
c
mp
(
i_old
.
key
,
i_com
.
key
)
cmpON
=
c
mp
(
i_old
.
key
,
i_new
.
key
)
cmpOC
=
c
ompare
(
i_old
.
key
,
i_com
.
key
)
cmpON
=
c
ompare
(
i_old
.
key
,
i_new
.
key
)
if
cmpOC
==
0
:
if
cmpON
==
0
:
if
i_com
.
value
==
i_old
.
value
:
...
...
@@ -497,7 +497,7 @@ class Bucket(_BucketBase):
else
:
raise
merge_error
(
3
)
else
:
# both keys changed
cmpCN
=
c
mp
(
i_com
.
key
,
i_new
.
key
)
cmpCN
=
c
ompare
(
i_com
.
key
,
i_new
.
key
)
if
cmpCN
==
0
:
# dueling insert
raise
merge_error
(
4
)
if
cmpOC
>
0
:
# insert committed
...
...
@@ -511,7 +511,7 @@ class Bucket(_BucketBase):
raise
merge_error
(
5
)
# both deleted same key
while
i_com
.
active
and
i_new
.
active
:
# new inserts
cmpCN
=
c
mp
(
i_com
.
key
,
i_new
.
key
)
cmpCN
=
c
ompare
(
i_com
.
key
,
i_new
.
key
)
if
cmpCN
==
0
:
raise
merge_error
(
6
)
# dueling insert
if
cmpCN
>
0
:
# insert new
...
...
@@ -520,7 +520,7 @@ class Bucket(_BucketBase):
merge_output
(
i_com
)
while
i_old
.
active
and
i_com
.
active
:
# new deletes rest of original
cmpOC
=
c
mp
(
i_old
.
key
,
i_com
.
key
)
cmpOC
=
c
ompare
(
i_old
.
key
,
i_com
.
key
)
if
cmpOC
>
0
:
# insert committed
merge_output
(
i_com
)
elif
cmpOC
==
0
and
(
i_old
.
value
==
i_com
.
value
):
# del in new
...
...
@@ -531,7 +531,7 @@ class Bucket(_BucketBase):
while
i_old
.
active
and
i_new
.
active
:
# committed deletes rest of original
cmpON
=
c
mp
(
i_old
.
key
,
i_new
.
key
)
cmpON
=
c
ompare
(
i_old
.
key
,
i_new
.
key
)
if
cmpON
>
0
:
# insert new
merge_output
(
i_new
)
elif
cmpON
==
0
and
(
i_old
.
value
==
i_new
.
value
):
...
...
@@ -665,8 +665,8 @@ class Set(_BucketBase):
it
.
advance
()
while
i_old
.
active
and
i_com
.
active
and
i_new
.
active
:
cmpOC
=
c
mp
(
i_old
.
key
,
i_com
.
key
)
cmpON
=
c
mp
(
i_old
.
key
,
i_new
.
key
)
cmpOC
=
c
ompare
(
i_old
.
key
,
i_com
.
key
)
cmpON
=
c
ompare
(
i_old
.
key
,
i_new
.
key
)
if
cmpOC
==
0
:
if
cmpON
==
0
:
# all match
merge_output
(
i_old
)
...
...
@@ -694,7 +694,7 @@ class Set(_BucketBase):
i_old
.
advance
()
i_new
.
advance
()
else
:
# both com and new keys changed
cmpCN
=
c
mp
(
i_com
.
key
,
i_new
.
key
)
cmpCN
=
c
ompare
(
i_com
.
key
,
i_new
.
key
)
if
cmpCN
==
0
:
# both inserted same key
raise
merge_error
(
4
)
if
cmpOC
>
0
:
# insert committed
...
...
@@ -708,7 +708,7 @@ class Set(_BucketBase):
raise
merge_error
(
5
)
while
i_com
.
active
and
i_new
.
active
:
# new inserts
cmpCN
=
c
mp
(
i_com
.
key
,
i_new
.
key
)
cmpCN
=
c
ompare
(
i_com
.
key
,
i_new
.
key
)
if
cmpCN
==
0
:
# dueling insert
raise
merge_error
(
6
)
if
cmpCN
>
0
:
# insert new
...
...
@@ -717,7 +717,7 @@ class Set(_BucketBase):
merge_output
(
i_com
)
while
i_old
.
active
and
i_com
.
active
:
# new deletes rest of original
cmpOC
=
c
mp
(
i_old
.
key
,
i_com
.
key
)
cmpOC
=
c
ompare
(
i_old
.
key
,
i_com
.
key
)
if
cmpOC
>
0
:
# insert committed
merge_output
(
i_com
)
elif
cmpOC
==
0
:
# del in new
...
...
@@ -728,7 +728,7 @@ class Set(_BucketBase):
while
i_old
.
active
and
i_new
.
active
:
# committed deletes rest of original
cmpON
=
c
mp
(
i_old
.
key
,
i_new
.
key
)
cmpON
=
c
ompare
(
i_old
.
key
,
i_new
.
key
)
if
cmpON
>
0
:
# insert new
merge_output
(
i_new
)
elif
cmpON
==
0
:
# deleted in committed
...
...
@@ -843,7 +843,7 @@ class _Tree(_Base):
hi
=
len
(
data
)
i
=
hi
//
2
while
i
>
lo
:
cmp_
=
c
mp
(
data
[
i
].
key
,
key
)
cmp_
=
c
ompare
(
data
[
i
].
key
,
key
)
if
cmp_
<
0
:
lo
=
i
elif
cmp_
>
0
:
...
...
@@ -919,7 +919,7 @@ class _Tree(_Base):
max
=
self
.
_to_key
(
max
)
index
=
self
.
_search
(
max
)
if
index
and
c
mp
(
data
[
index
].
child
.
minKey
(),
max
)
>
0
:
if
index
and
c
ompare
(
data
[
index
].
child
.
minKey
(),
max
)
>
0
:
index
-=
1
#pragma: no cover no idea how to provoke this
return
data
[
index
].
child
.
maxKey
(
max
)
...
...
@@ -1014,7 +1014,7 @@ class _Tree(_Base):
self
.
_p_changed
=
True
# fix up the node key, but not for the 0'th one.
if
index
>
0
and
child
.
size
and
c
mp
(
key
,
data
[
index
].
key
)
==
0
:
if
index
>
0
and
child
.
size
and
c
ompare
(
key
,
data
[
index
].
key
)
==
0
:
self
.
_p_changed
=
True
data
[
index
].
key
=
child
.
minKey
()
...
...
@@ -1324,7 +1324,7 @@ def difference(set_type, o1, o2):
def
copy
(
i
):
result
.
_keys
.
append
(
i
.
key
)
while
i1
.
active
and
i2
.
active
:
cmp_
=
c
mp
(
i1
.
key
,
i2
.
key
)
cmp_
=
c
ompare
(
i1
.
key
,
i2
.
key
)
if
cmp_
<
0
:
copy
(
i1
)
i1
.
advance
()
...
...
@@ -1349,7 +1349,7 @@ def union(set_type, o1, o2):
def
copy
(
i
):
result
.
_keys
.
append
(
i
.
key
)
while
i1
.
active
and
i2
.
active
:
cmp_
=
c
mp
(
i1
.
key
,
i2
.
key
)
cmp_
=
c
ompare
(
i1
.
key
,
i2
.
key
)
if
cmp_
<
0
:
copy
(
i1
)
i1
.
advance
()
...
...
@@ -1379,7 +1379,7 @@ def intersection(set_type, o1, o2):
def
copy
(
i
):
result
.
_keys
.
append
(
i
.
key
)
while
i1
.
active
and
i2
.
active
:
cmp_
=
c
mp
(
i1
.
key
,
i2
.
key
)
cmp_
=
c
ompare
(
i1
.
key
,
i2
.
key
)
if
cmp_
<
0
:
i1
.
advance
()
elif
cmp_
==
0
:
...
...
@@ -1425,7 +1425,7 @@ def weightedUnion(set_type, o1, o2, w1=1, w2=1):
result
.
_keys
.
append
(
i
.
key
)
while
i1
.
active
and
i2
.
active
:
cmp_
=
c
mp
(
i1
.
key
,
i2
.
key
)
cmp_
=
c
ompare
(
i1
.
key
,
i2
.
key
)
if
cmp_
<
0
:
copy
(
i1
,
w1
)
i1
.
advance
()
...
...
@@ -1466,7 +1466,7 @@ def weightedIntersection(set_type, o1, o2, w1=1, w2=1):
else
:
result
=
o1
.
_set_type
()
while
i1
.
active
and
i2
.
active
:
cmp_
=
c
mp
(
i1
.
key
,
i2
.
key
)
cmp_
=
c
ompare
(
i1
.
key
,
i2
.
key
)
if
cmp_
<
0
:
i1
.
advance
()
elif
cmp_
==
0
:
...
...
BTrees/_compat.py
View file @
ecccd60f
...
...
@@ -13,7 +13,6 @@
##############################################################################
import
sys
None_
=
None
if
sys
.
version_info
[
0
]
<
3
:
#pragma NO COVER Python2
PY2
=
True
...
...
@@ -24,17 +23,16 @@ if sys.version_info[0] < 3: #pragma NO COVER Python2
int_types
=
int
,
long
xrange
=
xrange
cmp_
=
cmp
def
cmp
(
x
,
y
):
if
x
is
None_
:
if
y
is
None_
:
def
compare
(
x
,
y
):
if
x
is
None
:
if
y
is
None
:
return
0
else
:
return
-
1
elif
y
is
None
_
:
elif
y
is
None
:
return
1
else
:
return
cmp
_
(
x
,
y
)
return
cmp
(
x
,
y
)
_bytes
=
str
def
_ascii
(
x
):
...
...
@@ -54,13 +52,13 @@ else: #pragma NO COVER Python3
int_types
=
int
,
xrange
=
range
def
c
mp
(
x
,
y
):
if
x
is
None
_
:
if
y
is
None
_
:
def
c
ompare
(
x
,
y
):
if
x
is
None
:
if
y
is
None
:
return
0
else
:
return
-
1
elif
y
is
None
_
:
elif
y
is
None
:
return
1
else
:
return
(
x
>
y
)
-
(
y
>
x
)
...
...
BTrees/check.py
View file @
ecccd60f
...
...
@@ -56,7 +56,7 @@ from BTrees.utils import oid_repr
TYPE_UNKNOWN
,
TYPE_BTREE
,
TYPE_BUCKET
=
range
(
3
)
from
._compat
import
c
mp
from
._compat
import
c
ompare
_type2kind
=
{}
for
kv
in
(
'OO'
,
...
...
@@ -348,13 +348,13 @@ class Checker(Walker):
def
check_sorted
(
self
,
obj
,
path
,
keys
,
lo
,
hi
):
i
,
n
=
0
,
len
(
keys
)
for
x
in
keys
:
if
lo
is
not
None
and
not
c
mp
(
lo
,
x
)
<=
0
:
if
lo
is
not
None
and
not
c
ompare
(
lo
,
x
)
<=
0
:
s
=
"key %r < lower bound %r at index %d"
%
(
x
,
lo
,
i
)
self
.
complain
(
s
,
obj
,
path
)
if
hi
is
not
None
and
not
c
mp
(
x
,
hi
)
<
0
:
if
hi
is
not
None
and
not
c
ompare
(
x
,
hi
)
<
0
:
s
=
"key %r >= upper bound %r at index %d"
%
(
x
,
hi
,
i
)
self
.
complain
(
s
,
obj
,
path
)
if
i
<
n
-
1
and
not
c
mp
(
x
,
keys
[
i
+
1
])
<
0
:
if
i
<
n
-
1
and
not
c
ompare
(
x
,
keys
[
i
+
1
])
<
0
:
s
=
"key %r at index %d >= key %r at index %d"
%
(
x
,
i
,
keys
[
i
+
1
],
i
+
1
)
self
.
complain
(
s
,
obj
,
path
)
...
...
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