Commit f70f5c92 authored by Tres Seaver's avatar Tres Seaver

Merge 'BTrees-pure_python' branch.

parents aec0aa5d 81e6c4fe
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -12,10 +12,118 @@
#
##############################################################################
import zope.interface
import BTrees.Interfaces
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'IFBucket', 'IFSet', 'IFBTree', 'IFTreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection', 'multiunion',
)
# hack to overcome dynamic-linking headache.
from _IFBTree import *
from zope.interface import moduleProvides
zope.interface.moduleProvides(BTrees.Interfaces.IIntegerFloatBTreeModule)
from .Interfaces import IIntegerFloatBTreeModule
from ._base import Bucket
from ._base import MERGE
from ._base import MERGE_WEIGHT_numeric
from ._base import MERGE_DEFAULT_float
from ._base import Set
from ._base import Tree as BTree
from ._base import TreeSet
from ._base import difference as _difference
from ._base import intersection as _intersection
from ._base import multiunion as _multiunion
from ._base import set_operation as _set_operation
from ._base import to_int as _to_key
from ._base import to_float as _to_value
from ._base import union as _union
from ._base import weightedIntersection as _weightedIntersection
from ._base import weightedUnion as _weightedUnion
_BUCKET_SIZE = 120
_TREE_SIZE = 500
using64bits = False
class IFBucketPy(Bucket):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class IFSetPy(Set):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class IFBTreePy(BTree):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class IFTreeSetPy(TreeSet):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
# Can't declare forward refs, so fix up afterwards:
IFBucketPy._mapping_type = IFBucketPy._bucket_type = IFBucketPy
IFBucketPy._set_type = IFSetPy
IFSetPy._mapping_type = IFBucketPy
IFSetPy._set_type = IFSetPy._bucket_type = IFSetPy
IFBTreePy._mapping_type = IFBTreePy._bucket_type = IFBucketPy
IFBTreePy._set_type = IFSetPy
IFTreeSetPy._mapping_type = IFBucketPy
IFTreeSetPy._set_type = IFTreeSetPy._bucket_type = IFSetPy
differencePy = _set_operation(_difference, IFSetPy)
unionPy = _set_operation(_union, IFSetPy)
intersectionPy = _set_operation(_intersection, IFSetPy)
multiunionPy = _set_operation(_multiunion, IFSetPy)
weightedUnionPy = _set_operation(_weightedUnion, IFSetPy)
weightedIntersectionPy = _set_operation(_weightedIntersection, IFSetPy)
try:
from _IFBTree import IFBucket
from _IFBTree import IFSet
from _IFBTree import IFBTree
from _IFBTree import IFTreeSet
from _IFBTree import difference
from _IFBTree import union
from _IFBTree import intersection
from _IFBTree import multiunion
from _OIBTree import weightedUnion
from _OIBTree import weightedIntersection
except ImportError: #pragma NO COVER
IFBucket = IFBucketPy
IFSet = IFSetPy
IFBTree = IFBTreePy
IFTreeSet = IFTreeSetPy
difference = differencePy
union = unionPy
intersection = intersectionPy
multiunion = multiunionPy
weightedUnion = weightedUnionPy
weightedIntersection = weightedIntersectionPy
Bucket = IFBucket
Set = IFSet
BTree = IFBTree
TreeSet = IFTreeSet
moduleProvides(IIntegerFloatBTreeModule)
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -12,10 +12,119 @@
#
##############################################################################
import zope.interface
import BTrees.Interfaces
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'IIBucket', 'IISet', 'IIBTree', 'IITreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection', 'multiunion',
)
# hack to overcome dynamic-linking headache.
from _IIBTree import *
from zope.interface import moduleProvides
zope.interface.moduleProvides(BTrees.Interfaces.IIntegerIntegerBTreeModule)
from .Interfaces import IIntegerIntegerBTreeModule
from ._base import Bucket
from ._base import MERGE
from ._base import MERGE_WEIGHT_numeric
from ._base import MERGE_DEFAULT_int
from ._base import Set
from ._base import Tree as BTree
from ._base import TreeSet
from ._base import difference as _difference
from ._base import intersection as _intersection
from ._base import multiunion as _multiunion
from ._base import set_operation as _set_operation
from ._base import to_int as _to_key
from ._base import to_int as _to_value
from ._base import union as _union
from ._base import weightedIntersection as _weightedIntersection
from ._base import weightedUnion as _weightedUnion
_BUCKET_SIZE = 120
_TREE_SIZE = 500
using64bits = False
class IIBucketPy(Bucket):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class IISetPy(Set):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class IIBTreePy(BTree):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class IITreeSetPy(TreeSet):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
# Can't declare forward refs, so fix up afterwards:
IIBucketPy._mapping_type = IIBucketPy._bucket_type = IIBucketPy
IIBucketPy._set_type = IISetPy
IISetPy._mapping_type = IIBucketPy
IISetPy._set_type = IISetPy._bucket_type = IISetPy
IIBTreePy._mapping_type = IIBTreePy._bucket_type = IIBucketPy
IIBTreePy._set_type = IISetPy
IITreeSetPy._mapping_type = IIBucketPy
IITreeSetPy._set_type = IITreeSetPy._bucket_type = IISetPy
differencePy = _set_operation(_difference, IISetPy)
unionPy = _set_operation(_union, IISetPy)
intersectionPy = _set_operation(_intersection, IISetPy)
multiunionPy = _set_operation(_multiunion, IISetPy)
weightedUnionPy = _set_operation(_weightedUnion, IISetPy)
weightedIntersectionPy = _set_operation(_weightedIntersection, IISetPy)
try:
from _IIBTree import IIBucket
from _IIBTree import IISet
from _IIBTree import IIBTree
from _IIBTree import IITreeSet
from _IIBTree import difference
from _IIBTree import union
from _IIBTree import intersection
from _IIBTree import multiunion
from _IIBTree import weightedUnion
from _IIBTree import weightedIntersection
except ImportError: #pragma NO COVER
IIBucket = IIBucketPy
IISet = IISetPy
IIBTree = IIBTreePy
IITreeSet = IITreeSetPy
difference = differencePy
union = unionPy
intersection = intersectionPy
multiunion = multiunionPy
weightedUnion = weightedUnionPy
weightedIntersection = weightedIntersectionPy
Bucket = IIBucket
Set = IISet
BTree = IIBTree
TreeSet = IITreeSet
moduleProvides(IIntegerIntegerBTreeModule)
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -12,10 +12,98 @@
#
##############################################################################
import zope.interface
import BTrees.Interfaces
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'IOBucket', 'IOSet', 'IOBTree', 'IOTreeSet',
'union', 'intersection', 'difference', 'multiunion',
)
# hack to overcome dynamic-linking headache.
from _IOBTree import *
from zope.interface import moduleProvides
zope.interface.moduleProvides(BTrees.Interfaces.IIntegerObjectBTreeModule)
from .Interfaces import IIntegerObjectBTreeModule
from ._base import Bucket
from ._base import MERGE_WEIGHT_default
from ._base import Set
from ._base import Tree as BTree
from ._base import TreeSet
from ._base import difference as _difference
from ._base import intersection as _intersection
from ._base import multiunion as _multiunion
from ._base import set_operation as _set_operation
from ._base import to_int as _to_key
from ._base import to_ob as _to_value
from ._base import union as _union
_BUCKET_SIZE = 60
_TREE_SIZE = 500
using64bits = False
class IOBucketPy(Bucket):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE_WEIGHT = MERGE_WEIGHT_default
class IOSetPy(Set):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
class IOBTreePy(BTree):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE_WEIGHT = MERGE_WEIGHT_default
class IOTreeSetPy(TreeSet):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
# Can't declare forward refs, so fix up afterwards:
IOBucketPy._mapping_type = IOBucketPy._bucket_type = IOBucketPy
IOBucketPy._set_type = IOSetPy
IOSetPy._mapping_type = IOBucketPy
IOSetPy._set_type = IOSetPy._bucket_type = IOSetPy
IOBTreePy._mapping_type = IOBTreePy._bucket_type = IOBucketPy
IOBTreePy._set_type = IOSetPy
IOTreeSetPy._mapping_type = IOBucketPy
IOTreeSetPy._set_type = IOTreeSetPy._bucket_type = IOSetPy
differencePy = _set_operation(_difference, IOSetPy)
unionPy = _set_operation(_union, IOSetPy)
intersectionPy = _set_operation(_intersection, IOSetPy)
multiunionPy = _set_operation(_multiunion, IOSetPy)
try:
from _IOBTree import IOBucket
from _IOBTree import IOSet
from _IOBTree import IOBTree
from _IOBTree import IOTreeSet
from _IOBTree import difference
from _IOBTree import union
from _IOBTree import intersection
from _IOBTree import multiunion
except ImportError: #pragma NO COVER
IOBucket = IOBucketPy
IOSet = IOSetPy
IOBTree = IOBTreePy
IOTreeSet = IOTreeSetPy
difference = differencePy
union = unionPy
intersection = intersectionPy
multiunion = multiunionPy
Bucket = IOBucket
Set = IOSet
BTree = IOBTree
TreeSet = IOTreeSet
moduleProvides(IIntegerObjectBTreeModule)
......@@ -511,7 +511,9 @@ try:
from ZODB.POSException import BTreesConflictError
except ImportError:
class BTreesConflictError(ValueError):
pass
@property
def reason(self):
return self.args[-1]
###############################################################
# IMPORTANT NOTE
......
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -12,10 +12,119 @@
#
##############################################################################
import zope.interface
import BTrees.Interfaces
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'LFBucket', 'LFSet', 'LFBTree', 'LFTreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection', 'multiunion',
)
# hack to overcome dynamic-linking headache.
from _LFBTree import *
from zope.interface import moduleProvides
zope.interface.moduleProvides(BTrees.Interfaces.IIntegerFloatBTreeModule)
from .Interfaces import IIntegerFloatBTreeModule
from ._base import Bucket
from ._base import MERGE
from ._base import MERGE_WEIGHT_numeric
from ._base import MERGE_DEFAULT_float
from ._base import Set
from ._base import Tree as BTree
from ._base import TreeSet
from ._base import difference as _difference
from ._base import intersection as _intersection
from ._base import multiunion as _multiunion
from ._base import set_operation as _set_operation
from ._base import to_long as _to_key
from ._base import to_float as _to_value
from ._base import union as _union
from ._base import weightedIntersection as _weightedIntersection
from ._base import weightedUnion as _weightedUnion
_BUCKET_SIZE = 120
_TREE_SIZE = 500
using64bits = True
class LFBucketPy(Bucket):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class LFSetPy(Set):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class LFBTreePy(BTree):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class LFTreeSetPy(TreeSet):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
# Can't declare forward refs, so fix up afterwards:
LFBucketPy._mapping_type = LFBucketPy._bucket_type = LFBucketPy
LFBucketPy._set_type = LFSetPy
LFSetPy._mapping_type = LFBucketPy
LFSetPy._set_type = LFSetPy._bucket_type = LFSetPy
LFBTreePy._mapping_type = LFBTreePy._bucket_type = LFBucketPy
LFBTreePy._set_type = LFSetPy
LFTreeSetPy._mapping_type = LFBucketPy
LFTreeSetPy._set_type = LFTreeSetPy._bucket_type = LFSetPy
differencePy = _set_operation(_difference, LFSetPy)
unionPy = _set_operation(_union, LFSetPy)
intersectionPy = _set_operation(_intersection, LFSetPy)
multiunionPy = _set_operation(_multiunion, LFSetPy)
weightedUnionPy = _set_operation(_weightedUnion, LFSetPy)
weightedIntersectionPy = _set_operation(_weightedIntersection, LFSetPy)
try:
from _LFBTree import LFBucket
from _LFBTree import LFSet
from _LFBTree import LFBTree
from _LFBTree import LFTreeSet
from _LFBTree import difference
from _LFBTree import union
from _LFBTree import intersection
from _LFBTree import multiunion
from _OIBTree import weightedUnion
from _OIBTree import weightedIntersection
except ImportError: #pragma NO COVER
LFBucket = LFBucketPy
LFSet = LFSetPy
LFBTree = LFBTreePy
LFTreeSet = LFTreeSetPy
difference = differencePy
union = unionPy
intersection = intersectionPy
multiunion = multiunionPy
weightedUnion = weightedUnionPy
weightedIntersection = weightedIntersectionPy
Bucket = LFBucket
Set = LFSet
BTree = LFBTree
TreeSet = LFTreeSet
moduleProvides(IIntegerFloatBTreeModule)
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -12,10 +12,119 @@
#
##############################################################################
import zope.interface
import BTrees.Interfaces
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'LLBucket', 'LLSet', 'LLBTree', 'LLTreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection', 'multiunion',
)
# hack to overcome dynamic-linking headache.
from _LLBTree import *
from zope.interface import moduleProvides
zope.interface.moduleProvides(BTrees.Interfaces.IIntegerIntegerBTreeModule)
from .Interfaces import IIntegerIntegerBTreeModule
from ._base import Bucket
from ._base import MERGE
from ._base import MERGE_WEIGHT_numeric
from ._base import MERGE_DEFAULT_int
from ._base import Set
from ._base import Tree as BTree
from ._base import TreeSet
from ._base import difference as _difference
from ._base import intersection as _intersection
from ._base import multiunion as _multiunion
from ._base import set_operation as _set_operation
from ._base import to_long as _to_key
from ._base import to_long as _to_value
from ._base import union as _union
from ._base import weightedIntersection as _weightedIntersection
from ._base import weightedUnion as _weightedUnion
_BUCKET_SIZE = 120
_TREE_SIZE = 500
using64bits = True
class LLBucketPy(Bucket):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class LLSetPy(Set):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class LLBTreePy(BTree):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class LLTreeSetPy(TreeSet):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
# Can't declare forward refs, so fix up afterwards:
LLBucketPy._mapping_type = LLBucketPy._bucket_type = LLBucketPy
LLBucketPy._set_type = LLSetPy
LLSetPy._mapping_type = LLBucketPy
LLSetPy._set_type = LLSetPy._bucket_type = LLSetPy
LLBTreePy._mapping_type = LLBTreePy._bucket_type = LLBucketPy
LLBTreePy._set_type = LLSetPy
LLTreeSetPy._mapping_type = LLBucketPy
LLTreeSetPy._set_type = LLTreeSetPy._bucket_type = LLSetPy
differencePy = _set_operation(_difference, LLSetPy)
unionPy = _set_operation(_union, LLSetPy)
intersectionPy = _set_operation(_intersection, LLSetPy)
multiunionPy = _set_operation(_multiunion, LLSetPy)
weightedUnionPy = _set_operation(_weightedUnion, LLSetPy)
weightedIntersectionPy = _set_operation(_weightedIntersection, LLSetPy)
try:
from _LLBTree import LLBucket
from _LLBTree import LLSet
from _LLBTree import LLBTree
from _LLBTree import LLTreeSet
from _LLBTree import difference
from _LLBTree import union
from _LLBTree import intersection
from _LLBTree import multiunion
from _LLBTree import weightedUnion
from _LLBTree import weightedIntersection
except ImportError: #pragma NO COVER
LLBucket = LLBucketPy
LLSet = LLSetPy
LLBTree = LLBTreePy
LLTreeSet = LLTreeSetPy
difference = differencePy
union = unionPy
intersection = intersectionPy
multiunion = multiunionPy
weightedUnion = weightedUnionPy
weightedIntersection = weightedIntersectionPy
Bucket = LLBucket
Set = LLSet
BTree = LLBTree
TreeSet = LLTreeSet
moduleProvides(IIntegerIntegerBTreeModule)
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -12,10 +12,98 @@
#
##############################################################################
import zope.interface
import BTrees.Interfaces
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'LOBucket', 'LOSet', 'LOBTree', 'LOTreeSet',
'union', 'intersection', 'difference', 'multiunion',
)
# hack to overcome dynamic-linking headache.
from _LOBTree import *
from zope.interface import moduleProvides
zope.interface.moduleProvides(BTrees.Interfaces.IIntegerObjectBTreeModule)
from .Interfaces import IIntegerObjectBTreeModule
from ._base import Bucket
from ._base import MERGE_WEIGHT_default
from ._base import Set
from ._base import Tree as BTree
from ._base import TreeSet
from ._base import difference as _difference
from ._base import intersection as _intersection
from ._base import multiunion as _multiunion
from ._base import set_operation as _set_operation
from ._base import to_long as _to_key
from ._base import to_ob as _to_value
from ._base import union as _union
_BUCKET_SIZE = 60
_TREE_SIZE = 500
using64bits = True
class LOBucketPy(Bucket):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE_WEIGHT = MERGE_WEIGHT_default
class LOSetPy(Set):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
class LOBTreePy(BTree):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE_WEIGHT = MERGE_WEIGHT_default
class LOTreeSetPy(TreeSet):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
# Can't declare forward refs, so fix up afterwards:
LOBucketPy._mapping_type = LOBucketPy._bucket_type = LOBucketPy
LOBucketPy._set_type = LOSetPy
LOSetPy._mapping_type = LOBucketPy
LOSetPy._set_type = LOSetPy._bucket_type = LOSetPy
LOBTreePy._mapping_type = LOBTreePy._bucket_type = LOBucketPy
LOBTreePy._set_type = LOSetPy
LOTreeSetPy._mapping_type = LOBucketPy
LOTreeSetPy._set_type = LOTreeSetPy._bucket_type = LOSetPy
differencePy = _set_operation(_difference, LOSetPy)
unionPy = _set_operation(_union, LOSetPy)
intersectionPy = _set_operation(_intersection, LOSetPy)
multiunionPy = _set_operation(_multiunion, LOSetPy)
try:
from _LOBTree import LOBucket
from _LOBTree import LOSet
from _LOBTree import LOBTree
from _LOBTree import LOTreeSet
from _LOBTree import difference
from _LOBTree import union
from _LOBTree import intersection
from _LOBTree import multiunion
except ImportError: #pragma NO COVER
LOBucket = LOBucketPy
LOSet = LOSetPy
LOBTree = LOBTreePy
LOTreeSet = LOTreeSetPy
difference = differencePy
union = unionPy
intersection = intersectionPy
multiunion = multiunionPy
Bucket = LOBucket
Set = LOSet
BTree = LOBTree
TreeSet = LOTreeSet
moduleProvides(IIntegerObjectBTreeModule)
......@@ -28,8 +28,9 @@ class Length(persistent.Persistent):
longer works as expected, because new-style classes cache
class-defined slot methods (like __len__) in C type slots. Thus,
instance-defined slot fillers are ignored.
"""
# class-level default required to keep copy.deepcopy happy -- see
# https://bugs.launchpad.net/zodb/+bug/516653
value = 0
def __init__(self, v=0):
......
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -12,10 +12,115 @@
#
##############################################################################
import zope.interface
import BTrees.Interfaces
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'OIBucket', 'OISet', 'OIBTree', 'OITreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection',
)
# hack to overcome dynamic-linking headache.
from _OIBTree import *
from zope.interface import moduleProvides
zope.interface.moduleProvides(BTrees.Interfaces.IObjectIntegerBTreeModule)
from .Interfaces import IObjectIntegerBTreeModule
from ._base import Bucket
from ._base import MERGE
from ._base import MERGE_WEIGHT_numeric
from ._base import MERGE_DEFAULT_float
from ._base import Set
from ._base import Tree as BTree
from ._base import TreeSet
from ._base import difference as _difference
from ._base import intersection as _intersection
from ._base import set_operation as _set_operation
from ._base import to_ob as _to_key
from ._base import to_int as _to_value
from ._base import union as _union
from ._base import weightedIntersection as _weightedIntersection
from ._base import weightedUnion as _weightedUnion
_BUCKET_SIZE = 60
_TREE_SIZE = 250
using64bits = True
class OIBucketPy(Bucket):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class OISetPy(Set):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class OIBTreePy(BTree):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class OITreeSetPy(TreeSet):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
# Can't declare forward refs, so fix up afterwards:
OIBucketPy._mapping_type = OIBucketPy._bucket_type = OIBucketPy
OIBucketPy._set_type = OISetPy
OISetPy._mapping_type = OIBucketPy
OISetPy._set_type = OISetPy._bucket_type = OISetPy
OIBTreePy._mapping_type = OIBTreePy._bucket_type = OIBucketPy
OIBTreePy._set_type = OISetPy
OITreeSetPy._mapping_type = OIBucketPy
OITreeSetPy._set_type = OITreeSetPy._bucket_type = OISetPy
differencePy = _set_operation(_difference, OISetPy)
unionPy = _set_operation(_union, OISetPy)
intersectionPy = _set_operation(_intersection, OISetPy)
weightedUnionPy = _set_operation(_weightedUnion, OISetPy)
weightedIntersectionPy = _set_operation(_weightedIntersection, OISetPy)
try:
from _OIBTree import OIBucket
from _OIBTree import OISet
from _OIBTree import OIBTree
from _OIBTree import OITreeSet
from _OIBTree import difference
from _OIBTree import union
from _OIBTree import intersection
from _OIBTree import weightedUnion
from _OIBTree import weightedIntersection
except ImportError: #pragma NO COVER
OIBucket = OIBucketPy
OISet = OISetPy
OIBTree = OIBTreePy
OITreeSet = OITreeSetPy
difference = differencePy
union = unionPy
intersection = intersectionPy
weightedUnion = weightedUnionPy
weightedIntersection = weightedIntersectionPy
Bucket = OIBucket
Set = OISet
BTree = OIBTree
TreeSet = OITreeSet
moduleProvides(IObjectIntegerBTreeModule)
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -12,10 +12,115 @@
#
##############################################################################
import zope.interface
import BTrees.Interfaces
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'OLBucket', 'OLSet', 'OLBTree', 'OLTreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection',
)
# hack to overcome dynamic-linking headache.
from _OLBTree import *
from zope.interface import moduleProvides
zope.interface.moduleProvides(BTrees.Interfaces.IObjectIntegerBTreeModule)
from .Interfaces import IObjectIntegerBTreeModule
from ._base import Bucket
from ._base import MERGE
from ._base import MERGE_WEIGHT_numeric
from ._base import MERGE_DEFAULT_int
from ._base import Set
from ._base import Tree as BTree
from ._base import TreeSet
from ._base import difference as _difference
from ._base import intersection as _intersection
from ._base import set_operation as _set_operation
from ._base import to_ob as _to_key
from ._base import to_int as _to_value
from ._base import union as _union
from ._base import weightedIntersection as _weightedIntersection
from ._base import weightedUnion as _weightedUnion
_BUCKET_SIZE = 60
_TREE_SIZE = 250
using64bits = True
class OLBucketPy(Bucket):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class OLSetPy(Set):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class OLBTreePy(BTree):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class OLTreeSetPy(TreeSet):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
# Can't declare forward refs, so fix up afterwards:
OLBucketPy._mapping_type = OLBucketPy._bucket_type = OLBucketPy
OLBucketPy._set_type = OLSetPy
OLSetPy._mapping_type = OLBucketPy
OLSetPy._set_type = OLSetPy._bucket_type = OLSetPy
OLBTreePy._mapping_type = OLBTreePy._bucket_type = OLBucketPy
OLBTreePy._set_type = OLSetPy
OLTreeSetPy._mapping_type = OLBucketPy
OLTreeSetPy._set_type = OLTreeSetPy._bucket_type = OLSetPy
differencePy = _set_operation(_difference, OLSetPy)
unionPy = _set_operation(_union, OLSetPy)
intersectionPy = _set_operation(_intersection, OLSetPy)
weightedUnionPy = _set_operation(_weightedUnion, OLSetPy)
weightedIntersectionPy = _set_operation(_weightedIntersection, OLSetPy)
try:
from _OLBTree import OLBucket
from _OLBTree import OLSet
from _OLBTree import OLBTree
from _OLBTree import OLTreeSet
from _OLBTree import difference
from _OLBTree import union
from _OLBTree import intersection
from _OLBTree import weightedUnion
from _OLBTree import weightedIntersection
except ImportError: #pragma NO COVER
OLBucket = OLBucketPy
OLSet = OLSetPy
OLBTree = OLBTreePy
OLTreeSet = OLTreeSetPy
difference = differencePy
union = unionPy
intersection = intersectionPy
weightedUnion = weightedUnionPy
weightedIntersection = weightedIntersectionPy
Bucket = OLBucket
Set = OLSet
BTree = OLBTree
TreeSet = OLTreeSet
moduleProvides(IObjectIntegerBTreeModule)
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -12,10 +12,91 @@
#
##############################################################################
import zope.interface
import BTrees.Interfaces
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'OOBucket', 'OOSet', 'OOBTree', 'OOTreeSet',
'union', 'intersection','difference',
)
# hack to overcome dynamic-linking headache.
from _OOBTree import *
from zope.interface import moduleProvides
zope.interface.moduleProvides(BTrees.Interfaces.IObjectObjectBTreeModule)
from .Interfaces import IObjectObjectBTreeModule
from ._base import Bucket
from ._base import Set
from ._base import Tree as BTree
from ._base import TreeSet
from ._base import difference as _difference
from ._base import intersection as _intersection
from ._base import set_operation as _set_operation
from ._base import to_ob as _to_key
from ._base import to_ob as _to_value
from ._base import union as _union
_BUCKET_SIZE = 30
_TREE_SIZE = 250
using64bits = False
class OOBucketPy(Bucket):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
_to_value = _to_value
class OOSetPy(Set):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
class OOBTreePy(BTree):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
class OOTreeSetPy(TreeSet):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
# Can't declare forward refs, so fix up afterwards:
OOBucketPy._mapping_type = OOBucketPy._bucket_type = OOBucketPy
OOBucketPy._set_type = OOSetPy
OOSetPy._mapping_type = OOBucketPy
OOSetPy._set_type = OOSetPy._bucket_type = OOSetPy
OOBTreePy._mapping_type = OOBTreePy._bucket_type = OOBucketPy
OOBTreePy._set_type = OOSetPy
OOTreeSetPy._mapping_type = OOBucketPy
OOTreeSetPy._set_type = OOTreeSetPy._bucket_type = OOSetPy
differencePy = _set_operation(_difference, OOSetPy)
unionPy = _set_operation(_union, OOSetPy)
intersectionPy = _set_operation(_intersection, OOSetPy)
try:
from _OOBTree import OOBucket
from _OOBTree import OOSet
from _OOBTree import OOBTree
from _OOBTree import OOTreeSet
from _OOBTree import difference
from _OOBTree import union
from _OOBTree import intersection
except ImportError: #pragma NO COVER
OOBucket = OOBucketPy
OOSet = OOSetPy
OOBTree = OOBTreePy
OOTreeSet = OOTreeSetPy
difference = differencePy
union = unionPy
intersection = intersectionPy
Bucket = OOBucket
Set = OOSet
BTree = OOBTree
TreeSet = OOTreeSet
moduleProvides(IObjectObjectBTreeModule)
This diff is collapsed.
......@@ -32,15 +32,24 @@ addresses and/or object identity (the synthesized bucket has an address
that doesn't exist in the actual BTree).
"""
from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet
from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet
from BTrees.IFBTree import IFBTree, IFBucket, IFSet, IFTreeSet
from BTrees.OLBTree import OLBTree, OLBucket, OLSet, OLTreeSet
from BTrees.LOBTree import LOBTree, LOBucket, LOSet, LOTreeSet
from BTrees.LLBTree import LLBTree, LLBucket, LLSet, LLTreeSet
from BTrees.IFBTree import IFBTreePy, IFBucketPy, IFSetPy, IFTreeSetPy
from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet
from BTrees.IIBTree import IIBTreePy, IIBucketPy, IISetPy, IITreeSetPy
from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
from BTrees.IOBTree import IOBTreePy, IOBucketPy, IOSetPy, IOTreeSetPy
from BTrees.LFBTree import LFBTree, LFBucket, LFSet, LFTreeSet
from BTrees.LFBTree import LFBTreePy, LFBucketPy, LFSetPy, LFTreeSetPy
from BTrees.LLBTree import LLBTree, LLBucket, LLSet, LLTreeSet
from BTrees.LLBTree import LLBTreePy, LLBucketPy, LLSetPy, LLTreeSetPy
from BTrees.LOBTree import LOBTree, LOBucket, LOSet, LOTreeSet
from BTrees.LOBTree import LOBTreePy, LOBucketPy, LOSetPy, LOTreeSetPy
from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
from BTrees.OIBTree import OIBTreePy, OIBucketPy, OISetPy, OITreeSetPy
from BTrees.OLBTree import OLBTree, OLBucket, OLSet, OLTreeSet
from BTrees.OLBTree import OLBTreePy, OLBucketPy, OLSetPy, OLTreeSetPy
from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet
from BTrees.OOBTree import OOBTreePy, OOBucketPy, OOSetPy, OOTreeSetPy
from BTrees.utils import positive_id
from BTrees.utils import oid_repr
......@@ -59,6 +68,9 @@ for kv in ('OO',
('Set', (TYPE_BUCKET, False)),
):
_type2kind[globals()[kv+name]] = kind
py = kv + name + 'Py'
if py in globals():
_type2kind[globals()[py]] = kind
# Return pair
#
......@@ -114,7 +126,14 @@ for kv in ('OO',
'LL', 'LO', 'OL', 'LF',
):
_btree2bucket[globals()[kv+'BTree']] = globals()[kv+'Bucket']
py = kv + 'BTreePy'
if py in globals():
_btree2bucket[globals()[py]] = globals()[kv+'BucketPy']
_btree2bucket[globals()[kv+'TreeSet']] = globals()[kv+'Set']
py = kv + 'TreeSetPy'
if py in globals():
_btree2bucket[globals()[kv+'TreeSetPy']] = globals()[kv+'SetPy']
def crack_btree(t, is_mapping):
state = t.__getstate__()
......@@ -349,7 +368,7 @@ class Checker(Walker):
".".join(map(str, path)))
self.errors.append(s)
class Printer(Walker):
class Printer(Walker): #pragma NO COVER
def __init__(self, obj):
Walker.__init__(self, obj)
......@@ -403,6 +422,6 @@ def check(btree):
Checker(btree).check()
def display(btree):
def display(btree): #pragma NO COVER
"Display the internal structure of a BTree, Bucket, TreeSet or Set."
Printer(btree).display()
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -15,5 +15,119 @@
# fsBTrees are data structures used for ZODB FileStorage. They are not
# expected to be "public" excpect to FileStorage.
# hack to overcome dynamic-linking headache.
from _fsBTree import *
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'fsBucket', 'fsSet', 'fsBTree', 'fsTreeSet',
'union', 'intersection', 'difference', 'multiunion',
)
from zope.interface import moduleProvides
from .Interfaces import IIntegerObjectBTreeModule
from ._base import Bucket
from ._base import Set
from ._base import Tree as BTree
from ._base import TreeSet
from ._base import difference as _difference
from ._base import intersection as _intersection
from ._base import multiunion as _multiunion
from ._base import set_operation as _set_operation
from ._base import to_str as _to_str
from ._base import union as _union
_BUCKET_SIZE = 500
_TREE_SIZE = 500
using64bits = False
_to_key = _to_str(2)
_to_value = _to_str(6)
class fsBucketPy(Bucket):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
_to_value = _to_value
def MERGE_WEIGHT(self, value, weight):
return value
def toString(self):
return ''.join(self._keys) + ''.join(self._values)
def fromString(self, v):
length = len(v)
if length % 8 != 0:
raise ValueError()
count = length // 8
keys, values = v[:count*2], v[count*2:]
self.clear()
while keys and values:
key, keys = keys[:2], keys[2:]
value, values = values[:6], values[6:]
self._keys.append(key)
self._values.append(value)
return self
class fsSetPy(Set):
MAX_SIZE = _BUCKET_SIZE
_to_key = _to_key
class fsBTreePy(BTree):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
def MERGE_WEIGHT(self, value, weight):
return value
class fsTreeSetPy(TreeSet):
MAX_SIZE = _TREE_SIZE
_to_key = _to_key
# Can't declare forward refs, so fix up afterwards:
fsBucketPy._mapping_type = fsBucketPy._bucket_type = fsBucketPy
fsBucketPy._set_type = fsSetPy
fsSetPy._mapping_type = fsBucketPy
fsSetPy._set_type = fsSetPy._bucket_type = fsSetPy
fsBTreePy._mapping_type = fsBTreePy._bucket_type = fsBucketPy
fsBTreePy._set_type = fsSetPy
fsTreeSetPy._mapping_type = fsBucketPy
fsTreeSetPy._set_type = fsTreeSetPy._bucket_type = fsSetPy
differencePy = _set_operation(_difference, fsSetPy)
unionPy = _set_operation(_union, fsSetPy)
intersectionPy = _set_operation(_intersection, fsSetPy)
multiunionPy = _set_operation(_multiunion, fsSetPy)
try:
from _fsBTree import fsBucket
from _fsBTree import fsSet
from _fsBTree import fsBTree
from _fsBTree import fsTreeSet
from _fsBTree import difference
from _fsBTree import union
from _fsBTree import intersection
from _fsBTree import multiunion
except ImportError: #pragma NO COVER
fsBucket = fsBucketPy
fsSet = fsSetPy
fsBTree = fsBTreePy
fsTreeSet = fsTreeSetPy
difference = differencePy
union = unionPy
intersection = intersectionPy
multiunion = multiunionPy
Bucket = fsBucket
Set = fsSet
BTree = fsBTree
TreeSet = fsTreeSet
moduleProvides(IIntegerObjectBTreeModule)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -11,26 +11,57 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import doctest
import unittest
def test_fsbucket_string_conversion():
"""
fsBuckets have toString and fromString methods that can be used to
get and set their state very efficiently:
>>> from BTrees.fsBTree import fsBucket
>>> b = fsBucket([(c*2, c*6) for c in 'abcdef'])
>>> import pprint
>>> b.toString()
'aabbccddeeffaaaaaabbbbbbccccccddddddeeeeeeffffff'
class fsBucketTests(unittest.TestCase):
>>> b2 = fsBucket().fromString(b.toString())
>>> b.__getstate__() == b2.__getstate__()
True
def _getTargetClass(self):
from BTrees.fsBTree import fsBucket
return fsBucket
"""
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)
def test_MERGE_WEIGHT(self):
bucket = self._makeOne()
self.assertEqual(bucket.MERGE_WEIGHT(42, 17), 42)
def test_toString(self):
bucket = self._makeOne([(c*2, c*6) for c in 'abcdef'])
self.assertEqual(bucket.toString(),
'aabbccddeeffaaaaaabbbbbbccccccddddddeeeeeeffffff')
def test_fromString(self):
before = self._makeOne([(c*2, c*6) for c in 'abcdef'])
after = before.fromString(before.toString())
self.assertEqual(before.__getstate__(), after.__getstate__())
def test_fromString_empty(self):
before = self._makeOne([(c*2, c*6) for c in 'abcdef'])
after = before.fromString('')
self.assertEqual(after.__getstate__(), ((),))
def test_fromString_invalid(self):
bucket = self._makeOne([(c*2, c*6) for c in 'abcdef'])
self.assertRaises(ValueError, bucket.fromString, 'xxx')
def test_suite():
return doctest.DocTestSuite()
class fsBTreeTests(unittest.TestCase):
def _getTargetClass(self):
from BTrees.fsBTree import fsBTree
return fsBTree
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)
def test_MERGE_WEIGHT(self):
bucket = self._makeOne()
self.assertEqual(bucket.MERGE_WEIGHT(42, 17), 42)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(fsBucketTests),
))
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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