X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Freckeys.c;h=652b729324cc8ef1da75bbeaaa2b80c01ae81d17;hb=8e584bbdc77d4c825ed3596c4d8c24a0ab7300e5;hp=067de6b843b07e8ee2bada63a5bbd1c15797f0a8;hpb=ecb3935e78cd9bcfdebafdee0834cfb1060d7b5e;p=idzebra-moved-to-github.git diff --git a/index/reckeys.c b/index/reckeys.c index 067de6b..652b729 100644 --- a/index/reckeys.c +++ b/index/reckeys.c @@ -1,5 +1,5 @@ -/* $Id: reckeys.c,v 1.4 2006-05-10 08:13:22 adam Exp $ - Copyright (C) 1995-2005 +/* $Id: reckeys.c,v 1.10 2006-11-21 22:17:49 adam Exp $ + Copyright (C) 1995-2006 Index Data ApS This file is part of the Zebra server. @@ -15,19 +15,20 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Zebra; see the file LICENSE.zebra. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ #include #include +#include #include #include -#include -#include "index.h" #include "reckeys.h" +#include +#include struct zebra_rec_key_entry { char *buf; @@ -53,12 +54,20 @@ struct zebra_rec_keys_t_ { struct zebra_rec_key_entry **zebra_rec_keys_mk_hash(zebra_rec_keys_t p, const char *buf, - size_t len) + size_t len, + const struct it_key *key) { unsigned h = 0; size_t i; + int j; +#if 0 + h = key->mem[key->len-1]; +#else for (i = 0; ilen; j++) + h = h * 65509 + CAST_ZINT_TO_INT(key->mem[j]); +#endif return &p->entries[h % (unsigned) p->hash_size]; } @@ -75,7 +84,7 @@ static void init_hash(zebra_rec_keys_t p) } } -zebra_rec_keys_t zebra_rec_keys_open() +zebra_rec_keys_t zebra_rec_keys_open(void) { zebra_rec_keys_t p = xmalloc(sizeof(*p)); p->buf_used = 0; @@ -87,7 +96,7 @@ zebra_rec_keys_t zebra_rec_keys_open() p->decode_handle = iscz1_start(); p->nmem = nmem_create(); - p->hash_size = 127; + p->hash_size = 32767; p->entries = 0; init_hash(p); @@ -148,13 +157,19 @@ int zebra_rec_keys_add_hash(zebra_rec_keys_t keys, const char *str, size_t slen, const struct it_key *key) { - struct zebra_rec_key_entry **kep = zebra_rec_keys_mk_hash(keys, str, slen); + struct zebra_rec_key_entry **kep_first + = zebra_rec_keys_mk_hash(keys, str, slen, key); + struct zebra_rec_key_entry **kep = kep_first; while (*kep) { struct zebra_rec_key_entry *e = *kep; if (slen == e->len && !memcmp(str, e->buf, slen) && !key_compare(key, &e->key)) { + *kep = (*kep)->next; /* out of queue */ + e->next = *kep_first; /* move to front */ + *kep_first = e; + return 0; } kep = &(*kep)->next; @@ -177,8 +192,17 @@ void zebra_rec_keys_write(zebra_rec_keys_t keys, assert(keys->owner_of_buffer); +#if 1 if (!zebra_rec_keys_add_hash(keys, str, slen, key)) + { +#if 0 + yaz_log(YLOG_LOG, "dup key slen=%d %.*s " + "ord=" ZINT_FORMAT " seq=" ZINT_FORMAT, + slen, slen, str, key->mem[0], key->mem[key->len-1]); +#endif return; /* key already there . Omit it */ + } +#endif if (keys->buf_used+1024 > keys->buf_max) { char *b = (char *) xmalloc (keys->buf_max += 128000);