From 49bc5b6975587c1c8f31e3bff5d420b00552af7e Mon Sep 17 00:00:00 2001 From: teodor Date: Fri, 11 Jul 2008 13:22:39 +0000 Subject: [PATCH] Add SFSFindDataFromSavedOrSave - to fast insert partially existed strings --- sfxstr.c | 18 +++++++++++++----- sfxstr.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sfxstr.c b/sfxstr.c index 50cbab4..3eb12c4 100644 --- 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) ) { diff --git a/sfxstr.h b/sfxstr.h index c49ac24..283326c 100644 --- 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); /* -- 2.46.1