Skip to content

Commit

Permalink
WIP towards unsigned keys and values.
Browse files Browse the repository at this point in the history
test__UUBTree.py is complete and passing on Python 3
  • Loading branch information
jamadden committed Feb 14, 2020
1 parent e0a9880 commit feb5b6d
Show file tree
Hide file tree
Showing 45 changed files with 7,462 additions and 250 deletions.
59 changes: 58 additions & 1 deletion BTrees/BTreeModuleTemplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ static void PyVar_Assign(PyObject **v, PyObject *e) { Py_XDECREF(*v); *v=e;}
#endif

#ifdef NEED_LONG_LONG_KEYS
#if defined(ZODB_UNSIGNED_VALUE_INTS) || defined(ZODB_UNSIGNED_KEY_INTS)
static int
ulonglong_check(PyObject *ob)
{
/* if (UINT_CHECK(ob)) // No, this is not right. */
/* return 1; */
// XXX: Python 2.
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)
{
Expand All @@ -97,8 +113,49 @@ longlong_check(PyObject *ob)
"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)
{
#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;
}

unsigned PY_LONG_LONG val;
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)
{
Expand All @@ -107,7 +164,6 @@ longlong_as_object(PY_LONG_LONG val)
return INT_FROM_LONG((long)val);
}


static int
longlong_convert(PyObject *ob, PY_LONG_LONG *value)
{
Expand Down Expand Up @@ -138,6 +194,7 @@ longlong_convert(PyObject *ob, PY_LONG_LONG *value)
PyErr_SetString(PyExc_ValueError, "long integer out of range");
return 0;
}

#endif /* NEED_LONG_LONG_SUPPORT */


Expand Down
113 changes: 113 additions & 0 deletions BTrees/IUBTree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
##############################################################################
#
# 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
from ._base import to_uint 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 IUBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int


class IUSetPy(Set):
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int


class IUBTreePy(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 IUTreeSetPy(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 IUTreeIteratorPy(_TreeIterator):
pass


# Can't declare forward refs, so fix up afterwards:

IUBucketPy._mapping_type = IUBucketPy._bucket_type = IUBucketPy
IUBucketPy._set_type = IUSetPy

IUSetPy._mapping_type = IUBucketPy
IUSetPy._set_type = IUSetPy._bucket_type = IUSetPy

IUBTreePy._mapping_type = IUBTreePy._bucket_type = IUBucketPy
IUBTreePy._set_type = IUSetPy

IUTreeSetPy._mapping_type = IUBucketPy
IUTreeSetPy._set_type = IUTreeSetPy._bucket_type = IUSetPy


differencePy = _set_operation(_difference, IUSetPy)
unionPy = _set_operation(_union, IUSetPy)
intersectionPy = _set_operation(_intersection, IUSetPy)
multiunionPy = _set_operation(_multiunion, IUSetPy)
weightedUnionPy = _set_operation(_weightedUnion, IUSetPy)
weightedIntersectionPy = _set_operation(_weightedIntersection, IUSetPy)

import_c_extension(globals())

_fix_pickle(globals(), __name__)

moduleProvides(IIntegerIntegerBTreeModule)
113 changes: 113 additions & 0 deletions BTrees/LQBTree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
##############################################################################
#
# 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',
'LQBucket', 'LQSet', 'LQBTree', 'LQTreeSet',
'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_ulong 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 LQBucketPy(Bucket):
_to_key = _to_key
_to_value = _to_value
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int


class LQSetPy(Set):
_to_key = _to_key
MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric
MERGE_DEFAULT = MERGE_DEFAULT_int


class LQBTreePy(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 LQTreeSetPy(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 LQTreeIteratorPy(_TreeIterator):
pass


# Can't declare forward refs, so fix up afterwards:

LQBucketPy._mapping_type = LQBucketPy._bucket_type = LQBucketPy
LQBucketPy._set_type = LQSetPy

LQSetPy._mapping_type = LQBucketPy
LQSetPy._set_type = LQSetPy._bucket_type = LQSetPy

LQBTreePy._mapping_type = LQBTreePy._bucket_type = LQBucketPy
LQBTreePy._set_type = LQSetPy

LQTreeSetPy._mapping_type = LQBucketPy
LQTreeSetPy._set_type = LQTreeSetPy._bucket_type = LQSetPy


differencePy = _set_operation(_difference, LQSetPy)
unionPy = _set_operation(_union, LQSetPy)
intersectionPy = _set_operation(_intersection, LQSetPy)
multiunionPy = _set_operation(_multiunion, LQSetPy)
weightedUnionPy = _set_operation(_weightedUnion, LQSetPy)
weightedIntersectionPy = _set_operation(_weightedIntersection, LQSetPy)

import_c_extension(globals())

_fix_pickle(globals(), __name__)

moduleProvides(IIntegerIntegerBTreeModule)
Loading

0 comments on commit feb5b6d

Please sign in to comment.