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

add integer family conveniences

parent 1f20f799
...@@ -440,10 +440,27 @@ class IMergeIntegerKey(IMerge): ...@@ -440,10 +440,27 @@ class IMergeIntegerKey(IMerge):
linear-time pass. 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): class IIntegerObjectBTreeModule(IBTreeModule, IMerge):
"""keys, or set values, are integers; values are objects. """keys, or set values, are integers; values are objects.
describes IOBTree and LOBTree""" describes IOBTree and LOBTree"""
family = Attribute('The IIntegerFamily of this module')
class IObjectIntegerBTreeModule(IBTreeModule, IIMerge): class IObjectIntegerBTreeModule(IBTreeModule, IIMerge):
"""keys, or set values, are objects; values are integers. """keys, or set values, are objects; values are integers.
...@@ -452,11 +469,17 @@ class IObjectIntegerBTreeModule(IBTreeModule, IIMerge): ...@@ -452,11 +469,17 @@ class IObjectIntegerBTreeModule(IBTreeModule, IIMerge):
object id)! Homogenous key types recommended. object id)! Homogenous key types recommended.
describes OIBTree and LOBTree""" describes OIBTree and LOBTree"""
family = Attribute('The IIntegerFamily of this module')
class IIntegerIntegerBTreeModule(IBTreeModule, IIMerge, IMergeIntegerKey): class IIntegerIntegerBTreeModule(IBTreeModule, IIMerge, IMergeIntegerKey):
"""keys, or set values, are integers; values are also integers. """keys, or set values, are integers; values are also integers.
describes IIBTree and LLBTree""" describes IIBTree and LLBTree"""
family = Attribute('The IIntegerFamily of this module')
class IObjectObjectBTreeModule(IBTreeModule, IMerge): class IObjectObjectBTreeModule(IBTreeModule, IMerge):
"""keys, or set values, are objects; values are also objects. """keys, or set values, are objects; values are also objects.
...@@ -466,10 +489,14 @@ class IObjectObjectBTreeModule(IBTreeModule, IMerge): ...@@ -466,10 +489,14 @@ class IObjectObjectBTreeModule(IBTreeModule, IMerge):
describes OOBTree""" describes OOBTree"""
class IIntegerFloatBTreeModule(IBTreeModule, IMerge): class IIntegerFloatBTreeModule(IBTreeModule, IMerge):
"""keys, or set values, are integers; values are floats. """keys, or set values, are integers; values are floats.
describes IFBTree and LFBTree""" describes IFBTree and LFBTree"""
family = Attribute('The IIntegerFamily of this module')
############################################################### ###############################################################
# IMPORTANT NOTE # 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 ...@@ -26,6 +26,8 @@ from BTrees.LLBTree import LLBTree, LLBucket, LLSet, LLTreeSet
from BTrees.LFBTree import LFBTree, LFBucket, LFSet, LFTreeSet from BTrees.LFBTree import LFBTree, LFBucket, LFSet, LFTreeSet
from BTrees.OLBTree import OLBTree, OLBucket, OLSet, OLTreeSet from BTrees.OLBTree import OLBTree, OLBucket, OLSet, OLTreeSet
import BTrees.family32
import BTrees.family64
import BTrees.OOBTree import BTrees.OOBTree
import BTrees.IOBTree import BTrees.IOBTree
import BTrees.IIBTree import BTrees.IIBTree
...@@ -1676,6 +1678,72 @@ class ModuleTest(TestCase): ...@@ -1676,6 +1678,72 @@ class ModuleTest(TestCase):
self.assert_( self.assert_(
zope.interface.verify.verifyObject(self.iface, self.module)) 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(): def test_suite():
s = TestSuite() s = TestSuite()
...@@ -1723,6 +1791,7 @@ def test_suite(): ...@@ -1723,6 +1791,7 @@ def test_suite():
DegenerateBTree, DegenerateBTree,
TestCmpError, TestCmpError,
BugFixes, BugFixes,
FamilyTest,
): ):
s.addTest(makeSuite(klass)) 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