Commit df609e11 authored by Jim Fulton's avatar Jim Fulton

Tuned size/splitting parameters to provide bigger internal

nodes.

Optimized pickle formats (using tuple rather than tuple of tuples).
parent 4506c7a9
......@@ -85,7 +85,7 @@
static char BTree_module_documentation[] =
""
"\n$Id: BTreeModuleTemplate.c,v 1.2 2001/02/19 00:38:41 jim Exp $"
"\n$Id: BTreeModuleTemplate.c,v 1.3 2001/02/19 17:36:04 jim Exp $"
;
#ifdef PERSISTENT
......@@ -124,7 +124,7 @@ static void PyVar_Assign(PyObject **v, PyObject *e) { Py_XDECREF(*v); *v=e;}
#define OBJECT(O) ((PyObject*)(O))
#define MIN_BUCKET_ALLOC 16
#define MAX_BTREE_SIZE(B) 256
#define MAX_BTREE_SIZE(B) DEFAULT_MAX_BTREE_SIZE
#define MAX_BUCKET_SIZE(B) DEFAULT_MAX_BUCKET_SIZE
#define SameType_Check(O1, O2) ((O1)->ob_type==(O2)->ob_type)
......@@ -366,7 +366,7 @@ INITMODULE ()
d = PyModule_GetDict(m);
PyDict_SetItemString(d, "__version__",
PyString_FromString("$Revision: 1.2 $"));
PyString_FromString("$Revision: 1.3 $"));
PyExtensionClass_Export(d,PREFIX "Bucket", BucketType);
PyExtensionClass_Export(d,PREFIX "BTree", BTreeType);
......
......@@ -611,49 +611,41 @@ err:
static PyObject *
BTree_getstate(BTree *self, PyObject *args)
{
PyObject *r=0, *o, *item, *result;
int i;
PyObject *r=0, *o;
int i, l;
PER_USE_OR_RETURN(self, NULL);
if (self->len)
{
UNLESS (r=PyTuple_New(self->len)) goto err;
for (i=self->len; --i >= 0; )
UNLESS (r=PyTuple_New(self->len*2-1)) goto err;
for (i=self->len, l=0; --i >= 0; )
{
UNLESS (item=PyTuple_New(2)) goto err;
if (i)
{
COPY_KEY_TO_OBJECT(o, self->data[i].key);
PyTuple_SET_ITEM(r,l,o);
l++;
}
else
{
o=Py_None;
Py_INCREF(o);
}
PyTuple_SET_ITEM(item, 0, o);
o=self->data[i].value;
Py_INCREF(o);
PyTuple_SET_ITEM(item, 1, o);
PyTuple_SET_ITEM(r,i,item);
PyTuple_SET_ITEM(r,l,o);
l++;
}
result = Py_BuildValue("OO", r, self->firstbucket);
Py_DECREF(r);
ASSIGN(r, Py_BuildValue("OO", r, self->firstbucket));
}
else
{
result = Py_None;
Py_INCREF(result);
r = Py_None;
Py_INCREF(r);
}
PER_ALLOW_DEACTIVATION(self);
return result;
return r;
err:
PER_ALLOW_DEACTIVATION(self);
Py_DECREF(r);
return NULL;
}
......@@ -668,7 +660,7 @@ BTree_setstate(BTree *self, PyObject *args)
PyObject *state, *k, *v=0, *items;
BTreeItem *d;
Bucket *firstbucket;
int l, i, r, copied=1;
int len, l, i, r, copied=1;
if (!PyArg_ParseTuple(args,"O",&state)) return NULL;
......@@ -683,29 +675,30 @@ BTree_setstate(BTree *self, PyObject *args)
if (!PyArg_ParseTuple(state,"O|O",&items, &firstbucket))
goto err;
if ((l=PyTuple_Size(items)) < 0) goto err;
if ((len=PyTuple_Size(items)) < 0) goto err;
len=(len+1)/2;
self->firstbucket = firstbucket;
Py_INCREF(firstbucket);
if (l > self->size)
if (len > self->size)
{
UNLESS (d=PyRealloc(self->data, sizeof(BTreeItem)*l)) goto err;
UNLESS (d=PyRealloc(self->data, sizeof(BTreeItem)*len)) goto err;
self->data=d;
self->size=l;
self->size=len;
}
for (i=0, d=self->data; i < l; i++, d++)
for (i=0, d=self->data, l=0; i < len; i++, d++)
{
UNLESS (PyArg_ParseTuple(PyTuple_GET_ITEM(state,i), "OO",
&k, &(d->value)))
goto err;
if (i)
{
COPY_KEY_FROM_ARG(d->key, k, &copied);
COPY_KEY_FROM_ARG(d->key, PyTuple_GET_ITEM(state,l), &copied);
l++;
UNLESS (&copied) return NULL;
INCREF_KEY(d->key);
}
d->value=PyTuple_GET_ITEM(state,l);
l++;
Py_INCREF(d->value);
}
self->len=l;
......
......@@ -749,18 +749,6 @@ bucket__p_deactivate(Bucket *self, PyObject *args)
}
#endif
/*
** bucket_clear
**
** Zeros out a bucket
**
** Arguments: self The bucket
** args (unused)
**
** Returns: None on success
** NULL on failure
**
*/
static PyObject *
bucket_clear(Bucket *self, PyObject *args)
{
......@@ -784,55 +772,42 @@ err:
return NULL;
}
/*
** bucket_getstate
**
** bulk get all objects in bucket
**
** Arguments: self The Bucket
** args (unused)
**
** Returns: pair of tuples of keys, values
*/
static PyObject *
bucket_getstate(Bucket *self, PyObject *args)
{
PyObject *r=0, *o=0, *items=0;
int i, l;
PyObject *o=0, *items=0;
int i, len, l;
PER_USE_OR_RETURN(self, NULL);
l=self->len;
len=self->len;
UNLESS (items=PyTuple_New(self->len)) goto err;
for (i=0; i<l; i++)
UNLESS (items=PyTuple_New(len*2)) goto err;
for (i=0, l=0; i < len; i++)
{
UNLESS (r = PyTuple_New(2)) goto err;
COPY_KEY_TO_OBJECT(o, self->keys[i]);
UNLESS (o) goto err;
PyTuple_SET_ITEM(r, 0, o);
PyTuple_SET_ITEM(items, l, o);
l++;
COPY_VALUE_TO_OBJECT(o, self->values[i]);
UNLESS (o) goto err;
PyTuple_SET_ITEM(r, 1, o);
PyTuple_SET_ITEM(items, i, r);
r=0;
PyTuple_SET_ITEM(items, l, o);
l++;
}
if (self->next)
r=Py_BuildValue("OO", items, self->next);
ASSIGN(items, Py_BuildValue("OO", items, self->next));
else
r=Py_BuildValue("(O)", items);
ASSIGN(items, Py_BuildValue("(O)", items));
PER_ALLOW_DEACTIVATION(self);
return r;
return items;
err:
PER_ALLOW_DEACTIVATION(self);
Py_XDECREF(items);
Py_XDECREF(r);
return NULL;
}
......@@ -852,7 +827,7 @@ bucket_setstate(Bucket *self, PyObject *args)
{
PyObject *k, *v, *r, *items;
Bucket *next=0;
int i, l, copied=1;
int i, l, len, copied=1;
KEY_TYPE *keys;
VALUE_TYPE *values;
......@@ -863,7 +838,7 @@ bucket_setstate(Bucket *self, PyObject *args)
UNLESS (PyArg_ParseTuple(args, "O|O!", &items, self->ob_type, &next))
goto err;
if ((l=PyTuple_Size(items)) < 0) goto err;
if ((len=PyTuple_Size(items)) < 0) goto err;
for (i=self->len; --i >= 0; )
{
......@@ -878,20 +853,22 @@ bucket_setstate(Bucket *self, PyObject *args)
self->next=0;
}
if (l > self->size)
if (len > self->size)
{
UNLESS (keys=PyRealloc(self->keys, sizeof(KEY_TYPE)*l)) goto err;
UNLESS (values=PyRealloc(self->values, sizeof(KEY_TYPE)*l)) goto err;
UNLESS (keys=PyRealloc(self->keys, sizeof(KEY_TYPE)*len)) goto err;
UNLESS (values=PyRealloc(self->values, sizeof(KEY_TYPE)*len)) goto err;
self->keys=keys;
self->values=values;
self->size=l;
self->size=len;
}
for (i=0; i<l; i++)
for (i=0, l=0; i<len; i++)
{
r=PyTuple_GET_ITEM(items, i);
UNLESS(k=PyTuple_GetItem(r, 0)) goto perr;
UNLESS(v=PyTuple_GetItem(r, 1)) goto perr;
k=PyTuple_GET_ITEM(items, l);
l++;
v=PyTuple_GET_ITEM(items, l);
l++;
COPY_KEY_FROM_ARG(self->keys[i], k, &copied);
UNLESS (copied) return NULL;
COPY_VALUE_FROM_ARG(self->values[i], v, &copied);
......
......@@ -4,7 +4,8 @@
#define PREFIX "II"
#define INITMODULE initIIBTree
#define DEFAULT_MAX_BUCKET_SIZE 100
#define DEFAULT_MAX_BUCKET_SIZE 120
#define DEFAULT_MAX_BTREE_SIZE 500
#include "intkeymacros.h"
#include "intvaluemacros.h"
......
......@@ -2,7 +2,8 @@
#define PERSISTENT
#define PREFIX "IO"
#define DEFAULT_MAX_BUCKET_SIZE 32
#define DEFAULT_MAX_BUCKET_SIZE 30
#define DEFAULT_MAX_BTREE_SIZE 500
#define INITMODULE initIOBTree
#include "intkeymacros.h"
......
......@@ -3,7 +3,8 @@
#define PREFIX "OI"
#define INITMODULE initOIBTree
#define DEFAULT_MAX_BUCKET_SIZE 64
#define DEFAULT_MAX_BUCKET_SIZE 60
#define DEFAULT_MAX_BTREE_SIZE 250
#include "objectkeymacros.h"
#include "intvaluemacros.h"
......
......@@ -3,7 +3,8 @@
#define PREFIX "OO"
#define INITMODULE initOOBTree
#define DEFAULT_MAX_BUCKET_SIZE 32
#define DEFAULT_MAX_BUCKET_SIZE 30
#define DEFAULT_MAX_BTREE_SIZE 250
#include "objectkeymacros.h"
#include "objectvaluemacros.h"
......
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