Commit 5183dc97 authored by Tim Peters's avatar Tim Peters

BTree_rangeSearch(): Like its bucket counterpart, this wasn't checking

for lo > hi either, except if they happened to be in the same bucket.  All
sorts of strange results followed (the range should be empty if lo > hi,
and is after this patch).
parent 90a7d5e2
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.51 2002/06/13 14:06:57 tim_one Exp $\n" #define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.52 2002/06/13 20:08:39 tim_one Exp $\n"
/* /*
** _BTree_get ** _BTree_get
...@@ -1123,6 +1123,23 @@ BTree_rangeSearch(BTree *self, PyObject *args, char type) ...@@ -1123,6 +1123,23 @@ BTree_rangeSearch(BTree *self, PyObject *args, char type)
UNLESS (self->data && self->len) goto empty; UNLESS (self->data && self->len) goto empty;
/* If f and l were both passed in, ensure f <= l. */
if (f && f != Py_None && l && l != Py_None)
{
int cmp;
KEY_TYPE first;
KEY_TYPE last;
int copied = 1;
COPY_KEY_FROM_ARG(first, f, copied);
UNLESS (copied) goto err;
COPY_KEY_FROM_ARG(last, l, copied);
UNLESS (copied) goto err;
TEST_KEY_SET_OR(cmp, first, last) goto err;
if (cmp > 0) goto empty;
}
/* Find the low range */ /* Find the low range */
if (f && f != Py_None) if (f && f != Py_None)
......
...@@ -251,6 +251,14 @@ class MappingBase(Base): ...@@ -251,6 +251,14 @@ class MappingBase(Base):
self.assertEqual(list(t.keys(10,12)), [], list(t.keys(10,12))) self.assertEqual(list(t.keys(10,12)), [], list(t.keys(10,12)))
self.assertEqual(list(t.keys(9, 1)), [], list(t.keys(9, 1))) self.assertEqual(list(t.keys(9, 1)), [], list(t.keys(9, 1)))
# For IITreeSets, this one was returning 31 for len(keys), and
# list(keys) produced a list with 100 elements.
t.clear()
t.update(zip(range(300), range(300)))
keys = t.keys(200, 50)
self.assertEqual(len(keys), 0)
self.assertEqual(list(keys), [])
def testSlicing(self): def testSlicing(self):
# Test that slicing of .keys()/.values()/.items() works exactly the # Test that slicing of .keys()/.values()/.items() works exactly the
# same way as slicing a Python list with the same contents. # same way as slicing a Python list with the same contents.
...@@ -430,6 +438,14 @@ class NormalSetTests(Base): ...@@ -430,6 +438,14 @@ class NormalSetTests(Base):
self.assertEqual(list(t.keys(10,12)), [], list(t.keys(10,12))) self.assertEqual(list(t.keys(10,12)), [], list(t.keys(10,12)))
self.assertEqual(list(t.keys(9,1)), [], list(t.keys(9,1))) self.assertEqual(list(t.keys(9,1)), [], list(t.keys(9,1)))
# For IITreeSets, this one was returning 31 for len(keys), and
# list(keys) produced a list with 100 elements.
t.clear()
t.update(range(300))
keys = t.keys(200, 50)
self.assertEqual(len(keys), 0)
self.assertEqual(list(keys), [])
def testSlicing(self): def testSlicing(self):
# Test that slicing of .keys() works exactly the same way as slicing # Test that slicing of .keys() works exactly the same way as slicing
# a Python list with the same contents. # a Python list with the same contents.
......
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