Commit b86388a1 authored by Jim Fulton's avatar Jim Fulton

*** empty log message ***

parent 5343dd45
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
static char BTree_module_documentation[] = static char BTree_module_documentation[] =
"" ""
"\n$Id: BTree.c,v 1.1 1997/09/08 18:42:21 jim Exp $" "\n$Id: BTree.c,v 1.2 1997/09/10 17:24:47 jim Exp $"
; ;
#define PERSISTENT #define PERSISTENT
...@@ -666,6 +666,7 @@ _bucket_set(Bucket *self, PyObject *key, PyObject *v) ...@@ -666,6 +666,7 @@ _bucket_set(Bucket *self, PyObject *key, PyObject *v)
#else #else
ASSIGN(self->data[i].value, v); ASSIGN(self->data[i].value, v);
#endif #endif
if(PER_CHANGED(self) < 0) goto err;
PER_ALLOW_DEACTIVATION(self); PER_ALLOW_DEACTIVATION(self);
return 0; return 0;
} }
...@@ -682,6 +683,7 @@ _bucket_set(Bucket *self, PyObject *key, PyObject *v) ...@@ -682,6 +683,7 @@ _bucket_set(Bucket *self, PyObject *key, PyObject *v)
free(self->data); free(self->data);
self->data=NULL; self->data=NULL;
} }
if(PER_CHANGED(self) < 0) goto err;
PER_ALLOW_DEACTIVATION(self); PER_ALLOW_DEACTIVATION(self);
return 1; return 1;
} }
...@@ -726,6 +728,7 @@ _bucket_set(Bucket *self, PyObject *key, PyObject *v) ...@@ -726,6 +728,7 @@ _bucket_set(Bucket *self, PyObject *key, PyObject *v)
#endif #endif
self->len++; self->len++;
if(PER_CHANGED(self) < 0) goto err;
PER_ALLOW_DEACTIVATION(self); PER_ALLOW_DEACTIVATION(self);
return 1; return 1;
...@@ -965,11 +968,13 @@ _BTree_set(BTree *self, PyObject *key, PyObject *value) ...@@ -965,11 +968,13 @@ _BTree_set(BTree *self, PyObject *key, PyObject *value)
if(grew < 0) goto err; if(grew < 0) goto err;
if(grew) if(grew)
{
if(value) /* got bigger */ if(value) /* got bigger */
{ {
d->count++; d->count++;
self->count++; self->count++;
if(d->count > MAX_SIZE(self) && BTree_grow(self,min) < 0) goto err; if(BUCKET(d->value)->len > MAX_SIZE(self) &&
BTree_grow(self,min) < 0) goto err;
} }
else /* got smaller */ else /* got smaller */
{ {
...@@ -983,6 +988,8 @@ _BTree_set(BTree *self, PyObject *key, PyObject *value) ...@@ -983,6 +988,8 @@ _BTree_set(BTree *self, PyObject *key, PyObject *value)
if(min < self->len) memmove(d, d+1, self->len-min); if(min < self->len) memmove(d, d+1, self->len-min);
} }
} }
if(PER_CHANGED(self) < 0) goto err;
}
PER_ALLOW_DEACTIVATION(self); PER_ALLOW_DEACTIVATION(self);
return grew; return grew;
...@@ -1087,6 +1094,24 @@ bucket_items(Bucket *self, PyObject *args) ...@@ -1087,6 +1094,24 @@ bucket_items(Bucket *self, PyObject *args)
return NULL; return NULL;
} }
#ifdef PERSISTENT
static PyObject *
bucket__p___reinit__(Bucket *self, PyObject *args)
{
int i;
/* Note that this implementation is broken, in that it doesn't
account for subclass needs. */
for(i=self->len; --i >= 0; )
{
DECREF_KEY(self->data[i].key);
DECREF_VALUE(self->data[i].value);
}
self->len=0;
Py_INCREF(Py_None);
return Py_None;
}
#endif
static PyObject * static PyObject *
bucket_clear(Bucket *self, PyObject *args) bucket_clear(Bucket *self, PyObject *args)
{ {
...@@ -1100,8 +1125,13 @@ bucket_clear(Bucket *self, PyObject *args) ...@@ -1100,8 +1125,13 @@ bucket_clear(Bucket *self, PyObject *args)
DECREF_VALUE(self->data[i].value); DECREF_VALUE(self->data[i].value);
} }
self->len=0; self->len=0;
if(PER_CHANGED(self) < 0) goto err;
PER_ALLOW_DEACTIVATION(self); PER_ALLOW_DEACTIVATION(self);
RETURN_NONE; RETURN_NONE;
err:
PER_ALLOW_DEACTIVATION(self);
return NULL;
} }
static int static int
...@@ -1109,8 +1139,8 @@ _BTree_clear(BTree *self) ...@@ -1109,8 +1139,8 @@ _BTree_clear(BTree *self)
{ {
int i; int i;
UNLESS(self->data) return 0;
PER_USE_OR_RETURN(self, -1);
for(i=self->len; --i >= 0; ) for(i=self->len; --i >= 0; )
{ {
DECREF_KEY(self->data[i].key); DECREF_KEY(self->data[i].key);
...@@ -1119,16 +1149,36 @@ _BTree_clear(BTree *self) ...@@ -1119,16 +1149,36 @@ _BTree_clear(BTree *self)
i=BTree_ini(self); i=BTree_ini(self);
PER_ALLOW_DEACTIVATION(self);
return i; return i;
} }
#ifdef PERSISTENT
static PyObject * static PyObject *
BTree_clear(BTree *self, PyObject *args) BTree__p___reinit__(BTree *self, PyObject *args)
{ {
/* Note that this implementation is broken, in that it doesn't
account for subclass needs. */
if(_BTree_clear(self) < 0) return NULL; if(_BTree_clear(self) < 0) return NULL;
Py_INCREF(Py_None);
return Py_None;
}
#endif
static PyObject *
BTree_clear(BTree *self, PyObject *args)
{
PER_USE_OR_RETURN(self, NULL);
if(_BTree_clear(self) < 0) goto err;
if(PER_CHANGED(self) < 0) goto err;
PER_ALLOW_DEACTIVATION(self);
RETURN_NONE; RETURN_NONE;
err:
PER_ALLOW_DEACTIVATION(self);
return NULL;
} }
static PyObject * static PyObject *
...@@ -1220,7 +1270,7 @@ bucket_setstate(Bucket *self, PyObject *args) ...@@ -1220,7 +1270,7 @@ bucket_setstate(Bucket *self, PyObject *args)
PER_PREVENT_DEACTIVATION(self); PER_PREVENT_DEACTIVATION(self);
UNLESS(PyArg_ParseTuple(args,"O",&r)) goto err; UNLESS(PyArg_ParseTuple(args,"O",&r)) goto err;
UNLESS(PyArg_ParseTuple(r,"O",&keys,&values)) goto err; UNLESS(PyArg_ParseTuple(r,"OO",&keys,&values)) goto err;
if((l=PyObject_Length(keys)) < 0) goto err; if((l=PyObject_Length(keys)) < 0) goto err;
#ifdef INTKEY #ifdef INTKEY
...@@ -1331,6 +1381,10 @@ static struct PyMethodDef Bucket_methods[] = { ...@@ -1331,6 +1381,10 @@ static struct PyMethodDef Bucket_methods[] = {
{"map", (PyCFunction)bucket_map, METH_VARARGS, {"map", (PyCFunction)bucket_map, METH_VARARGS,
"map(keys) -- map a sorted sequence of keys into values\n\n" "map(keys) -- map a sorted sequence of keys into values\n\n"
"Invalid keys are skipped"}, "Invalid keys are skipped"},
#ifdef PERSISTENT
{"_p___reinit__", (PyCFunction)bucket__p___reinit__, METH_VARARGS,
"_p___reinit__() -- Reinitialize from a newly created copy"},
#endif
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
...@@ -1399,6 +1453,7 @@ BTree_setstate(BTree *self, PyObject *args) ...@@ -1399,6 +1453,7 @@ BTree_setstate(BTree *self, PyObject *args)
KEY_PARSE "Oi", KEY_PARSE "Oi",
&(d->key), &(d->value), &(d->count))) &(d->key), &(d->value), &(d->count)))
goto err; goto err;
Py_INCREF(d->value);
self->count+=d->count; self->count+=d->count;
} }
...@@ -1486,6 +1541,10 @@ static struct PyMethodDef BTree_methods[] = { ...@@ -1486,6 +1541,10 @@ static struct PyMethodDef BTree_methods[] = {
{"map", (PyCFunction)BTree_map, METH_VARARGS, {"map", (PyCFunction)BTree_map, METH_VARARGS,
"map(keys) -- map a sorted sequence of keys into values\n\n" "map(keys) -- map a sorted sequence of keys into values\n\n"
"Invalid keys are skipped"}, "Invalid keys are skipped"},
#ifdef PERSISTENT
{"_p___reinit__", (PyCFunction)BTree__p___reinit__, METH_VARARGS,
"_p___reinit__() -- Reinitialize from a newly created copy"},
#endif
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
...@@ -1650,7 +1709,7 @@ initBTree() ...@@ -1650,7 +1709,7 @@ initBTree()
#endif #endif
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.1 $"; char *rev="$Revision: 1.2 $";
UNLESS(PyExtensionClassCAPI=PyCObject_Import("ExtensionClass","CAPI")) UNLESS(PyExtensionClassCAPI=PyCObject_Import("ExtensionClass","CAPI"))
return; return;
...@@ -1710,6 +1769,9 @@ initBTree() ...@@ -1710,6 +1769,9 @@ initBTree()
Revision Log: Revision Log:
$Log: BTree.c,v $ $Log: BTree.c,v $
Revision 1.2 1997/09/10 17:24:47 jim
*** empty log message ***
Revision 1.1 1997/09/08 18:42:21 jim Revision 1.1 1997/09/08 18:42:21 jim
initial BTree initial BTree
......
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