Commit d861d116 authored by Jim Fulton's avatar Jim Fulton

renamed max_bucket_size and max_btree_size

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