Commit d49ff39e authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #123 from zopefoundation/reduce-boilerplate

Remove most all the boilerplate required to add new trees
parents 7d439db2 2038bcb6
......@@ -85,14 +85,14 @@ script:
- python --version
- |
if [[ "$WITH_COVERAGE" == "1" ]]; then
coverage run -m zope.testrunner --test-path=. --auto-color --auto-progress --verbose
python -m coverage run -m zope.testrunner --test-path=. --auto-color --auto-progress --verbose
else
zope-testrunner --test-path=. --auto-color --auto-progress --verbose
python -m zope.testrunner --test-path=. --auto-color --auto-progress --verbose
fi
- python setup.py -q bdist_wheel
after_success:
- if [[ "$WITH_COVERAGE" == "1" ]]; then coveralls; fi
- if [[ "$WITH_COVERAGE" == "1" ]]; then python -m coveralls; fi
- |
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
# macpython 3.5 doesn't support recent TLS protocols which causes twine
......
......@@ -77,28 +77,117 @@ static void PyVar_Assign(PyObject **v, PyObject *e) { Py_XDECREF(*v); *v=e;}
#error "PY_LONG_LONG required but not defined"
#endif
static int
longlong_handle_overflow(PY_LONG_LONG result, int overflow)
{
if (overflow)
{
/* Python 3 tends to have an exception already set, Python 2 not so much */
if (!PyErr_Occurred())
PyErr_SetString(PyExc_OverflowError, "couldn't convert integer to C long long");
return 0;
}
else if (result == -1 && PyErr_Occurred())
/* An exception has already been raised. */
return 0;
return 1;
}
#ifdef NEED_LONG_LONG_KEYS
#if defined(ZODB_UNSIGNED_VALUE_INTS) || defined(ZODB_UNSIGNED_KEY_INTS)
static int
ulonglong_check(PyObject *ob)
{
#ifndef PY3K
if (PyInt_Check(ob))
{
long tmp;
tmp = PyInt_AS_LONG(ob);
if (tmp < 0) {
PyErr_SetString(PyExc_OverflowError, "unsigned value less than 0");
return 0;
}
return 1;
}
#endif
if (!PyLong_Check(ob))
{
return 0;
}
if (PyLong_AsUnsignedLongLong(ob) == (unsigned long long)-1 && PyErr_Occurred())
{
return 0;
}
return 1;
}
#endif /* defined(ZODB_UNSIGNED_VALUE_INTS) || defined(ZODB_UNSIGNED_KEY_INTS) */
static int
longlong_check(PyObject *ob)
{
if (INT_CHECK(ob))
#ifndef PY3K
/* Python's small integers can always fit into a long long. */
if (PyInt_Check(ob))
return 1;
#endif
if (PyLong_Check(ob)) {
int overflow;
(void)PyLong_AsLongLongAndOverflow(ob, &overflow);
if (overflow)
goto overflow;
return 1;
PY_LONG_LONG result;
result = PyLong_AsLongLongAndOverflow(ob, &overflow);
return longlong_handle_overflow(result, overflow);
}
return 0;
overflow:
PyErr_SetString(PyExc_ValueError,
"longlong_check: long integer out of range");
return 0;
}
#endif
#if defined(ZODB_UNSIGNED_VALUE_INTS) || defined(ZODB_UNSIGNED_KEY_INTS)
static PyObject *
ulonglong_as_object(unsigned PY_LONG_LONG val)
{
if ((val > LONG_MAX))
return PyLong_FromUnsignedLongLong(val);
return UINT_FROM_LONG((unsigned long)val);
}
static int
ulonglong_convert(PyObject *ob, unsigned PY_LONG_LONG *value)
{
unsigned PY_LONG_LONG val;
#ifndef PY3K
if (PyInt_Check(ob))
{
long tmp;
tmp = PyInt_AS_LONG(ob);
if (tmp < 0) {
PyErr_SetString(PyExc_OverflowError, "unsigned value less than 0");
return 0;
}
(*value) = (unsigned PY_LONG_LONG)tmp;
return 1;
}
#endif
if (!PyLong_Check(ob))
{
PyErr_SetString(PyExc_TypeError, "expected integer key");
return 0;
}
val = PyLong_AsUnsignedLongLong(ob);
if (val == (unsigned long long)-1 && PyErr_Occurred())
return 0;
(*value) = val;
return 1;
}
#endif /* defined(ZODB_UNSIGNED_VALUE_INTS) || defined(ZODB_UNSIGNED_KEY_INTS) */
static PyObject *
longlong_as_object(PY_LONG_LONG val)
{
......@@ -107,10 +196,11 @@ longlong_as_object(PY_LONG_LONG val)
return INT_FROM_LONG((long)val);
}
static int
longlong_convert(PyObject *ob, PY_LONG_LONG *value)
{
PY_LONG_LONG val;
int overflow;
#ifndef PY3K
if (PyInt_Check(ob))
{
......@@ -124,20 +214,15 @@ longlong_convert(PyObject *ob, PY_LONG_LONG *value)
PyErr_SetString(PyExc_TypeError, "expected integer key");
return 0;
}
else
val = PyLong_AsLongLongAndOverflow(ob, &overflow);
if (!longlong_handle_overflow(val, overflow))
{
PY_LONG_LONG val;
int overflow;
val = PyLong_AsLongLongAndOverflow(ob, &overflow);
if (overflow)
goto overflow;
(*value) = val;
return 1;
return 0;
}
overflow:
PyErr_SetString(PyExc_ValueError, "long integer out of range");
return 0;
(*value) = val;
return 1;
}
#endif /* NEED_LONG_LONG_SUPPORT */
......@@ -424,30 +509,30 @@ static char *search_keywords[] = {"min", "max",
static struct PyMethodDef module_methods[] = {
{"difference", (PyCFunction) difference_m, METH_VARARGS,
"difference(o1, o2) -- "
"difference(o1, o2)\n"
"compute the difference between o1 and o2"
},
{"union", (PyCFunction) union_m, METH_VARARGS,
"union(o1, o2) -- compute the union of o1 and o2\n"
"union(o1, o2)\ncompute the union of o1 and o2\n"
},
{"intersection", (PyCFunction) intersection_m, METH_VARARGS,
"intersection(o1, o2) -- "
"intersection(o1, o2)\n"
"compute the intersection of o1 and o2"
},
#ifdef MERGE
{"weightedUnion", (PyCFunction) wunion_m, METH_VARARGS,
"weightedUnion(o1, o2 [, w1, w2]) -- compute the union of o1 and o2\n"
"weightedUnion(o1, o2 [, w1, w2])\ncompute the union of o1 and o2\n"
"\nw1 and w2 are weights."
},
{"weightedIntersection", (PyCFunction) wintersection_m, METH_VARARGS,
"weightedIntersection(o1, o2 [, w1, w2]) -- "
"weightedIntersection(o1, o2 [, w1, w2])\n"
"compute the intersection of o1 and o2\n"
"\nw1 and w2 are weights."
},
#endif
#ifdef MULTI_INT_UNION
{"multiunion", (PyCFunction) multiunion_m, METH_VARARGS,
"multiunion(seq) -- compute union of a sequence of integer sets.\n"
"multiunion(seq)\ncompute union of a sequence of integer sets.\n"
"\n"
"Each element of seq must be an integer set, or convertible to one\n"
"via the set iteration protocol. The union returned is an IISet."
......
......@@ -57,7 +57,9 @@
** self The bucket
** keyarg The key to look for
** has_key Boolean; if true, return a true/false result; else return
** the value associated with the key.
** the value associated with the key. When true, ignore the TypeError from
** a key conversion issue, instead
** transforming it into a KeyError.
**
** Return
** If has_key:
......@@ -81,7 +83,15 @@ _bucket_get(Bucket *self, PyObject *keyarg, int has_key)
int copied = 1;
COPY_KEY_FROM_ARG(key, keyarg, copied);
UNLESS (copied) return NULL;
UNLESS (copied)
{
if (has_key && PyErr_ExceptionMatches(PyExc_TypeError))
{
PyErr_Clear();
PyErr_SetObject(PyExc_KeyError, keyarg);
}
return NULL;
}
UNLESS (PER_USE(self)) return NULL;
......@@ -106,7 +116,17 @@ Done:
static PyObject *
bucket_getitem(Bucket *self, PyObject *key)
{
return _bucket_get(self, key, 0);
PyObject* result;
result = _bucket_get(self, key, 0);
if (result == NULL && PyErr_ExceptionMatches(PyExc_TypeError))
{
PyErr_Clear();
PyErr_SetObject(PyExc_KeyError, key);
}
return result;
}
/*
......@@ -1448,6 +1468,10 @@ bucket_contains(Bucket *self, PyObject *key)
result = INT_AS_LONG(asobj) ? 1 : 0;
Py_DECREF(asobj);
}
else if (PyErr_ExceptionMatches(PyExc_KeyError)) {
PyErr_Clear();
result = 0;
}
return result;
}
......@@ -1465,6 +1489,10 @@ bucket_getm(Bucket *self, PyObject *args)
r = _bucket_get(self, key, 0);
if (r)
return r;
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
PyErr_Clear();
PyErr_SetObject(PyExc_KeyError, key);
}
if (!PyErr_ExceptionMatches(PyExc_KeyError))
return NULL;
PyErr_Clear();
......
##############################################################################
#
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'IFBucket', 'IFSet', 'IFBTree', 'IFTreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection', 'multiunion',
)
from zope.interface import moduleProvides
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 _TreeIterator
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
from ._base import _fix_pickle
from ._compat import import_c_extension
_BUCKET_SIZE = 120
_TREE_SIZE = 500
using64bits = False
class IFBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class IFSetPy(Set):
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class IFBTreePy(BTree):
max_leaf_size = _BUCKET_SIZE
max_internal_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_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class IFTreeIteratorPy(_TreeIterator):
pass
# 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)
import_c_extension(globals())
_fix_pickle(globals(), __name__)
moduleProvides(IIntegerFloatBTreeModule)
##############################################################################
#
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'IIBucket', 'IISet', 'IIBTree', 'IITreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection', 'multiunion',
)
from zope.interface import moduleProvides
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 _TreeIterator
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
_to_value = _to_key
from ._base import union as _union
from ._base import weightedIntersection as _weightedIntersection
from ._base import weightedUnion as _weightedUnion
from ._base import _fix_pickle
from ._compat import import_c_extension
_BUCKET_SIZE = 120
_TREE_SIZE = 500
using64bits = False
class IIBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class IISetPy(Set):
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class IIBTreePy(BTree):
max_leaf_size = _BUCKET_SIZE
max_internal_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_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class IITreeIteratorPy(_TreeIterator):
pass
# 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)
import_c_extension(globals())
_fix_pickle(globals(), __name__)
moduleProvides(IIntegerIntegerBTreeModule)
##############################################################################
#
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'IOBucket', 'IOSet', 'IOBTree', 'IOTreeSet',
'union', 'intersection', 'difference', 'multiunion',
)
from zope.interface import moduleProvides
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 _TreeIterator
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
from ._base import _fix_pickle
from ._compat import import_c_extension
_BUCKET_SIZE = 60
_TREE_SIZE = 500
using64bits = False
class IOBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
MERGE_WEIGHT = MERGE_WEIGHT_default
class IOSetPy(Set):
_to_key = _to_key
class IOBTreePy(BTree):
max_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE_WEIGHT = MERGE_WEIGHT_default
class IOTreeSetPy(TreeSet):
max_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
class IOTreeIteratorPy(_TreeIterator):
pass
# 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)
import_c_extension(globals())
_fix_pickle(globals(), __name__)
moduleProvides(IIntegerObjectBTreeModule)
......@@ -451,40 +451,78 @@ class IMergeIntegerKey(IMerge):
class IBTreeFamily(Interface):
"""the 64-bit or 32-bit family"""
IF = Attribute('The IIntegerFloatBTreeModule for this family')
II = Attribute('The IIntegerIntegerBTreeModule for this family')
IO = Attribute('The IIntegerObjectBTreeModule for this family')
IU = Attribute('The IIntegerUnsignedBTreeModule for this family')
UF = Attribute('The IUnsignedFloatBTreeModule for this family')
UI = Attribute('The IUnsignedIntegerBTreeModule for this family')
UO = Attribute('The IUnsignedObjectBTreeModule for this family')
UU = Attribute('The IUnsignedUnsignedBTreeModule for this family')
OI = Attribute('The IObjectIntegerBTreeModule for this family')
II = Attribute('The IIntegerIntegerBTreeModule for this family')
IF = Attribute('The IIntegerFloatBTreeModule for this family')
OO = Attribute('The IObjectObjectBTreeModule for this family')
maxint = Attribute('The maximum integer storable in this family')
minint = Attribute('The minimum integer storable in this family')
OU = Attribute('The IObjectUnsignedBTreeModule for this family')
maxint = Attribute('The maximum signed integer storable in this family')
maxuint = Attribute('The maximum unsigned integer storable in this family')
minint = Attribute('The minimum signed integer storable in this family')
class IIntegerObjectBTreeModule(IBTreeModule, IMerge):
"""keys, or set values, are integers; values are objects.
class _IMergeBTreeModule(IBTreeModule, IMerge):
family = Attribute('The IBTreeFamily of this module')
class IIntegerObjectBTreeModule(_IMergeBTreeModule):
"""keys, or set values, are signed integers; values are objects.
describes IOBTree and LOBTree"""
family = Attribute('The IBTreeFamily of this module')
class IUnsignedObjectBTreeModule(_IMergeBTreeModule):
"""
As for `IIntegerObjectBTreeModule` with unsigned integers.
"""
class IObjectIntegerBTreeModule(IBTreeModule, IIMerge):
"""keys, or set values, are objects; values are integers.
class IObjectIntegerBTreeModule(_IMergeBTreeModule):
"""keys, or set values, are objects; values are signed integers.
Object keys (and set values) must sort reliably (for instance, *not* on
object id)! Homogenous key types recommended.
describes OIBTree and LOBTree"""
family = Attribute('The IBTreeFamily of this module')
class IObjectUnsignedBTreeModule(_IMergeBTreeModule):
"""
As for `IObjectIntegerBTreeModule` with unsigned integers.
"""
class IIntegerIntegerBTreeModule(IBTreeModule, IIMerge, IMergeIntegerKey):
"""keys, or set values, are integers; values are also integers.
class IIntegerIntegerBTreeModule(_IMergeBTreeModule, IMergeIntegerKey):
"""keys, or set values, are signed integers; values are also signed integers.
describes IIBTree and LLBTree"""
family = Attribute('The IBTreeFamily of this module')
class IUnsignedUnsignedBTreeModule(_IMergeBTreeModule, IMergeIntegerKey):
"""
As for `IIntegerIntegerBTreeModule` with unsigned integers.
"""
class IUnsignedIntegerBTreeModule(_IMergeBTreeModule, IMergeIntegerKey):
"""
As for `IIntegerIntegerBTreeModule` with unsigned integers for keys only.
"""
class IIntegerUnsignedBTreeModule(_IMergeBTreeModule, IMergeIntegerKey):
"""
As for `IIntegerIntegerBTreeModule` with unsigned integers for values only.
"""
class IObjectObjectBTreeModule(IBTreeModule, IMerge):
......@@ -499,12 +537,15 @@ class IObjectObjectBTreeModule(IBTreeModule, IMerge):
# the OO flavor of BTrees.
class IIntegerFloatBTreeModule(IBTreeModule, IMerge):
"""keys, or set values, are integers; values are floats.
class IIntegerFloatBTreeModule(_IMergeBTreeModule):
"""keys, or set values, are signed integers; values are floats.
describes IFBTree and LFBTree"""
family = Attribute('The IBTreeFamily of this module')
class IUnsignedFloatBTreeModule(_IMergeBTreeModule):
"""
As for `IIntegerFloatBTreeModule` with unsigned integers.
"""
try:
......
##############################################################################
#
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'LFBucket', 'LFSet', 'LFBTree', 'LFTreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection', 'multiunion',
)
from zope.interface import moduleProvides
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 _TreeIterator
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
from ._base import _fix_pickle
from ._compat import import_c_extension
_BUCKET_SIZE = 120
_TREE_SIZE = 500
using64bits = True
class LFBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class LFSetPy(Set):
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class LFBTreePy(BTree):
max_leaf_size = _BUCKET_SIZE
max_internal_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_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class LFTreeIteratorPy(_TreeIterator):
pass
# 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)
import_c_extension(globals())
_fix_pickle(globals(), __name__)
moduleProvides(IIntegerFloatBTreeModule)
##############################################################################
#
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'LLBucket', 'LLSet', 'LLBTree', 'LLTreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection', 'multiunion',
)
from zope.interface import moduleProvides
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 _TreeIterator
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
from ._base import _fix_pickle
from ._compat import import_c_extension
_BUCKET_SIZE = 120
_TREE_SIZE = 500
using64bits = True
class LLBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class LLSetPy(Set):
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class LLBTreePy(BTree):
max_leaf_size = _BUCKET_SIZE
max_internal_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_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class LLTreeIteratorPy(_TreeIterator):
pass
# 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)
import_c_extension(globals())
_fix_pickle(globals(), __name__)
moduleProvides(IIntegerIntegerBTreeModule)
##############################################################################
#
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'LOBucket', 'LOSet', 'LOBTree', 'LOTreeSet',
'union', 'intersection', 'difference', 'multiunion',
)
from zope.interface import moduleProvides
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 _TreeIterator
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
from ._base import _fix_pickle
from ._compat import import_c_extension
_BUCKET_SIZE = 60
_TREE_SIZE = 500
using64bits = True
class LOBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
MERGE_WEIGHT = MERGE_WEIGHT_default
class LOSetPy(Set):
_to_key = _to_key
class LOBTreePy(BTree):
max_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
MERGE_WEIGHT = MERGE_WEIGHT_default
class LOTreeSetPy(TreeSet):
max_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
class LOTreeIteratorPy(_TreeIterator):
pass
# 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)
import_c_extension(globals())
_fix_pickle(globals(), __name__)
moduleProvides(IIntegerObjectBTreeModule)
##############################################################################
#
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'OIBucket', 'OISet', 'OIBTree', 'OITreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection',
)
from zope.interface import moduleProvides
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 _TreeIterator
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
from ._base import _fix_pickle
from ._compat import import_c_extension
_BUCKET_SIZE = 60
_TREE_SIZE = 250
using64bits = False
class OIBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class OISetPy(Set):
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class OIBTreePy(BTree):
max_leaf_size = _BUCKET_SIZE
max_internal_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_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_float
class OITreeIteratorPy(_TreeIterator):
pass
# 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)
import_c_extension(globals())
_fix_pickle(globals(), __name__)
moduleProvides(IObjectIntegerBTreeModule)
##############################################################################
#
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'OLBucket', 'OLSet', 'OLBTree', 'OLTreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection',
)
from zope.interface import moduleProvides
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 _TreeIterator
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_long as _to_value
from ._base import union as _union
from ._base import weightedIntersection as _weightedIntersection
from ._base import weightedUnion as _weightedUnion
from ._base import _fix_pickle
from ._compat import import_c_extension
_BUCKET_SIZE = 60
_TREE_SIZE = 250
using64bits = True
class OLBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class OLSetPy(Set):
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class OLBTreePy(BTree):
max_leaf_size = _BUCKET_SIZE
max_internal_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_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int
class OLTreeIteratorPy(_TreeIterator):
pass
# 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)
import_c_extension(globals())
_fix_pickle(globals(), __name__)
moduleProvides(IObjectIntegerBTreeModule)
##############################################################################
#
# Copyright (c) 2001-2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__all__ = ('Bucket', 'Set', 'BTree', 'TreeSet',
'OOBucket', 'OOSet', 'OOBTree', 'OOTreeSet',
'union', 'intersection','difference',
)
from zope.interface import moduleProvides
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 _TreeIterator
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
_to_value = _to_key
from ._base import union as _union
from ._base import _fix_pickle
from ._compat import import_c_extension
_BUCKET_SIZE = 30
_TREE_SIZE = 250
using64bits = False
class OOBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
class OOSetPy(Set):
_to_key = _to_key
class OOBTreePy(BTree):
max_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
_to_value = _to_value
class OOTreeSetPy(TreeSet):
max_leaf_size = _BUCKET_SIZE
max_internal_size = _TREE_SIZE
_to_key = _to_key
class OOTreeIteratorPy(_TreeIterator):
pass
# 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)
import_c_extension(globals())
_fix_pickle(globals(), __name__)
moduleProvides(IObjectObjectBTreeModule)
......@@ -129,7 +129,7 @@ initSetIteration(SetIteration *i, PyObject *s, int useValues)
#endif
else
{
PyErr_SetString(PyExc_TypeError, "invalid argument");
PyErr_SetString(PyExc_TypeError, "set operation: invalid argument, cannot iterate");
return -1;
}
......@@ -143,7 +143,7 @@ initSetIteration(SetIteration *i, PyObject *s, int useValues)
#endif
static int
copyRemaining(Bucket *r, SetIteration *i, int merge,
copyRemaining(Bucket *r, SetIteration *i, int merge,
/* See comment # 42 */
#ifdef MERGE
......@@ -209,7 +209,7 @@ set_operation(PyObject *s1, PyObject *s2,
difference is one. This works fine in the int value and float value
cases but makes no sense in the object value case. In the object
value case, we don't do merging, so we don't use the weights, so it
doesn't matter what they are.
doesn't matter what they are.
*/
#ifdef MERGE
VALUE_TYPE w1, VALUE_TYPE w2,
......@@ -427,7 +427,7 @@ wunion_m(PyObject *ignored, PyObject *args)
PyObject *o1, *o2;
VALUE_TYPE w1 = 1, w2 = 1;
UNLESS(PyArg_ParseTuple(args, "OO|" VALUE_PARSE VALUE_PARSE,
UNLESS(PyArg_ParseTuple(args, "OO|" VALUE_PARSE VALUE_PARSE,
&o1, &o2, &w1, &w2)
) return NULL;
......@@ -437,7 +437,7 @@ wunion_m(PyObject *ignored, PyObject *args)
return Py_BuildValue(VALUE_PARSE "O", w1, o1);
o1 = set_operation(o1, o2, 1, 1, w1, w2, 1, 1, 1);
if (o1)
if (o1)
ASSIGN(o1, Py_BuildValue(VALUE_PARSE "O", (VALUE_TYPE)1, o1));
return o1;
......@@ -449,7 +449,7 @@ wintersection_m(PyObject *ignored, PyObject *args)
PyObject *o1, *o2;
VALUE_TYPE w1 = 1, w2 = 1;
UNLESS(PyArg_ParseTuple(args, "OO|" VALUE_PARSE VALUE_PARSE,
UNLESS(PyArg_ParseTuple(args, "OO|" VALUE_PARSE VALUE_PARSE,
&o1, &o2, &w1, &w2)
) return NULL;
......
......@@ -37,7 +37,7 @@ _Set_update(Bucket *self, PyObject *seq)
{
int n=0, ind=0;
PyObject *iter, *v;
iter = PyObject_GetIter(seq);
if (iter == NULL)
return -1;
......@@ -177,49 +177,49 @@ set_setstate(Bucket *self, PyObject *args)
static struct PyMethodDef Set_methods[] = {
{"__getstate__", (PyCFunction) bucket_getstate, METH_VARARGS,
"__getstate__() -- Return the picklable state of the object"},
"__getstate__()\nReturn the picklable state of the object"},
{"__setstate__", (PyCFunction) set_setstate, METH_VARARGS,
"__setstate__() -- Set the state of the object"},
"__setstate__()\nSet the state of the object"},
{"keys", (PyCFunction) bucket_keys, METH_VARARGS | METH_KEYWORDS,
"keys() -- Return the keys"},
"keys()\nReturn the keys"},
{"has_key", (PyCFunction) bucket_has_key, METH_O,
"has_key(key) -- Test whether the bucket contains the given key"},
"has_key(key)\nTest whether the bucket contains the given key"},
{"clear", (PyCFunction) bucket_clear, METH_VARARGS,
"clear() -- Remove all of the items from the bucket"},
"clear()\nRemove all of the items from the bucket"},
{"maxKey", (PyCFunction) Bucket_maxKey, METH_VARARGS,
"maxKey([key]) -- Find the maximum key\n\n"
"maxKey([key])\nFind the maximum key\n\n"
"If an argument is given, find the maximum <= the argument"},
{"minKey", (PyCFunction) Bucket_minKey, METH_VARARGS,
"minKey([key]) -- Find the minimum key\n\n"
"minKey([key])\nFind the minimum key\n\n"
"If an argument is given, find the minimum >= the argument"},
#ifdef PERSISTENT
{"_p_resolveConflict",
(PyCFunction) bucket__p_resolveConflict, METH_VARARGS,
"_p_resolveConflict() -- Reinitialize from a newly created copy"},
"_p_resolveConflict()\nReinitialize from a newly created copy"},
{"_p_deactivate",
(PyCFunction) bucket__p_deactivate, METH_VARARGS | METH_KEYWORDS,
"_p_deactivate() -- Reinitialize from a newly created copy"},
"_p_deactivate()\nReinitialize from a newly created copy"},
#endif
{"add", (PyCFunction)Set_insert, METH_VARARGS,
"add(id) -- Add a key to the set"},
"add(id)\nAdd a key to the set"},
{"insert", (PyCFunction)Set_insert, METH_VARARGS,
"insert(id) -- Add a key to the set"},
"insert(id)\nAdd a key to the set"},
{"update", (PyCFunction)Set_update, METH_VARARGS,
"update(seq) -- Add the items from the given sequence to the set"},
"update(seq)\nAdd the items from the given sequence to the set"},
{"remove", (PyCFunction)Set_remove, METH_VARARGS,
"remove(id) -- Remove an id from the set"},
"remove(id)\nRemove an id from the set"},
{NULL, NULL} /* sentinel */
};
......
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id$\n"
/* IIBTree - int32_t key, uint32_t value BTree
Implements a collection using int type keys
and int type values
*/
/* Setup template macros */
#define PERSISTENT
#define MOD_NAME_PREFIX "IU"
#define DEFAULT_MAX_BUCKET_SIZE 120
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_UNSIGNED_VALUE_INTS
#include "_compat.h"
#include "intkeymacros.h"
#include "intvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__IUBTree
#else
#define INITMODULE init_IUBTree
#endif
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id: _IIBTree.c 25186 2004-06-02 15:07:33Z jim $\n"
/* IIBTree - int64_t key, uint64_t value BTree
Implements a collection using int type keys
and int type values
*/
/* Setup template macros */
#define PERSISTENT
#define MOD_NAME_PREFIX "LQ"
#define DEFAULT_MAX_BUCKET_SIZE 120
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_64BIT_INTS
#define ZODB_UNSIGNED_VALUE_INTS
#include "_compat.h"
#include "intkeymacros.h"
#include "intvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__LQBTree
#else
#define INITMODULE init_LQBTree
#endif
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id: _OIBTree.c 25186 2004-06-02 15:07:33Z jim $\n"
/* OQBTree - object key, uint64_t value BTree
Implements a collection using object type keys
and int type values
*/
#define PERSISTENT
#define MOD_NAME_PREFIX "OQ"
#define DEFAULT_MAX_BUCKET_SIZE 60
#define DEFAULT_MAX_BTREE_SIZE 250
#define ZODB_64BIT_INTS
#define ZODB_UNSIGNED_VALUE_INTS
#include "_compat.h"
#include "objectkeymacros.h"
#include "intvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__OQBTree
#else
#define INITMODULE init_OQBTree
#endif
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id$\n"
/* OUBTree - object key, uint32_t value BTree
Implements a collection using object type keys
and int type values
*/
#define PERSISTENT
#define MOD_NAME_PREFIX "OU"
#define DEFAULT_MAX_BUCKET_SIZE 60
#define DEFAULT_MAX_BTREE_SIZE 250
#define ZODB_UNSIGNED_VALUE_INTS
#include "_compat.h"
#include "objectkeymacros.h"
#include "intvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__OUBTree
#else
#define INITMODULE init_OUBTree
#endif
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id: _IFBTree.c 67074 2006-04-17 19:13:39Z fdrake $\n"
/* QFBTree - uint64_t key, float value BTree
Implements a collection using int type keys
and float type values
*/
/* Setup template macros */
#define PERSISTENT
#define MOD_NAME_PREFIX "QF"
#define DEFAULT_MAX_BUCKET_SIZE 120
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_64BIT_INTS
#define ZODB_UNSIGNED_KEY_INTS
#include "_compat.h"
#include "intkeymacros.h"
#include "floatvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__QFBTree
#else
#define INITMODULE init_QFBTree
#endif
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id: _IIBTree.c 25186 2004-06-02 15:07:33Z jim $\n"
/* QLBTree - uint64_t key, int64_t value BTree
Implements a collection using int type keys
and int type values
*/
/* Setup template macros */
#define PERSISTENT
#define MOD_NAME_PREFIX "QL"
#define DEFAULT_MAX_BUCKET_SIZE 120
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_64BIT_INTS
#define ZODB_UNSIGNED_KEY_INTS
#include "_compat.h"
#include "intkeymacros.h"
#include "intvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__QLBTree
#else
#define INITMODULE init_QLBTree
#endif
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id: _IOBTree.c 25186 2004-06-02 15:07:33Z jim $\n"
/* QOBTree - uint64_t key, object value BTree
Implements a collection using int type keys
and object type values
*/
#define PERSISTENT
#define MOD_NAME_PREFIX "QO"
#define DEFAULT_MAX_BUCKET_SIZE 60
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_64BIT_INTS
#define ZODB_UNSIGNED_KEY_INTS
#include "_compat.h"
#include "intkeymacros.h"
#include "objectvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__QOBTree
#else
#define INITMODULE init_QOBTree
#endif
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id: _IIBTree.c 25186 2004-06-02 15:07:33Z jim $\n"
/* QQBTree - uint64_t key, uint64_t value BTree
Implements a collection using int type keys
and int type values
*/
/* Setup template macros */
#define PERSISTENT
#define MOD_NAME_PREFIX "QQ"
#define DEFAULT_MAX_BUCKET_SIZE 120
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_64BIT_INTS
#define ZODB_UNSIGNED_KEY_INTS
#define ZODB_UNSIGNED_VALUE_INTS
#include "_compat.h"
#include "intkeymacros.h"
#include "intvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__QQBTree
#else
#define INITMODULE init_QQBTree
#endif
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id$\n"
/* IFBTree - unsigned int key, float value BTree
Implements a collection using int type keys
and float type values
*/
/* Setup template macros */
#define PERSISTENT
#define MOD_NAME_PREFIX "UF"
#define DEFAULT_MAX_BUCKET_SIZE 120
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_UNSIGNED_KEY_INTS
#include "_compat.h"
#include "intkeymacros.h"
#include "floatvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__UFBTree
#else
#define INITMODULE init_UFBTree
#endif
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id$\n"
/* IIBTree - unsigned int key, int value BTree
Implements a collection using int type keys
and int type values
*/
/* Setup template macros */
#define PERSISTENT
#define MOD_NAME_PREFIX "UI"
#define DEFAULT_MAX_BUCKET_SIZE 120
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_UNSIGNED_KEY_INTS
#include "_compat.h"
#include "intkeymacros.h"
#include "intvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__UIBTree
#else
#define INITMODULE init_UIBTree
#endif
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id$\n"
/* UOBTree - unsigned int key, object value BTree
Implements a collection using unsigned int type keys
and object type values
*/
#define PERSISTENT
#define MOD_NAME_PREFIX "UO"
#define DEFAULT_MAX_BUCKET_SIZE 60
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_UNSIGNED_KEY_INTS
#include "_compat.h"
#include "intkeymacros.h"
#include "objectvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__UOBTree
#else
#define INITMODULE init_UOBTree
#endif
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#define MASTER_ID "$Id$\n"
/* IIBTree - unsigned int key, unsigned int value BTree
Implements a collection using int type keys
and int type values
*/
/* Setup template macros */
#define PERSISTENT
#define MOD_NAME_PREFIX "UU"
#define DEFAULT_MAX_BUCKET_SIZE 120
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_UNSIGNED_KEY_INTS
#define ZODB_UNSIGNED_VALUE_INTS
#include "_compat.h"
#include "intkeymacros.h"
#include "intvaluemacros.h"
#ifdef PY3K
#define INITMODULE PyInit__UUBTree
#else
#define INITMODULE init_UUBTree
#endif
#include "BTreeModuleTemplate.c"
......@@ -12,35 +12,110 @@
#
#############################################################################
import sys
import zope.interface
import BTrees.Interfaces
from ._module_builder import create_module
__all__ = [
'family32',
'family64',
]
_FAMILIES = (
# Signed 32-bit keys
"IO", # object value
"II", # self value
"IF", # float value
"IU", # opposite sign value
# Unsigned 32-bit keys
"UO", # object value
"UU", # self value
"UF", # float value
"UI", # opposite sign value
# Signed 64-bit keys
"LO", # object value
"LL", # self value
"LF", # float value
"LQ", # opposite sign value
# Unsigned 64-bit keys
"QO", # object value
"QQ", # self value
"QF", # float value
"QL", # opposite sign value
# Object keys
"OO", # object
"OI", # 32-bit signed
"OU", # 32-bit unsigned
"OL", # 64-bit signed
"OQ", # 64-bit unsigned
)
# XXX: Do this without completely ruining
# pylint and other static analysis.
for family in _FAMILIES:
mod = create_module(family)
name = vars(mod)['__name__']
sys.modules[name] = mod
globals()[name.split('.', 1)[1]] = mod
__all__.append(name)
@zope.interface.implementer(BTrees.Interfaces.IBTreeFamily)
class _Family(object):
from BTrees import OOBTree as OO
_BITSIZE = 0
minint = maxint = maxuint = None
def __init__(self):
self.maxint = int(2 ** (self._BITSIZE - 1) - 1)
self.minint = int(-self.maxint - 1)
self.maxuint = int(2 ** self._BITSIZE - 1)
def __str__(self):
return (
"BTree family using {} bits. "
"Supports signed integer values from {:,} to {:,} "
"and maximum unsigned integer value {:,}."
).format(self._BITSIZE, self.minint, self.maxint, self.maxuint)
def __repr__(self):
return "<%s>" % (
self
)
class _Family32(_Family):
_BITSIZE = 32
from BTrees import OIBTree as OI
from BTrees import OUBTree as OU
from BTrees import IFBTree as IF
from BTrees import IIBTree as II
from BTrees import IOBTree as IO
from BTrees import IFBTree as IF
from BTrees import IUBTree as IU
maxint = int(2**31-1)
minint = -maxint - 1
from BTrees import UFBTree as UF
from BTrees import UIBTree as UI
from BTrees import UOBTree as UO
from BTrees import UUBTree as UU
def __reduce__(self):
return _family32, ()
class _Family64(_Family):
_BITSIZE = 64
from BTrees import OLBTree as OI
from BTrees import OQBTree as OU
from BTrees import LFBTree as IF
from BTrees import LLBTree as II
from BTrees import LOBTree as IO
from BTrees import LFBTree as IF
from BTrees import LQBTree as IU
maxint = 2**63-1
minint = -maxint - 1
from BTrees import QFBTree as UF
from BTrees import QLBTree as UI
from BTrees import QOBTree as UO
from BTrees import QQBTree as UU
def __reduce__(self):
return _family64, ()
......@@ -53,17 +128,16 @@ def _family64():
return family64
_family64.__safe_for_unpickling__ = True
#: 32-bit BTree family.
family32 = _Family32()
family64 = _Family64()
#: 64-bit BTree family.
family64 = _Family64()
BTrees.family64.IO.family = family64
BTrees.family64.OI.family = family64
BTrees.family64.IF.family = family64
BTrees.family64.II.family = family64
BTrees.family32.IO.family = family32
BTrees.family32.OI.family = family32
BTrees.family32.IF.family = family32
BTrees.family32.II.family = family32
for _family in family32, family64:
for _mod_name in (
"OI", "OU",
'IO', "II", "IF", "IU",
"UO", "UU", "UF", "UI",
):
getattr(_family, _mod_name).family = _family
......@@ -14,18 +14,24 @@
"""Python BTree implementation
"""
from struct import Struct
from struct import error as struct_error
from operator import index
from persistent import Persistent
from .Interfaces import BTreesConflictError
from ._compat import PY3
from ._compat import compare
from ._compat import int_types
from ._compat import xrange
# XXX: Fix these. These ignores are temporary to
# reduce the noise and help find specific issues during
# refactoring
# pylint:disable=too-many-lines,fixme,protected-access
# pylint:disable=attribute-defined-outside-init,redefined-builtin,no-else-return
# pylint:disable=redefined-outer-name,bad-continuation,unused-variable
# pylint:disable=too-many-branches,too-many-statements,arguments-differ,assigning-non-slot
# pylint:disable=superfluous-parens,inconsistent-return-statements,unidiomatic-typecheck
# pylint:disable=deprecated-method,consider-using-enumerate
_marker = object()
......@@ -33,6 +39,11 @@ _marker = object()
class _Base(Persistent):
__slots__ = ()
# This is used to allocate storage for the keys.
# It's probably here so that we could, for example, use
# an ``array.array`` for native types. But nothing actually does
# that, everything is stored boxed.
# TODO: Figure out why not.
_key_type = list
def __init__(self, items=None):
......@@ -190,7 +201,13 @@ class _BucketBase(_Base):
return iter(self._keys)
def __contains__(self, key):
return (self._search(self._to_key(key)) >= 0)
try:
tree_key = self._to_key(key)
except TypeError:
# Can't convert the key, so can't possibly be in the tree
return False
return (self._search(tree_key) >= 0)
has_key = __contains__
......@@ -252,25 +269,6 @@ class _SetIteration(object):
return self
_object_lt = getattr(object, '__lt__', _marker)
def _no_default_comparison(key):
# Enforce test that key has non-default comparison.
if key is None:
return
if type(key) is object:
raise TypeError("Can't use object() as keys")
lt = getattr(key, '__lt__', None)
if lt is not None:
# CPython 3.x follows PEP 252, defining '__objclass__'
if getattr(lt, '__objclass__', None) is object:
lt = None # pragma: no cover Py3k
# PyPy3 doesn't follow PEP 252, but defines '__func__'
elif getattr(lt, '__func__', None) is _object_lt:
lt = None # pragma: no cover PyPy3
if (lt is None and
getattr(key, '__cmp__', None) is None):
raise TypeError("Object has default comparison")
class Bucket(_BucketBase):
......@@ -308,7 +306,6 @@ class Bucket(_BucketBase):
raise TypeError('items must be a sequence of 2-tuples')
def __setitem__(self, key, value):
_no_default_comparison(key)
self._set(self._to_key(key), self._to_value(value))
def __delitem__(self, key):
......@@ -319,13 +316,23 @@ class Bucket(_BucketBase):
self._values = self._value_type()
def get(self, key, default=None):
index = self._search(self._to_key(key))
try:
key = self._to_key(key)
except TypeError:
# Can't convert, cannot possibly be present.
return default
index = self._search(key)
if index < 0:
return default
return self._values[index]
def __getitem__(self, key):
index = self._search(self._to_key(key))
try:
tree_key = self._to_key(key)
except TypeError:
# Can't convert, so cannot possibly be present.
raise KeyError(key)
index = self._search(tree_key)
if index < 0:
raise KeyError(key)
return self._values[index]
......@@ -809,7 +816,6 @@ class _Tree(_Base):
set(*i)
def __setitem__(self, key, value):
_no_default_comparison(key)
self._set(self._to_key(key), self._to_value(value))
def __delitem__(self, key):
......@@ -990,7 +996,7 @@ class _Tree(_Base):
if isinstance(first.child, type(self)):
next._firstbucket = first.child._firstbucket
else:
next._firstbucket = first.child;
next._firstbucket = first.child
return next
def _del(self, key):
......@@ -1111,7 +1117,7 @@ class _Tree(_Base):
"BTree has firstbucket different than "
"its first child's firstbucket")
for i in range(len(data)-1):
data[i].child._check(data[i+1].child._firstbucket)
data[i].child._check(data[i+1].child._firstbucket)
data[-1].child._check(nextbucket)
elif child_class is self._bucket_type:
assert_(self._firstbucket is data[0].child,
......@@ -1297,13 +1303,23 @@ class TreeSet(_Tree):
class set_operation(object):
__slots__ = ('func',
'set_type',
)
__slots__ = (
'func',
'set_type',
'__name__',
'_module',
)
def __init__(self, func, set_type):
self.func = func
self.set_type = set_type
self.__name__ = func.__name__
self._module = func.__module__
__module__ = property(
lambda self: self._module,
lambda self, nv: setattr(self, '_module', nv)
)
def __call__(self, *a, **k):
return self.func(self.set_type, *a, **k)
......@@ -1492,56 +1508,6 @@ def multiunion(set_type, seqs):
result.update(s)
return result
def to_ob(self, v):
return v
def _packer_unpacker(struct_format):
s = Struct(struct_format)
return s.pack, s.unpack
int_pack, int_unpack = _packer_unpacker('i')
def to_int(self, v):
try:
int_pack(index(v))
except (struct_error, TypeError):
raise TypeError('32-bit integer expected')
return int(v)
float_pack = _packer_unpacker('f')[0]
def to_float(self, v):
try:
float_pack(v)
except struct_error:
raise TypeError('float expected')
return float(v)
long_pack, long_unpack = _packer_unpacker('q')
def to_long(self, v):
try:
long_pack(index(v))
except (struct_error, TypeError):
if isinstance(v, int_types):
raise ValueError("Value out of range", v)
raise TypeError('64-bit integer expected')
return int(v)
def to_bytes(l):
def to(self, v):
if not (isinstance(v, bytes) and len(v) == l):
raise TypeError("%s-byte array expected" % l)
return v
return to
tos = dict(I=to_int, L=to_long, F=to_float, O=to_ob)
MERGE_DEFAULT_int = 1
MERGE_DEFAULT_float = 1.0
def MERGE(self, value1, weight1, value2, weight2):
return (value1 * weight1) + (value2 * weight2)
......
......@@ -23,7 +23,15 @@
#define INTERN PyUnicode_InternFromString
#define INT_FROM_LONG(x) PyLong_FromLong(x)
#define INT_CHECK(x) PyLong_Check(x)
/* PyLong_AS_LONG isn't a documnted API function. But because of
* an issue in persistent/_compat.h, if we define it to be
* the documented function, PyLong_AsLong, we get
* warnings about macro redefinition. See
* https://github.com/zopefoundation/persistent/issues/125
*/
#define INT_AS_LONG(x) PyLong_AS_LONG(x)
#define UINT_FROM_LONG(x) PyLong_FromUnsignedLong(x)
#define UINT_AS_LONG(x) PyLong_AsUnsignedLong(x)
#define TEXT_FROM_STRING PyUnicode_FromString
#define TEXT_FORMAT PyUnicode_Format
......@@ -43,6 +51,8 @@
#define INT_FROM_LONG(x) PyInt_FromLong(x)
#define INT_CHECK(x) PyInt_Check(x)
#define INT_AS_LONG(x) PyInt_AS_LONG(x)
#define UINT_FROM_LONG(x) PyInt_FromSize_t(x)
#define UINT_AS_LONG(x) PyInt_AsUnsignedLongMask(x)
#define TEXT_FROM_STRING PyString_FromString
#define TEXT_FORMAT PyString_Format
......
......@@ -97,4 +97,4 @@ def import_c_extension(mod_globals):
mod_globals[name] = mod_globals[prefix + name]
# Cleanup
del mod_globals['import_c_extension']
mod_globals.pop('import_c_extension', None)
This diff is collapsed.
##############################################################################
#
# Copyright Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
Support functions to eliminate the boilerplate involved in defining
BTree modules.
"""
import sys
from zope.interface import directlyProvides
def _create_classes(
module_name, key_datatype, value_datatype,
):
from ._base import Bucket
from ._base import MERGE # Won't always want this.
from ._base import Set
from ._base import Tree
from ._base import TreeSet
from ._base import _TreeIterator
from ._base import _fix_pickle
classes = {}
prefix = key_datatype.prefix_code + value_datatype.prefix_code
for base in (
Bucket,
Set,
(Tree, 'BTree'),
TreeSet,
(_TreeIterator, 'TreeIterator'),
):
if isinstance(base, tuple):
base, base_name = base
else:
base_name = base.__name__
# XXX: Consider defining these with their natural names
# now and only aliasing them to 'Py' instead of the
# opposite. That should make pickling easier.
name = prefix + base_name + 'Py'
cls = type(name, (base,), dict(
_to_key=key_datatype,
_to_value=value_datatype,
MERGE=MERGE,
MERGE_WEIGHT=value_datatype.apply_weight,
MERGE_DEFAULT=value_datatype.multiplication_identity,
max_leaf_size=key_datatype.bucket_size_for_value(value_datatype),
max_internal_size=key_datatype.tree_size,
))
cls.__module__ = module_name
classes[cls.__name__] = cls
# Importing the C extension does this for the non-py
# classes.
# TODO: Unify that.
classes[base_name + 'Py'] = cls
for cls in classes.values():
cls._mapping_type = classes['BucketPy']
cls._set_type = classes['SetPy']
if 'Set' in cls.__name__:
cls._bucket_type = classes['SetPy']
else:
cls._bucket_type = classes['BucketPy']
return classes
def _create_set_operations(module_name, key_type, value_type, set_type):
from ._base import set_operation
from ._base import difference
from ._base import intersection
from ._base import multiunion
from ._base import union
from ._base import weightedIntersection
from ._base import weightedUnion
ops = {
op.__name__ + 'Py': set_operation(op, set_type)
for op in (
difference, intersection,
union,
) + (
(weightedIntersection, weightedUnion,)
if value_type.supports_value_union()
else ()
) + (
(multiunion,)
if key_type.supports_value_union()
else ()
)
}
for key, op in ops.items():
op.__module__ = module_name
op.__name__ = key
# TODO: Pickling. These things should be looked up by name.
return ops
def _create_globals(module_name, key_datatype, value_datatype):
classes = _create_classes(module_name, key_datatype, value_datatype)
set_type = classes['SetPy']
set_ops = _create_set_operations(module_name, key_datatype, value_datatype, set_type)
classes.update(set_ops)
return classes
def populate_module(mod_globals,
key_datatype, value_datatype,
interface, module=None):
from ._compat import import_c_extension
from ._base import _fix_pickle
module_name = mod_globals['__name__']
mod_globals.update(_create_globals(module_name, key_datatype, value_datatype))
# XXX: Maybe derive this from the values we create.
mod_all = (
'Bucket', 'Set', 'BTree', 'TreeSet',
'union', 'intersection', 'difference',
'weightedUnion', 'weightedIntersection', 'multiunion',
)
prefix = key_datatype.prefix_code + value_datatype.prefix_code
mod_all += tuple(prefix + c for c in ('Bucket', 'Set', 'BTree', 'TreeSet'))
mod_globals['__all__'] = tuple(c for c in mod_all if c in mod_globals)
mod_globals['using64bits'] = key_datatype.using64bits or value_datatype.using64bits
import_c_extension(mod_globals)
# XXX: We can probably do better than fix_pickle now;
# we can know if we're going to be renaming classes
# ahead of time.
_fix_pickle(mod_globals, module_name)
directlyProvides(module or sys.modules[module_name], interface)
def create_module(prefix):
import types
from . import _datatypes as datatypes
from . import Interfaces
mod = types.ModuleType('BTrees.' + prefix + 'BTree')
key_type = getattr(datatypes, prefix[0])()
val_type = getattr(datatypes, prefix[1])().as_value_type()
iface_name = 'I' + key_type.long_name + val_type.long_name + 'BTreeModule'
iface = getattr(Interfaces, iface_name)
populate_module(vars(mod), key_type, val_type, iface, mod)
return mod
......@@ -32,24 +32,57 @@ addresses and/or object identity (the synthesized bucket has an address
that doesn't exist in the actual BTree).
"""
# 32-bit signed int
from BTrees.IFBTree import IFBTree, IFBucket, IFSet, IFTreeSet
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.IUBTree import IUBTree, IUBucket, IUSet, IUTreeSet
from BTrees.IUBTree import IUBTreePy, IUBucketPy, IUSetPy, IUTreeSetPy
# 32-bit unsigned int
from BTrees.UFBTree import UFBTree, UFBucket, UFSet, UFTreeSet
from BTrees.UFBTree import UFBTreePy, UFBucketPy, UFSetPy, UFTreeSetPy
from BTrees.UIBTree import UIBTree, UIBucket, UISet, UITreeSet
from BTrees.UIBTree import UIBTreePy, UIBucketPy, UISetPy, UITreeSetPy
from BTrees.UOBTree import UOBTree, UOBucket, UOSet, UOTreeSet
from BTrees.UOBTree import UOBTreePy, UOBucketPy, UOSetPy, UOTreeSetPy
from BTrees.UUBTree import UUBTree, UUBucket, UUSet, UUTreeSet
from BTrees.UUBTree import UUBTreePy, UUBucketPy, UUSetPy, UUTreeSetPy
# 64-bit signed int
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.LQBTree import LQBTree, LQBucket, LQSet, LQTreeSet
from BTrees.LQBTree import LQBTreePy, LQBucketPy, LQSetPy, LQTreeSetPy
# 64-bit unsigned int
from BTrees.QFBTree import QFBTree, QFBucket, QFSet, QFTreeSet
from BTrees.QFBTree import QFBTreePy, QFBucketPy, QFSetPy, QFTreeSetPy
from BTrees.QLBTree import QLBTree, QLBucket, QLSet, QLTreeSet
from BTrees.QLBTree import QLBTreePy, QLBucketPy, QLSetPy, QLTreeSetPy
from BTrees.QOBTree import QOBTree, QOBucket, QOSet, QOTreeSet
from BTrees.QOBTree import QOBTreePy, QOBucketPy, QOSetPy, QOTreeSetPy
from BTrees.QQBTree import QQBTree, QQBucket, QQSet, QQTreeSet
from BTrees.QQBTree import QQBTreePy, QQBucketPy, QQSetPy, QQTreeSetPy
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.OUBTree import OUBTree, OUBucket, OUSet, OUTreeSet
from BTrees.OUBTree import OUBTreePy, OUBucketPy, OUSetPy, OUTreeSetPy
from BTrees.OQBTree import OQBTree, OQBucket, OQSet, OQTreeSet
from BTrees.OQBTree import OQBTreePy, OQBucketPy, OQSetPy, OQTreeSetPy
from BTrees.utils import positive_id
from BTrees.utils import oid_repr
......@@ -59,17 +92,22 @@ TYPE_UNKNOWN, TYPE_BTREE, TYPE_BUCKET = range(3)
from ._compat import compare
_type2kind = {}
for kv in ('OO',
'II', 'IO', 'OI', 'IF',
'LL', 'LO', 'OL', 'LF',
):
_FAMILIES = (
'OO', 'OI', 'OU', 'OL', 'OQ',
'II', 'IO', 'IF', 'IU',
'LL', 'LO', 'LF', 'LQ',
'UU', 'UO', 'UF', 'UI',
'QQ', 'QO', 'QF', 'QL',
# Note that fs is missing from this list.
)
for kv in _FAMILIES:
for name, kind in (
('BTree', (TYPE_BTREE, True)),
('Bucket', (TYPE_BUCKET, True)),
('TreeSet', (TYPE_BTREE, False)),
('Set', (TYPE_BUCKET, False)),
):
_type2kind[globals()[kv+name]] = kind
('BTree', (TYPE_BTREE, True)),
('Bucket', (TYPE_BUCKET, True)),
('TreeSet', (TYPE_BTREE, False)),
('Set', (TYPE_BUCKET, False)),
):
_type2kind[globals()[kv + name]] = kind
py = kv + name + 'Py'
_type2kind[globals()[py]] = kind
......@@ -122,10 +160,7 @@ BTREE_EMPTY, BTREE_ONE, BTREE_NORMAL = range(3)
# )
_btree2bucket = {}
for kv in ('OO',
'II', 'IO', 'OI', 'IF',
'LL', 'LO', 'OL', 'LF',
):
for kv in _FAMILIES:
_btree2bucket[globals()[kv+'BTree']] = globals()[kv+'Bucket']
py = kv + 'BTreePy'
_btree2bucket[globals()[py]] = globals()[kv+'BucketPy']
......
......@@ -32,19 +32,19 @@ 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_bytes as _to_bytes
from ._base import union as _union
from ._base import _fix_pickle
from ._compat import import_c_extension
from ._datatypes import Bytes
_BUCKET_SIZE = 500
_TREE_SIZE = 500
using64bits = False
_to_key = _to_bytes(2)
_to_value = _to_bytes(6)
_to_key = Bytes(2)
_to_value = Bytes(6)
# XXX: Port this to use _module_builder.
class fsBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
......
#define KEYMACROS_H "$Id$\n"
#ifndef ZODB_UNSIGNED_KEY_INTS
/* signed keys */
#ifdef ZODB_64BIT_INTS
/* PY_LONG_LONG as key */
#define NEED_LONG_LONG_SUPPORT
......@@ -12,7 +14,7 @@
if (!longlong_convert((ARG), &TARGET)) \
{ \
(STATUS)=0; (TARGET)=0; \
}
}
#else
/* C int as key */
#define KEY_TYPE int
......@@ -23,7 +25,7 @@
long vcopy = INT_AS_LONG(ARG); \
if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \
else if ((int)vcopy != vcopy) { \
PyErr_SetString(PyExc_TypeError, "integer out of range"); \
PyErr_SetString(PyExc_OverflowError, "integer out of range"); \
(STATUS)=0; (TARGET)=0; \
} \
else TARGET = vcopy; \
......@@ -31,6 +33,43 @@
PyErr_SetString(PyExc_TypeError, "expected integer key"); \
(STATUS)=0; (TARGET)=0; }
#endif
#else
/* Unsigned keys */
#ifdef ZODB_64BIT_INTS
/* PY_LONG_LONG as key */
#define NEED_LONG_LONG_SUPPORT
#define NEED_LONG_LONG_KEYS
#define KEY_TYPE unsigned PY_LONG_LONG
#define KEY_CHECK ulonglong_check
#define COPY_KEY_TO_OBJECT(O, K) O=ulonglong_as_object(K)
#define COPY_KEY_FROM_ARG(TARGET, ARG, STATUS) \
if (!ulonglong_convert((ARG), &TARGET)) \
{ \
(STATUS)=0; (TARGET)=0; \
}
#else
/* C int as key */
#define KEY_TYPE unsigned int
#define KEY_CHECK INT_CHECK
#define COPY_KEY_TO_OBJECT(O, K) O=UINT_FROM_LONG(K)
#define COPY_KEY_FROM_ARG(TARGET, ARG, STATUS) \
if (INT_CHECK(ARG)) { \
long vcopy = INT_AS_LONG(ARG); \
if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \
else if (vcopy < 0) { \
PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned int"); \
(STATUS)=0; (TARGET)=0; \
} \
else if ((unsigned int)vcopy != vcopy) { \
PyErr_SetString(PyExc_OverflowError, "integer out of range"); \
(STATUS)=0; (TARGET)=0; \
} \
else TARGET = vcopy; \
} else { \
PyErr_SetString(PyExc_TypeError, "expected integer key"); \
(STATUS)=0; (TARGET)=0; }
#endif
#endif /* ZODB_SIGNED_KEY_INTS */
#undef KEY_TYPE_IS_PYOBJECT
#define TEST_KEY_SET_OR(V, K, T) if ( ( (V) = (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0)) ) , 0 )
......
#define VALUEMACROS_H "$Id$\n"
/*
VALUE_PARSE is used exclusively in SetOpTemplate.c to accept the weight
values for merging. The PyArg_ParseTuple function it uses has no trivial way
to express "unsigned with check", so in the unsigned case, passing negative
values as weights will produce weird output no matter what VALUE_PARSE we
use (because it will immediately get cast to an unsigned).
*/
#ifndef ZODB_UNSIGNED_VALUE_INTS
/*signed values */
#ifdef ZODB_64BIT_INTS
#define NEED_LONG_LONG_SUPPORT
#define VALUE_TYPE PY_LONG_LONG
......@@ -10,7 +20,7 @@
if (!longlong_convert((ARG), &TARGET)) \
{ \
(STATUS)=0; (TARGET)=0; \
}
}
#else
#define VALUE_TYPE int
#define VALUE_PARSE "i"
......@@ -21,7 +31,7 @@
long vcopy = INT_AS_LONG(ARG); \
if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \
else if ((int)vcopy != vcopy) { \
PyErr_SetString(PyExc_TypeError, "integer out of range"); \
PyErr_SetString(PyExc_OverflowError, "integer out of range"); \
(STATUS)=0; (TARGET)=0; \
} \
else TARGET = vcopy; \
......@@ -30,9 +40,47 @@
(STATUS)=0; (TARGET)=0; }
#endif
#else
/* unsigned values */
#ifdef ZODB_64BIT_INTS
/* unsigned, 64-bit values */
#define NEED_LONG_LONG_SUPPORT
#define VALUE_TYPE unsigned PY_LONG_LONG
#define VALUE_PARSE "K"
#define COPY_VALUE_TO_OBJECT(O, K) O=ulonglong_as_object(K)
#define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \
if (!ulonglong_convert((ARG), &TARGET)) \
{ \
(STATUS)=0; (TARGET)=0; \
}
#else
/* unsigned, 32-bit values */
#define VALUE_TYPE unsigned int
#define VALUE_PARSE "I"
#define COPY_VALUE_TO_OBJECT(O, K) O=UINT_FROM_LONG(K)
#define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \
if (INT_CHECK(ARG)) { \
long vcopy = INT_AS_LONG(ARG); \
if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \
else if (vcopy < 0) { \
PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned int"); \
(STATUS)=0; (TARGET)=0; \
} \
else if ((unsigned int)vcopy != vcopy) { \
PyErr_SetString(PyExc_OverflowError, "integer out of range"); \
(STATUS)=0; (TARGET)=0; \
} \
else TARGET = vcopy; \
} else { \
PyErr_SetString(PyExc_TypeError, "expected integer key"); \
(STATUS)=0; (TARGET)=0; }
#endif
#endif
#undef VALUE_TYPE_IS_PYOBJECT
#define TEST_VALUE(K, T) (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0))
#define TEST_VALUE(K, T) (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0))
#define VALUE_SAME(VALUE, TARGET) ( (VALUE) == (TARGET) )
#define DECLARE_VALUE(NAME) VALUE_TYPE NAME
#define DECREF_VALUE(k)
......
# If tests is a package, debugging is a bit easier.
# Make this a package.
This diff is collapsed.
This diff is collapsed.
......@@ -442,8 +442,18 @@ class FamilyTest(unittest.TestCase):
BTrees.family32.II, BTrees.IIBTree)
self.assertEqual(
BTrees.family32.IF, BTrees.IFBTree)
self.assertEqual(
BTrees.family32.UO, BTrees.UOBTree)
self.assertEqual(
BTrees.family32.OU, BTrees.OUBTree)
self.assertEqual(
BTrees.family32.UU, BTrees.UUBTree)
self.assertEqual(
BTrees.family32.UF, BTrees.UFBTree)
self.assertEqual(
BTrees.family32.OO, BTrees.OOBTree)
self.assertEqual(
BTrees.family32.OU, BTrees.OUBTree)
s = IOTreeSet()
s.insert(BTrees.family32.maxint)
self.assertTrue(BTrees.family32.maxint in s)
......@@ -474,8 +484,18 @@ class FamilyTest(unittest.TestCase):
BTrees.family64.II, BTrees.LLBTree)
self.assertEqual(
BTrees.family64.IF, BTrees.LFBTree)
self.assertEqual(
BTrees.family64.UO, BTrees.QOBTree)
self.assertEqual(
BTrees.family64.OU, BTrees.OQBTree)
self.assertEqual(
BTrees.family64.UU, BTrees.QQBTree)
self.assertEqual(
BTrees.family64.UF, BTrees.QFBTree)
self.assertEqual(
BTrees.family64.OO, BTrees.OOBTree)
self.assertEqual(
BTrees.family64.OU, BTrees.OQBTree)
s = LOTreeSet()
s.insert(BTrees.family64.maxint)
self.assertTrue(BTrees.family64.maxint in s)
......@@ -484,8 +504,8 @@ class FamilyTest(unittest.TestCase):
self.assertTrue(BTrees.family64.minint in s)
s = LOTreeSet()
# XXX why oh why do we expect ValueError here, but TypeError in test32?
self.assertRaises(ValueError, s.insert, BTrees.family64.maxint + 1)
self.assertRaises(ValueError, s.insert, BTrees.family64.minint - 1)
self.assertRaises((TypeError, OverflowError), s.insert, BTrees.family64.maxint + 1)
self.assertRaises((TypeError, OverflowError), s.insert, BTrees.family64.minint - 1)
self.check_pickling(BTrees.family64)
def check_pickling(self, family):
......
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.
##############################################################################
#
# Copyright 2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import unittest
from BTrees import _datatypes
to_ob = _datatypes.Any()
to_int = _datatypes.I()
to_float = _datatypes.F()
to_long = _datatypes.L()
to_bytes = _datatypes.Bytes
class TestDatatypes(unittest.TestCase):
def test_to_ob(self):
for thing in "abc", 0, 1.3, (), frozenset((1, 2)), object():
self.assertTrue(to_ob(thing) is thing)
def test_to_int_w_int(self):
self.assertEqual(to_int(3), 3)
def test_to_int_w_long_in_range(self):
try:
self.assertEqual(to_int(long(3)), 3)
except NameError: #Python3
pass
def test_to_int_w_overflow(self):
self.assertRaises(OverflowError, to_int, 2**64)
def test_to_int_w_invalid(self):
self.assertRaises(TypeError, to_int, ())
def test_to_float_w_float(self):
self.assertEqual(to_float(3.14159), 3.14159)
def test_to_float_w_int(self):
self.assertEqual(to_float(3), 3.0)
def test_to_float_w_invalid(self):
self.assertRaises(TypeError, to_float, ())
def test_to_long_w_int(self):
self.assertEqual(to_long(3), 3)
def test_to_long_w_long_in_range(self):
try:
self.assertEqual(to_long(long(3)), 3)
except NameError: #Python3
pass
def test_to_long_w_overflow(self):
self.assertRaises(OverflowError, to_long, 2**64)
def test_to_long_w_invalid(self):
self.assertRaises(TypeError, to_long, ())
def test_to_bytes_w_ok(self):
conv = to_bytes(3)
self.assertEqual(conv(b'abc'), b'abc')
def test_to_bytes_w_invalid_length(self):
conv = to_bytes(3)
self.assertRaises(TypeError, conv, b'ab')
self.assertRaises(TypeError, conv, b'abcd')
......@@ -405,9 +405,9 @@ class Test_check(unittest.TestCase):
def _makeTree(fill):
from BTrees.OOBTree import OOBTree
from BTrees.OOBTree import _BUCKET_SIZE
from BTrees.OOBTree import OOBTreePy
tree = OOBTree()
if fill:
for i in range(_BUCKET_SIZE + 1):
for i in range(OOBTreePy.max_leaf_size + 1):
tree[i] = 2*i
return tree
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.
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