[Zope-Checkins] CVS: Zope/lib/python/BTrees - Setup:1.6.110.1 BTreeModuleTemplate.c:1.15.12.1

Andreas Jung andreas@digicool.com
Sun, 17 Mar 2002 16:06:51 -0500


Update of /cvs-repository/Zope/lib/python/BTrees
In directory cvs.zope.org:/tmp/cvs-serv19832

Modified Files:
      Tag: ajung-textindexng-branch
	Setup BTreeModuleTemplate.c 
Log Message:
added batchInsert() function to move Vocabulary main insert loops
into BTrees...should be moved to a dedicated module


=== Zope/lib/python/BTrees/Setup 1.6 => 1.6.110.1 ===
 _OOBTree _OOBTree.c  -I../../Components/ExtensionClass/src -I../ZODB
-_OIBTree _OIBTree.c  -I../../Components/ExtensionClass/src -I../ZODB
+_OIBTree _OIBTree.c  -DEXTENDED_API -I../../Components/ExtensionClass/src -I../ZODB
 _IIBTree _IIBTree.c  -I../../Components/ExtensionClass/src -I../ZODB -I../../Components
 _IOBTree _IOBTree.c  -I../../Components/ExtensionClass/src -I../ZODB -I../../Components


=== Zope/lib/python/BTrees/BTreeModuleTemplate.c 1.15 => 1.15.12.1 ===
 }
 
+#ifdef EXTENDED_API
+
+/*
+    Arguments:
+
+    - fwdIdx  --  forward index (OIBTree)
+    - reverseIdx -- reverse index (IOBtree)
+    - words -- sequence of words to be inserted 
+*/
+
+PyObject *batch_insert(PyObject *self,PyObject *args) {
+
+    PyObject *fwdIdx,*revIdx, *lst, *word, *wid;
+    PyObject *ids;
+    int i;
+
+    ids = PyList_New(0);
+
+    UNLESS(PyArg_ParseTuple(args, "OOO", &fwdIdx,&revIdx,&lst)) return NULL;
+
+    if (! PySequence_Check(lst)) {
+        PyErr_SetString(PyExc_TypeError, "sequence expected"); \
+        return NULL;
+    }
+
+
+    for (i=0; i<PySequence_Length(lst);i++) {
+        word = PySequence_GetItem(lst,i);
+
+        if (PyMapping_HasKey(fwdIdx,word)) {
+            wid = PyObject_GetItem(fwdIdx,word);
+        }
+        else {
+            wid = PyInt_FromLong(i); // needs to be replaced with a random ID !!!
+
+            if (_BTree_set(fwdIdx, word, wid, 1, 0) < 0) return NULL;
+            PyObject_SetItem(revIdx, wid,word);
+        }
+
+        PyList_Append(ids, wid);
+    }    
+    
+    return ids;
+}
+
+#endif
+
 #include "BTreeItemsTemplate.c"
 #include "BucketTemplate.c"
 #include "SetTemplate.c"
@@ -240,6 +287,12 @@
 #include "MergeTemplate.c"
 
 static struct PyMethodDef module_methods[] = {
+#ifdef EXTENDED_API
+  {"batchInsert", (PyCFunction) batch_insert,	METH_VARARGS,
+   "batchInsert(x,y) -- "
+   "compute the difference between o1 and o2"
+  },
+#endif
   {"difference", (PyCFunction) difference_m,	METH_VARARGS,
    "difference(o1, o2) -- "
    "compute the difference between o1 and o2"