Commit 9ed982a4 authored by Gary Poster's avatar Gary Poster

add integer family conveniences

parent 1f20f799
......@@ -440,11 +440,28 @@ class IMergeIntegerKey(IMerge):
linear-time pass.
"""
class IIntegerFamily(Interface):
"""the 64-bit or 32-bit family"""
IOModule = Attribute(
'The IIntegerObjectBTreeModule for this family')
OIModule = Attribute(
'The IObjectIntegerBTreeModule for this family')
IIModule = Attribute(
'The IIntegerIntegerBTreeModule for this family')
IFModule = Attribute(
'The IIntegerFloatBTreeModule for this family')
maxint = Attribute('The maximum integer storable in this family')
minint = Attribute('The minimum integer storable in this family')
class IIntegerObjectBTreeModule(IBTreeModule, IMerge):
"""keys, or set values, are integers; values are objects.
describes IOBTree and LOBTree"""
family = Attribute('The IIntegerFamily of this module')
class IObjectIntegerBTreeModule(IBTreeModule, IIMerge):
"""keys, or set values, are objects; values are integers.
......@@ -453,11 +470,17 @@ class IObjectIntegerBTreeModule(IBTreeModule, IIMerge):
describes OIBTree and LOBTree"""
family = Attribute('The IIntegerFamily of this module')
class IIntegerIntegerBTreeModule(IBTreeModule, IIMerge, IMergeIntegerKey):
"""keys, or set values, are integers; values are also integers.
describes IIBTree and LLBTree"""
family = Attribute('The IIntegerFamily of this module')
class IObjectObjectBTreeModule(IBTreeModule, IMerge):
"""keys, or set values, are objects; values are also objects.
......@@ -466,11 +489,15 @@ class IObjectObjectBTreeModule(IBTreeModule, IMerge):
describes OOBTree"""
class IIntegerFloatBTreeModule(IBTreeModule, IMerge):
"""keys, or set values, are integers; values are floats.
describes IFBTree and LFBTree"""
family = Attribute('The IIntegerFamily of this module')
###############################################################
# IMPORTANT NOTE
#
......
# This is a Python package.
import BTrees.family64
import BTrees.family32
BTrees.family64.IOModule.family = BTrees.family64
BTrees.family64.OIModule.family = BTrees.family64
BTrees.family64.IFModule.family = BTrees.family64
BTrees.family64.IIModule.family = BTrees.family64
BTrees.family32.IOModule.family = BTrees.family32
BTrees.family32.OIModule.family = BTrees.family32
BTrees.family32.IFModule.family = BTrees.family32
BTrees.family32.IIModule.family = BTrees.family32
......@@ -26,6 +26,8 @@ from BTrees.LLBTree import LLBTree, LLBucket, LLSet, LLTreeSet
from BTrees.LFBTree import LFBTree, LFBucket, LFSet, LFTreeSet
from BTrees.OLBTree import OLBTree, OLBucket, OLSet, OLTreeSet
import BTrees.family32
import BTrees.family64
import BTrees.OOBTree
import BTrees.IOBTree
import BTrees.IIBTree
......@@ -1676,6 +1678,72 @@ class ModuleTest(TestCase):
self.assert_(
zope.interface.verify.verifyObject(self.iface, self.module))
def testFamily(self):
if self.prefix == 'OO':
self.assert_(
getattr(self.module, 'family', self) is self)
elif 'L' in self.prefix:
self.assert_(self.module.family is BTrees.family64)
elif 'I' in self.prefix:
self.assert_(self.module.family is BTrees.family32)
class FamilyTest(TestCase):
def test32(self):
self.assert_(
zope.interface.verify.verifyObject(
BTrees.Interfaces.IIntegerFamily, BTrees.family32))
self.assertEquals(
BTrees.family32.IOModule, BTrees.IOBTree)
self.assertEquals(
BTrees.family32.OIModule, BTrees.OIBTree)
self.assertEquals(
BTrees.family32.IIModule, BTrees.IIBTree)
self.assertEquals(
BTrees.family32.IFModule, BTrees.IFBTree)
s = IOTreeSet()
s.insert(BTrees.family32.maxint)
self.assert_(BTrees.family32.maxint in s)
s = IOTreeSet()
s.insert(BTrees.family32.minint)
self.assert_(BTrees.family32.minint in s)
s = IOTreeSet()
# this next bit illustrates an, um, "interesting feature". If
# the characteristics change to match the 64 bit version, please
# feel free to change.
big = BTrees.family32.maxint + 1
if isinstance(big, long):
self.assertRaises(TypeError, s.insert, big)
self.assertRaises(TypeError, s.insert, BTrees.family32.minint - 1)
else: # 64 bit Python
s.insert(BTrees.family32.maxint + 1)
self.assert_(BTrees.family32.maxint + 1 not in s)
# yeah, it's len of 1 now...don't look...don't look...
s = IOTreeSet()
s.insert(BTrees.family32.minint - 1)
self.assert_(BTrees.family32.minint - 1 not in s)
def test64(self):
self.assert_(
zope.interface.verify.verifyObject(
BTrees.Interfaces.IIntegerFamily, BTrees.family64))
self.assertEquals(
BTrees.family64.IOModule, BTrees.LOBTree)
self.assertEquals(
BTrees.family64.OIModule, BTrees.OLBTree)
self.assertEquals(
BTrees.family64.IIModule, BTrees.LLBTree)
self.assertEquals(
BTrees.family64.IFModule, BTrees.LFBTree)
s = LOTreeSet()
s.insert(BTrees.family64.maxint)
self.assert_(BTrees.family64.maxint in s)
s = LOTreeSet()
s.insert(BTrees.family64.minint)
self.assert_(BTrees.family64.minint in s)
s = LOTreeSet()
self.assertRaises(ValueError, s.insert, BTrees.family64.maxint + 1)
self.assertRaises(ValueError, s.insert, BTrees.family64.minint - 1)
def test_suite():
s = TestSuite()
......@@ -1723,6 +1791,7 @@ def test_suite():
DegenerateBTree,
TestCmpError,
BugFixes,
FamilyTest,
):
s.addTest(makeSuite(klass))
......
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