Commit ecccd60f authored by Jim Fulton's avatar Jim Fulton

Rename _compat.cmp to _compat.compare to avoid confusion with Python2 cmp

Also removed s stupid non-optimization in compare
parent 269dcdab
......@@ -22,7 +22,7 @@ from persistent import Persistent
from .Interfaces import BTreesConflictError
from ._compat import PY3
from ._compat import cmp
from ._compat import compare
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 = cmp(i_old.key, i_com.key)
cmpON = cmp(i_old.key, i_new.key)
cmpOC = compare(i_old.key, i_com.key)
cmpON = compare(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 = cmp(i_com.key, i_new.key)
cmpCN = compare(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 = cmp(i_com.key, i_new.key)
cmpCN = compare(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 = cmp(i_old.key, i_com.key)
cmpOC = compare(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 = cmp(i_old.key, i_new.key)
cmpON = compare(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 = cmp(i_old.key, i_com.key)
cmpON = cmp(i_old.key, i_new.key)
cmpOC = compare(i_old.key, i_com.key)
cmpON = compare(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 = cmp(i_com.key, i_new.key)
cmpCN = compare(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 = cmp(i_com.key, i_new.key)
cmpCN = compare(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 = cmp(i_old.key, i_com.key)
cmpOC = compare(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 = cmp(i_old.key, i_new.key)
cmpON = compare(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_ = cmp(data[i].key, key)
cmp_ = compare(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 cmp(data[index].child.minKey(), max) > 0:
if index and compare(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 cmp(key, data[index].key) == 0:
if index > 0 and child.size and compare(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_ = cmp(i1.key, i2.key)
cmp_ = compare(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_ = cmp(i1.key, i2.key)
cmp_ = compare(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_ = cmp(i1.key, i2.key)
cmp_ = compare(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_ = cmp(i1.key, i2.key)
cmp_ = compare(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_ = cmp(i1.key, i2.key)
cmp_ = compare(i1.key, i2.key)
if cmp_ < 0:
i1.advance()
elif cmp_ == 0:
......
......@@ -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 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 (x > y) - (y > x)
......
......@@ -56,7 +56,7 @@ from BTrees.utils import oid_repr
TYPE_UNKNOWN, TYPE_BTREE, TYPE_BUCKET = range(3)
from ._compat import cmp
from ._compat import compare
_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 cmp(lo, x) <= 0:
if lo is not None and not compare(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 cmp(x, hi) < 0:
if hi is not None and not compare(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 cmp(x, keys[i+1]) < 0:
if i < n-1 and not compare(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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment