projects
/
idzebra-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Reformat: delete trailing whitespace
[idzebra-moved-to-github.git]
/
index
/
reckeys.c
diff --git
a/index/reckeys.c
b/index/reckeys.c
index
01bf317
..
e5174ab
100644
(file)
--- a/
index/reckeys.c
+++ b/
index/reckeys.c
@@
-1,8
+1,5
@@
-/* $Id: reckeys.c,v 1.8 2006-10-29 17:20:01 adam Exp $
- Copyright (C) 1995-2006
- Index Data ApS
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+ Copyright (C) 1994-2011 Index Data
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
@@
-20,14
+17,18
@@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <assert.h>
#include <ctype.h>
-#include <yaz/nmem.h>
-#include "index.h"
#include "reckeys.h"
#include "reckeys.h"
+#include <yaz/nmem.h>
+#include <yaz/xmalloc.h>
struct zebra_rec_key_entry {
char *buf;
struct zebra_rec_key_entry {
char *buf;
@@
-44,10
+45,11
@@
struct zebra_rec_keys_t_ {
void *encode_handle;
void *decode_handle;
char owner_of_buffer;
void *encode_handle;
void *decode_handle;
char owner_of_buffer;
+ zint custom_record_id;
NMEM nmem;
size_t hash_size;
NMEM nmem;
size_t hash_size;
- struct zebra_rec_key_entry **entries;
+ struct zebra_rec_key_entry **entries;
};
};
@@
-59,10
+61,14
@@
struct zebra_rec_key_entry **zebra_rec_keys_mk_hash(zebra_rec_keys_t p,
unsigned h = 0;
size_t i;
int j;
unsigned h = 0;
size_t i;
int j;
+#if 0
+ h = key->mem[key->len-1];
+#else
for (i = 0; i<len; i++)
h = h * 65509 + buf[i];
for (j = 0; j<key->len; j++)
h = h * 65509 + CAST_ZINT_TO_INT(key->mem[j]);
for (i = 0; i<len; i++)
h = h * 65509 + buf[i];
for (j = 0; j<key->len; j++)
h = h * 65509 + CAST_ZINT_TO_INT(key->mem[j]);
+#endif
return &p->entries[h % (unsigned) p->hash_size];
}
return &p->entries[h % (unsigned) p->hash_size];
}
@@
-88,10
+94,11
@@
zebra_rec_keys_t zebra_rec_keys_open(void)
p->buf = 0;
p->owner_of_buffer = 1;
p->encode_handle = iscz1_start();
p->buf = 0;
p->owner_of_buffer = 1;
p->encode_handle = iscz1_start();
- p->decode_handle = iscz1_start();
+ p->decode_handle = iscz1_start();
+ p->custom_record_id = 0;
p->nmem = nmem_create();
p->nmem = nmem_create();
- p->hash_size = 1023;
+ p->hash_size = 32767;
p->entries = 0;
init_hash(p);
p->entries = 0;
init_hash(p);
@@
-122,7
+129,7
@@
void zebra_rec_keys_set_buf(zebra_rec_keys_t p, char *buf, size_t sz,
}
p->owner_of_buffer = copy_buf;
}
}
p->owner_of_buffer = copy_buf;
}
-
+
void zebra_rec_keys_get_buf(zebra_rec_keys_t p, char **buf, size_t *sz)
{
*buf = p->buf;
void zebra_rec_keys_get_buf(zebra_rec_keys_t p, char **buf, size_t *sz)
{
*buf = p->buf;
@@
-137,7
+144,7
@@
void zebra_rec_keys_close(zebra_rec_keys_t p)
{
if (!p)
return;
{
if (!p)
return;
-
+
if (p->owner_of_buffer)
xfree(p->buf);
if (p->encode_handle)
if (p->owner_of_buffer)
xfree(p->buf);
if (p->encode_handle)
@@
-148,18
+155,23
@@
void zebra_rec_keys_close(zebra_rec_keys_t p)
xfree(p);
}
xfree(p);
}
-int zebra_rec_keys_add_hash(zebra_rec_keys_t keys,
+int zebra_rec_keys_add_hash(zebra_rec_keys_t keys,
const char *str, size_t slen,
const struct it_key *key)
{
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, key);
+ 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))
{
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;
return 0;
}
kep = &(*kep)->next;
@@
-173,17
+185,30
@@
int zebra_rec_keys_add_hash(zebra_rec_keys_t keys,
return 1;
}
return 1;
}
-void zebra_rec_keys_write(zebra_rec_keys_t keys,
+void zebra_rec_keys_write(zebra_rec_keys_t keys,
const char *str, size_t slen,
const struct it_key *key)
{
char *dst;
const char *src = (char*) key;
const char *str, size_t slen,
const struct it_key *key)
{
char *dst;
const char *src = (char*) key;
-
+
assert(keys->owner_of_buffer);
assert(keys->owner_of_buffer);
+ if (key->mem[1]) /* record_id custom */
+ {
+ keys->custom_record_id = key->mem[1];
+ }
+#if 1
if (!zebra_rec_keys_add_hash(keys, str, slen, key))
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 */
return; /* key already there . Omit it */
+ }
+#endif
if (keys->buf_used+1024 > keys->buf_max)
{
char *b = (char *) xmalloc (keys->buf_max += 128000);
if (keys->buf_used+1024 > keys->buf_max)
{
char *b = (char *) xmalloc (keys->buf_max += 128000);
@@
-206,17
+231,18
@@
void zebra_rec_keys_reset(zebra_rec_keys_t keys)
{
assert(keys);
keys->buf_used = 0;
{
assert(keys);
keys->buf_used = 0;
-
+
iscz1_reset(keys->encode_handle);
init_hash(keys);
iscz1_reset(keys->encode_handle);
init_hash(keys);
-
}
int zebra_rec_keys_rewind(zebra_rec_keys_t keys)
{
assert(keys);
iscz1_reset(keys->decode_handle);
}
int zebra_rec_keys_rewind(zebra_rec_keys_t keys)
{
assert(keys);
iscz1_reset(keys->decode_handle);
+
+
keys->fetch_offset = 0;
if (keys->buf_used == 0)
return 0;
keys->fetch_offset = 0;
if (keys->buf_used == 0)
return 0;
@@
-241,24
+267,31
@@
int zebra_rec_keys_read(zebra_rec_keys_t keys,
{
const char *src = keys->buf + keys->fetch_offset;
char *dst = (char*) key;
{
const char *src = keys->buf + keys->fetch_offset;
char *dst = (char*) key;
-
+
assert (keys->fetch_offset < keys->buf_used);
/* store the destination key */
iscz1_decode(keys->decode_handle, &dst, &src);
assert (keys->fetch_offset < keys->buf_used);
/* store the destination key */
iscz1_decode(keys->decode_handle, &dst, &src);
-
+
/* store pointer to string and length of it */
*str = src;
*slen = strlen(src);
src += *slen + 1;
/* store pointer to string and length of it */
*str = src;
*slen = strlen(src);
src += *slen + 1;
-
+
keys->fetch_offset = src - keys->buf;
}
return 1;
}
keys->fetch_offset = src - keys->buf;
}
return 1;
}
+
+zint zebra_rec_keys_get_custom_record_id(zebra_rec_keys_t keys)
+{
+ return keys->custom_record_id;
+}
+
/*
* Local variables:
* c-basic-offset: 4
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab