[Zope-Checkins] CVS: Zope3/lib/python/Persistence/BTrees - BTreeModuleTemplate.c:1.1.2.11 BTreeTemplate.c:1.1.2.10
Tim Peters
tim.one@comcast.net
Tue, 4 Jun 2002 16:00:59 -0400
Update of /cvs-repository/Zope3/lib/python/Persistence/BTrees
In directory cvs.zope.org:/tmp/cvs-serv26856
Modified Files:
Tag: Zope-3x-branch
BTreeModuleTemplate.c BTreeTemplate.c
Log Message:
As in the trunk, renamed BTreeItem.value to .child.
=== Zope3/lib/python/Persistence/BTrees/BTreeModuleTemplate.c 1.1.2.10 => 1.1.2.11 ===
PyErr_SetString(PyExc_AssertionError, (S)); return (R); }
+/* A BTree is complicated. See Maintainer.txt.
+ */
+
typedef struct BTreeItemStruct {
KEY_TYPE key;
- PyObject *value;
+ PyObject *child; /* points to another BTree, or to a Bucket of some sort */
} BTreeItem;
typedef struct Bucket_s {
=== Zope3/lib/python/Persistence/BTrees/BTreeTemplate.c 1.1.2.9 => 1.1.2.10 ===
}
- if (SameType_Check(self, self->data[min].value))
- r=_BTree_get( BTREE(self->data[min].value), keyarg,
+ if (SameType_Check(self, self->data[min].child))
+ r=_BTree_get( BTREE(self->data[min].child), keyarg,
has_key ? has_key + 1: 0);
else
- r=_bucket_get(BUCKET(self->data[min].value), keyarg,
+ r=_bucket_get(BUCKET(self->data[min].child), keyarg,
has_key ? has_key + 1: 0);
}
else
@@ -99,16 +99,16 @@
self->len = index;
- if (SameType_Check(self, next->data->value)) {
- PyPersist_INCREF((PyPersistObject *)next->data->value);
- if (!PyPersist_IS_STICKY((PyPersistObject *)next->data->value))
+ if (SameType_Check(self, next->data->child)) {
+ PyPersist_INCREF((PyPersistObject *)next->data->child);
+ if (!PyPersist_IS_STICKY((PyPersistObject *)next->data->child))
return -1;
- next->firstbucket = BTREE(next->data->value)->firstbucket;
+ next->firstbucket = BTREE(next->data->child)->firstbucket;
Py_XINCREF(next->firstbucket);
- PyPersist_DECREF(BTREE(next->data->value));
- PyPersist_SetATime(BTREE(next->data->value));
+ PyPersist_DECREF(BTREE(next->data->child));
+ PyPersist_SetATime(BTREE(next->data->child));
} else {
- next->firstbucket = BUCKET(next->data->value);
+ next->firstbucket = BUCKET(next->data->child);
Py_XINCREF(next->firstbucket);
}
@@ -156,13 +156,13 @@
self->data = d;
self->len = 2;
self->size = 2;
- self->data->value = (PyObject *)n1;
+ self->data->child = (PyObject *)n1;
COPY_KEY(self->data[1].key, n2->data->key);
/* We take the unused reference from n2, so there's no reason to INCREF! */
/* INCREF_KEY(self->data[1].key); */
- self->data[1].value = (PyObject *)n2;
+ self->data[1].child = (PyObject *)n2;
return 0;
@@ -210,7 +210,7 @@
d = self->data + index;
if (self->len) {
- v = d->value;
+ v = d->child;
/* Create a new object of the same type as the target value */
e = PyObject_CallObject((PyObject *)v->ob_type, NULL);
if (e == NULL)
@@ -245,21 +245,21 @@
COPY_KEY(d->key, BUCKET(e)->keys[0]);
INCREF_KEY(d->key);
}
- d->value = e;
+ d->child = e;
self->len++;
if (self->len >= MAX_BTREE_SIZE(self) * 2)
return BTree_clone(self);
} else {
if (noval)
- d->value = PyObject_CallObject((PyObject *)&SetType, NULL);
+ d->child = PyObject_CallObject((PyObject *)&SetType, NULL);
else
- d->value = PyObject_CallObject((PyObject *)&BucketType, NULL);
- if (d->value == NULL)
+ d->child = PyObject_CallObject((PyObject *)&BucketType, NULL);
+ if (d->child == NULL)
return -1;
self->len = 1;
- Py_INCREF(d->value);
- self->firstbucket = (Bucket *)d->value;
+ Py_INCREF(d->child);
+ self->firstbucket = (Bucket *)d->child;
}
/* refcnt note:
@@ -281,7 +281,7 @@
return NULL;
}
- o = self->data[self->len - 1].value;
+ o = self->data[self->len - 1].child;
Py_INCREF(o);
if (!SameType_Check(self, o))
@@ -376,10 +376,10 @@
}
d=self->data+min;
- if (SameType_Check(self, d->value))
- grew= _BTree_set((BTree *)d->value, keyarg, value, unique, noval);
+ if (SameType_Check(self, d->child))
+ grew= _BTree_set((BTree *)d->child, keyarg, value, unique, noval);
else
- grew=_bucket_set((Bucket *)d->value, keyarg, value, unique, noval,
+ grew=_bucket_set((Bucket *)d->child, keyarg, value, unique, noval,
&bchanged);
if (grew < 0)
goto err;
@@ -387,14 +387,14 @@
if (grew) {
bchanged = 1; /* A bucket changed size */
if (value) { /* got bigger */
- if (SameType_Check(self, d->value)) {
- if (BTREE(d->value)->len > MAX_BTREE_SIZE(d->value)) {
+ if (SameType_Check(self, d->child)) {
+ if (BTREE(d->child)->len > MAX_BTREE_SIZE(d->child)) {
if (BTree_grow(self, min, noval) < 0)
goto err;
changed = 1;
}
} else {
- if (BUCKET(d->value)->len > MAX_BUCKET_SIZE(d->value)) {
+ if (BUCKET(d->child)->len > MAX_BUCKET_SIZE(d->child)) {
if (BTree_grow(self, min, noval) < 0)
goto err;
changed = 1;
@@ -404,19 +404,19 @@
if (min && grew > 1) {
/* Somebody below us deleted their first bucket and */
/* and an intermediate tree couldn't handle it. */
- if (BTree_deleteNextBucket(BTREE(d[-1].value)) < 0)
+ if (BTree_deleteNextBucket(BTREE(d[-1].child)) < 0)
goto err;
grew = 1; /* Reset flag, since we handled it */
}
- if (BUCKET(d->value)->len == 0) { /* Got empty */
- if (!SameType_Check(self, d->value)) {
+ if (BUCKET(d->child)->len == 0) { /* Got empty */
+ if (!SameType_Check(self, d->child)) {
/* We are about to delete a bucket. */
if (min) {
/* If it's not our first bucket, we can tell the
previous bucket to adjust it's reference to
it. */
- if (Bucket_deleteNextBucket(BUCKET(d[-1].value)) < 0)
+ if (Bucket_deleteNextBucket(BUCKET(d[-1].child)) < 0)
goto err;
} else {
/* If it's the first bucket, we can't adjust the
@@ -429,7 +429,7 @@
}
}
self->len--;
- Py_DECREF(d->value);
+ Py_DECREF(d->child);
if (min) {
DECREF_KEY(d->key);
}
@@ -440,17 +440,17 @@
if (self->len) {
/* We just deleted our first child, so we need to
adjust our first bucket. */
- if (SameType_Check(self, self->data->value)) {
- UNLESS (PER_USE(BTREE(self->data->value)))
+ if (SameType_Check(self, self->data->child)) {
+ UNLESS (PER_USE(BTREE(self->data->child)))
goto err;
ASSIGNB(self->firstbucket,
- BTREE(self->data->value)->firstbucket);
+ BTREE(self->data->child)->firstbucket);
Py_XINCREF(self->firstbucket);
- PyPersist_DECREF(BTREE(self->data->value));
- PyPersist_SetATime(BTREE(self->data->value));
+ PyPersist_DECREF(BTREE(self->data->child));
+ PyPersist_SetATime(BTREE(self->data->child));
} else {
ASSIGNB(self->firstbucket,
- BUCKET(self->data->value));
+ BUCKET(self->data->child));
Py_INCREF(self->firstbucket);
}
/* We can toss our first key now */
@@ -469,8 +469,8 @@
if (changed
|| (bchanged /* The bucket changed */
&& self->len == 1 /* We have only one */
- && ! SameType_Check(self, self->data->value) /* It's our child */
- && BUCKET(self->data->value)->po_oid == NULL /* It's in our record*/
+ && ! SameType_Check(self, self->data->child) /* It's our child */
+ && BUCKET(self->data->child)->po_oid == NULL /* It's in our record*/
)
)
if (PyPersist_CHANGED(self) < 0)
@@ -538,7 +538,7 @@
if (i) {
DECREF_KEY(self->data[i].key);
}
- Py_DECREF(self->data[i].value);
+ Py_DECREF(self->data[i].child);
}
self->len = 0;
@@ -609,13 +609,13 @@
goto err;
if (self->len == 1
- && self->data->value->ob_type != self->ob_type
+ && self->data->child->ob_type != self->ob_type
#ifdef PERSISTENT
- && BUCKET(self->data->value)->po_oid == NULL
+ && BUCKET(self->data->child)->po_oid == NULL
#endif
) {
/* We have just one bucket. Save it's data directly. */
- o = bucket_getstate((Bucket *)self->data->value);
+ o = bucket_getstate((Bucket *)self->data->child);
if (o == NULL)
goto err;
PyTuple_SET_ITEM(r, 0, o);
@@ -627,7 +627,7 @@
PyTuple_SET_ITEM(r, l, o);
l++;
}
- o = self->data[i].value;
+ o = self->data[i].child;
Py_INCREF(o);
PyTuple_SET_ITEM(r,l,o);
l++;
@@ -686,25 +686,25 @@
return -1;
INCREF_KEY(d->key);
}
- d->value = PyTuple_GET_ITEM(items, l);
- if (PyTuple_Check(d->value)) {
+ d->child = PyTuple_GET_ITEM(items, l);
+ if (PyTuple_Check(d->child)) {
if (noval) {
- UNLESS (d->value=PyObject_CallObject(OBJECT(&SetType),
+ UNLESS (d->child=PyObject_CallObject(OBJECT(&SetType),
NULL))
return -1;
- if (_set_setstate(BUCKET(d->value),
+ if (_set_setstate(BUCKET(d->child),
PyTuple_GET_ITEM(items,l))
< 0) return -1;
} else {
- UNLESS (d->value=PyObject_CallObject(OBJECT(&BucketType),
+ UNLESS (d->child=PyObject_CallObject(OBJECT(&BucketType),
NULL))
return -1;
- if (_bucket_setstate(BUCKET(d->value),
+ if (_bucket_setstate(BUCKET(d->child),
PyTuple_GET_ITEM(items,l))
< 0) return -1;
}
} else {
- Py_INCREF(d->value);
+ Py_INCREF(d->child);
}
l++;
}
@@ -712,7 +712,7 @@
if (len)
{
if (!firstbucket)
- firstbucket = self->data->value;
+ firstbucket = self->data->child;
/* XXX what is this? */
if (!PyObject_IsInstance(firstbucket, (PyObject *)
@@ -857,9 +857,9 @@
else max=i;
}
- if (SameType_Check(self, self->data[min].value))
+ if (SameType_Check(self, self->data[min].child))
{
- self=BTREE(self->data[min].value);
+ self=BTREE(self->data[min].child);
PyPersist_INCREF(self);
if (!PyPersist_IS_STICKY(self))
return -1;
@@ -872,7 +872,7 @@
i = 0;
/* Because we might miss on a range search where max=len */
while(i == 0) {
- *bucket = BUCKET(self->data[min].value);
+ *bucket = BUCKET(self->data[min].child);
i=Bucket_findRangeEnd(*bucket, keyarg, low, offset);
if (i)
{
@@ -1297,7 +1297,7 @@
VISIT(self->firstbucket);
for (i = 0, l = self->len; i < l; i++) {
VISIT(KEY_IF_OBJECT(self->data[i].key));
- VISIT(self->data[i].value);
+ VISIT(self->data[i].child);
}
#undef VISIT
return 0;