Commit d861d116 authored by Jim Fulton's avatar Jim Fulton

renamed max_bucket_size and max_btree_size

parent e779278d
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
#define MODULE_NAME "BTrees." MOD_NAME_PREFIX "BTree." #define MODULE_NAME "BTrees." MOD_NAME_PREFIX "BTree."
static PyObject *sort_str, *reverse_str, *__setstate___str; static PyObject *sort_str, *reverse_str, *__setstate___str;
static PyObject *_bucket_type_str, *max_btree_size_str, *max_bucket_size_str; static PyObject *_bucket_type_str, *max_internal_size_str, *max_leaf_size_str;
static PyObject *ConflictError = NULL; static PyObject *ConflictError = NULL;
static void PyVar_Assign(PyObject **v, PyObject *e) { Py_XDECREF(*v); *v=e;} static void PyVar_Assign(PyObject **v, PyObject *e) { Py_XDECREF(*v); *v=e;}
...@@ -221,8 +221,8 @@ typedef struct BTree_s { ...@@ -221,8 +221,8 @@ typedef struct BTree_s {
* data[len].key is positive infinity. * data[len].key is positive infinity.
*/ */
BTreeItem *data; BTreeItem *data;
long max_btree_size; long max_internal_size;
long max_bucket_size; long max_leaf_size;
} BTree; } BTree;
static PyTypeObject BTreeType; static PyTypeObject BTreeType;
...@@ -542,11 +542,11 @@ module_init(void) ...@@ -542,11 +542,11 @@ module_init(void)
if (!_bucket_type_str) if (!_bucket_type_str)
return NULL; return NULL;
max_btree_size_str = INTERN("max_btree_size"); max_internal_size_str = INTERN("max_internal_size");
if (! max_btree_size_str) if (! max_internal_size_str)
return NULL; return NULL;
max_bucket_size_str = INTERN("max_bucket_size"); max_leaf_size_str = INTERN("max_leaf_size");
if (! max_bucket_size_str) if (! max_leaf_size_str)
return NULL; return NULL;
/* Grab the ConflictError class */ /* Grab the ConflictError class */
......
...@@ -43,24 +43,24 @@ _get_max_size(BTree *self, PyObject *name, long default_max) ...@@ -43,24 +43,24 @@ _get_max_size(BTree *self, PyObject *name, long default_max)
} }
static int static int
_max_btree_size(BTree *self) _max_internal_size(BTree *self)
{ {
long isize; long isize;
if (self->max_btree_size > 0) return self->max_btree_size; if (self->max_internal_size > 0) return self->max_internal_size;
isize = _get_max_size(self, max_btree_size_str, DEFAULT_MAX_BTREE_SIZE); isize = _get_max_size(self, max_internal_size_str, DEFAULT_MAX_BTREE_SIZE);
self->max_btree_size = isize; self->max_internal_size = isize;
return isize; return isize;
} }
static int static int
_max_bucket_size(BTree *self) _max_leaf_size(BTree *self)
{ {
long isize; long isize;
if (self->max_bucket_size > 0) return self->max_bucket_size; if (self->max_leaf_size > 0) return self->max_leaf_size;
isize = _get_max_size(self, max_bucket_size_str, DEFAULT_MAX_BUCKET_SIZE); isize = _get_max_size(self, max_leaf_size_str, DEFAULT_MAX_BUCKET_SIZE);
self->max_bucket_size = isize; self->max_leaf_size = isize;
return isize; return isize;
} }
...@@ -459,7 +459,7 @@ BTree_grow(BTree *self, int index, int noval) ...@@ -459,7 +459,7 @@ BTree_grow(BTree *self, int index, int noval)
if (self->len) if (self->len)
{ {
long max_size = _max_btree_size(self); long max_size = _max_internal_size(self);
if (max_size < 0) return -1; if (max_size < 0) return -1;
d = self->data + index; d = self->data + index;
...@@ -780,12 +780,12 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value, ...@@ -780,12 +780,12 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value,
assert(status == 1); /* can be 2 only on deletes */ assert(status == 1); /* can be 2 only on deletes */
if (SameType_Check(self, d->child)) { if (SameType_Check(self, d->child)) {
long max_size = _max_btree_size(self); long max_size = _max_internal_size(self);
if (max_size < 0) return -1; if (max_size < 0) return -1;
toobig = childlength > max_size; toobig = childlength > max_size;
} }
else { else {
long max_size = _max_bucket_size(self); long max_size = _max_leaf_size(self);
if (max_size < 0) return -1; if (max_size < 0) return -1;
toobig = childlength > max_size; toobig = childlength > max_size;
} }
...@@ -2235,8 +2235,8 @@ BTree_init(PyObject *self, PyObject *args, PyObject *kwds) ...@@ -2235,8 +2235,8 @@ BTree_init(PyObject *self, PyObject *args, PyObject *kwds)
{ {
PyObject *v = NULL; PyObject *v = NULL;
BTREE(self)->max_bucket_size = 0; BTREE(self)->max_leaf_size = 0;
BTREE(self)->max_btree_size = 0; BTREE(self)->max_internal_size = 0;
if (!PyArg_ParseTuple(args, "|O:" MOD_NAME_PREFIX "BTree", &v)) if (!PyArg_ParseTuple(args, "|O:" MOD_NAME_PREFIX "BTree", &v))
return -1; return -1;
......
...@@ -59,8 +59,8 @@ class IFSetPy(Set): ...@@ -59,8 +59,8 @@ class IFSetPy(Set):
class IFBTreePy(BTree): class IFBTreePy(BTree):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
_to_value = _to_value _to_value = _to_value
MERGE = MERGE MERGE = MERGE
...@@ -69,8 +69,8 @@ class IFBTreePy(BTree): ...@@ -69,8 +69,8 @@ class IFBTreePy(BTree):
class IFTreeSetPy(TreeSet): class IFTreeSetPy(TreeSet):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
MERGE = MERGE MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric MERGE_WEIGHT = MERGE_WEIGHT_numeric
......
...@@ -60,8 +60,8 @@ class IISetPy(Set): ...@@ -60,8 +60,8 @@ class IISetPy(Set):
class IIBTreePy(BTree): class IIBTreePy(BTree):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
_to_value = _to_value _to_value = _to_value
MERGE = MERGE MERGE = MERGE
...@@ -70,8 +70,8 @@ class IIBTreePy(BTree): ...@@ -70,8 +70,8 @@ class IIBTreePy(BTree):
class IITreeSetPy(TreeSet): class IITreeSetPy(TreeSet):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
MERGE = MERGE MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric MERGE_WEIGHT = MERGE_WEIGHT_numeric
......
...@@ -50,16 +50,16 @@ class IOSetPy(Set): ...@@ -50,16 +50,16 @@ class IOSetPy(Set):
class IOBTreePy(BTree): class IOBTreePy(BTree):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
_to_value = _to_value _to_value = _to_value
MERGE_WEIGHT = MERGE_WEIGHT_default MERGE_WEIGHT = MERGE_WEIGHT_default
class IOTreeSetPy(TreeSet): class IOTreeSetPy(TreeSet):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
class IOTreeIteratorPy(_TreeIterator): class IOTreeIteratorPy(_TreeIterator):
......
...@@ -60,8 +60,8 @@ class LFSetPy(Set): ...@@ -60,8 +60,8 @@ class LFSetPy(Set):
class LFBTreePy(BTree): class LFBTreePy(BTree):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
_to_value = _to_value _to_value = _to_value
MERGE = MERGE MERGE = MERGE
...@@ -70,8 +70,8 @@ class LFBTreePy(BTree): ...@@ -70,8 +70,8 @@ class LFBTreePy(BTree):
class LFTreeSetPy(TreeSet): class LFTreeSetPy(TreeSet):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
MERGE = MERGE MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric MERGE_WEIGHT = MERGE_WEIGHT_numeric
......
...@@ -60,8 +60,8 @@ class LLSetPy(Set): ...@@ -60,8 +60,8 @@ class LLSetPy(Set):
class LLBTreePy(BTree): class LLBTreePy(BTree):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
_to_value = _to_value _to_value = _to_value
MERGE = MERGE MERGE = MERGE
...@@ -70,8 +70,8 @@ class LLBTreePy(BTree): ...@@ -70,8 +70,8 @@ class LLBTreePy(BTree):
class LLTreeSetPy(TreeSet): class LLTreeSetPy(TreeSet):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
MERGE = MERGE MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric MERGE_WEIGHT = MERGE_WEIGHT_numeric
......
...@@ -50,16 +50,16 @@ class LOSetPy(Set): ...@@ -50,16 +50,16 @@ class LOSetPy(Set):
class LOBTreePy(BTree): class LOBTreePy(BTree):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
_to_value = _to_value _to_value = _to_value
MERGE_WEIGHT = MERGE_WEIGHT_default MERGE_WEIGHT = MERGE_WEIGHT_default
class LOTreeSetPy(TreeSet): class LOTreeSetPy(TreeSet):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
......
...@@ -58,8 +58,8 @@ class OISetPy(Set): ...@@ -58,8 +58,8 @@ class OISetPy(Set):
class OIBTreePy(BTree): class OIBTreePy(BTree):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
_to_value = _to_value _to_value = _to_value
MERGE = MERGE MERGE = MERGE
...@@ -68,8 +68,8 @@ class OIBTreePy(BTree): ...@@ -68,8 +68,8 @@ class OIBTreePy(BTree):
class OITreeSetPy(TreeSet): class OITreeSetPy(TreeSet):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
MERGE = MERGE MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric MERGE_WEIGHT = MERGE_WEIGHT_numeric
......
...@@ -59,8 +59,8 @@ class OLSetPy(Set): ...@@ -59,8 +59,8 @@ class OLSetPy(Set):
class OLBTreePy(BTree): class OLBTreePy(BTree):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
_to_value = _to_value _to_value = _to_value
MERGE = MERGE MERGE = MERGE
...@@ -69,8 +69,8 @@ class OLBTreePy(BTree): ...@@ -69,8 +69,8 @@ class OLBTreePy(BTree):
class OLTreeSetPy(TreeSet): class OLTreeSetPy(TreeSet):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
MERGE = MERGE MERGE = MERGE
MERGE_WEIGHT = MERGE_WEIGHT_numeric MERGE_WEIGHT = MERGE_WEIGHT_numeric
......
...@@ -47,15 +47,15 @@ class OOSetPy(Set): ...@@ -47,15 +47,15 @@ class OOSetPy(Set):
class OOBTreePy(BTree): class OOBTreePy(BTree):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
_to_value = _to_value _to_value = _to_value
class OOTreeSetPy(TreeSet): class OOTreeSetPy(TreeSet):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
......
...@@ -868,9 +868,9 @@ class _Tree(_Base): ...@@ -868,9 +868,9 @@ class _Tree(_Base):
grew = result[0] grew = result[0]
if grew: if grew:
if child.__class__ is self.__class__: if child.__class__ is self.__class__:
max_size = self.max_btree_size max_size = self.max_internal_size
else: else:
max_size = self.max_bucket_size max_size = self.max_leaf_size
if child.size > max_size: if child.size > max_size:
self._grow(child, index) self._grow(child, index)
elif (grew is not None and elif (grew is not None and
...@@ -885,7 +885,7 @@ class _Tree(_Base): ...@@ -885,7 +885,7 @@ class _Tree(_Base):
self._p_changed = True self._p_changed = True
new_child = child._split() new_child = child._split()
self._data.insert(index+1, _TreeItem(new_child.minKey(), new_child)) self._data.insert(index+1, _TreeItem(new_child.minKey(), new_child))
if len(self._data) >= self.max_btree_size * 2: if len(self._data) >= self.max_internal_size * 2:
self._split_root() self._split_root()
def _split_root(self): def _split_root(self):
......
...@@ -69,15 +69,15 @@ class fsSetPy(Set): ...@@ -69,15 +69,15 @@ class fsSetPy(Set):
class fsBTreePy(BTree): class fsBTreePy(BTree):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
_to_value = _to_value _to_value = _to_value
class fsTreeSetPy(TreeSet): class fsTreeSetPy(TreeSet):
max_bucket_size = _BUCKET_SIZE max_leaf_size = _BUCKET_SIZE
max_btree_size = _TREE_SIZE max_internal_size = _TREE_SIZE
_to_key = _to_key _to_key = _to_key
......
...@@ -30,8 +30,8 @@ class Test_Base(unittest.TestCase): ...@@ -30,8 +30,8 @@ class Test_Base(unittest.TestCase):
def _makeOne(self, items=None): def _makeOne(self, items=None):
class _Test(self._getTargetClass()): class _Test(self._getTargetClass()):
max_bucket_size = 10 max_leaf_size = 10
max_btree_size = 15 max_internal_size = 15
def clear(self): def clear(self):
self._data = {} self._data = {}
def update(self, d): def update(self, d):
...@@ -1403,8 +1403,8 @@ class Test_Tree(unittest.TestCase): ...@@ -1403,8 +1403,8 @@ class Test_Tree(unittest.TestCase):
class _Test(self._getTargetClass()): class _Test(self._getTargetClass()):
_to_key = _to_value = lambda self, x: x _to_key = _to_value = lambda self, x: x
_bucket_type = _Bucket _bucket_type = _Bucket
max_bucket_size = 10 max_leaf_size = 10
max_btree_size = 15 max_internal_size = 15
return _Test(items) return _Test(items)
def test_setdefault_miss(self): def test_setdefault_miss(self):
...@@ -2220,8 +2220,8 @@ class TreeTests(unittest.TestCase): ...@@ -2220,8 +2220,8 @@ class TreeTests(unittest.TestCase):
class _Test(self._getTargetClass()): class _Test(self._getTargetClass()):
_to_key = _to_value = lambda self, x: x _to_key = _to_value = lambda self, x: x
_bucket_type = _Bucket _bucket_type = _Bucket
max_bucket_size = 10 max_leaf_size = 10
max_btree_size = 15 max_internal_size = 15
return _Test(items) return _Test(items)
def test_get_empty_miss(self): def test_get_empty_miss(self):
...@@ -2365,8 +2365,8 @@ class TreeSetTests(unittest.TestCase): ...@@ -2365,8 +2365,8 @@ class TreeSetTests(unittest.TestCase):
class _Test(self._getTargetClass()): class _Test(self._getTargetClass()):
_to_key = _to_value = lambda self, x: x _to_key = _to_value = lambda self, x: x
_bucket_type = _Bucket _bucket_type = _Bucket
max_bucket_size = 10 max_leaf_size = 10
max_btree_size = 15 max_internal_size = 15
return _Test(items) return _Test(items)
def test_add_new_key(self): def test_add_new_key(self):
......
...@@ -18,8 +18,8 @@ class B(OOBucket): ...@@ -18,8 +18,8 @@ class B(OOBucket):
class T(OOBTree): class T(OOBTree):
_bucket_type = B _bucket_type = B
max_bucket_size = 2 max_leaf_size = 2
max_btree_size = 3 max_internal_size = 3
class S(T): class S(T):
pass pass
......
``BTrees`` Changelog ``BTrees`` Changelog
==================== ====================
- BTree subclasses can define max_bucket_size or max_btree_size to - BTree subclasses can define max_leaf_size or max_internal_size to
control maximum sizes for bucket and tree nodes. control maximum sizes for Bucket/Set and BTree/TreeSet nodes.
- Added support for Python 3.4. - Added support for Python 3.4.
- Update pure-Python and C trees / sets to accept explicit None to indicate - Update pure-Python and C trees / sets to accept explicit None to indicate
max / min value for ``minKey``, ``maxKey``. (PR #3) max / min value for ``minKey``, ``maxKey``. (PR #3)
- Update pure-Python trees / sets to accept explicit None to indicate - Update pure-Python trees / sets to accept explicit None to indicate
open ranges for ``keys``, ``values``, ``items``. (PR #3) open ranges for ``keys``, ``values``, ``items``. (PR #3)
......
...@@ -399,13 +399,17 @@ Object Object 30 250 ...@@ -399,13 +399,17 @@ Object Object 30 250
For your application, especially when using object keys or values, you For your application, especially when using object keys or values, you
may want to override the default sizes. You can do this by may want to override the default sizes. You can do this by
subclassing any of the BTree (or TreeSet) classes and specifying new subclassing any of the BTree (or TreeSet) classes and specifying new
values for ``max_bucket_size`` or ``max_btree_size`` in your subclass:: values for ``max_leaf_size`` or ``max_internal_size`` in your subclass::
import BTrees.OOBTree import BTrees.OOBTree
class MyBTree(BTrees.OOBTree.BTree): class MyBTree(BTrees.OOBTree.BTree):
max_bucket_size = 500 max_leaf_size = 500
max_btree_size = 1000 max_internal_size = 1000
``max_leaf_size`` is used for leaf nodes in a BTree, either Buckets or
Sets. ``max_internal_size`` is used for internal nodes, either BTrees
or TreeSets.
BTree Diagnostic Tools BTree Diagnostic Tools
---------------------- ----------------------
......
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