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