Add SFSFindDataFromSavedOrSave - to fast insert partially existed strings
authorteodor <teodor>
Fri, 11 Jul 2008 13:22:39 +0000 (13:22 +0000)
committerteodor <teodor>
Fri, 11 Jul 2008 13:22:39 +0000 (13:22 +0000)
sfxstr.c
sfxstr.h

index 50cbab4..3eb12c4 100644 (file)
--- a/sfxstr.c
+++ b/sfxstr.c
@@ -149,20 +149,28 @@ SFSFindData(SFSTree *info, char *word, int len) {
        in.key = word;
        in.keylen = len;
 
-       return SFSFindDataOrSave(info, &in, NULL);
+       return SFSFindDataFromSavedOrSave(info, &in, NULL);
 }
 
 void*
 SFSFindDataOrSave(SFSTree *info, SFSDataIO *in, SFSTreePosition *position) {
+       if ( position )
+               memset(position, 0, sizeof(position));
+
+       return SFSFindDataFromSavedOrSave(info, in, position); 
+}
+
+void*
+SFSFindDataFromSavedOrSave(SFSTree *info, SFSDataIO *in, SFSTreePosition *position) {
        SFSNode *node = info->node;
        SFSNode **pnode = &(info->node);
        SFSNodeData *StopLow, *StopHigh, *StopMiddle;
        u_int8_t *ptr =(u_int8_t*)in->key;
 
-       if ( position ) {
-               position->nodeptr = NULL;
-               position->node = NULL;
-               position->level = 0;
+       if ( position && position->nodeptr && position->node && in->keylen > position->level ) {
+               node = position->node;
+               pnode = position->nodeptr;
+               ptr += position->level;
        }
 
        while( node && !ISEND(ptr, in->key, in->keylen) ) {
index c49ac24..283326c 100644 (file)
--- a/sfxstr.h
+++ b/sfxstr.h
@@ -192,6 +192,7 @@ typedef struct SFSTreePosition {
 } SFSTreePosition;
 
 void* SFSFindDataOrSave(SFSTree *info, SFSDataIO *in, SFSTreePosition *position);
+void* SFSFindDataFromSavedOrSave(SFSTree *info, SFSDataIO *in, SFSTreePosition *position);
 void  SFSAddSaved(SFSTree *info, SFSDataIO *in, SFSTreePosition *position);
 
 /*