Jenkins hash function now in one place.
settings.h settings.c sel_thread.c sel_thread.h getaddrinfo.c \
charsets.c charsets.h \
client.c client.h connection.c connection.h host.h parameters.h \
- dirent.c direntz.h marcmap.c marcmap.h marchash.c marchash.h
+ dirent.c direntz.h marcmap.c marcmap.h marchash.c marchash.h \
+ jenkins_hash.c jenkins_hash.h
pazpar2_SOURCES = pazpar2.c
pazpar2_LDADD = libpazpar2.a $(YAZLIB)
--- /dev/null
+/* This file is part of Pazpar2.
+ Copyright (C) 2006-2009 Index Data
+
+Pazpar2 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
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+/** \file
+ \brief Jenkins hash function
+*/
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "jenkins_hash.h"
+
+// Jenkins one-at-a-time hash (from wikipedia)
+unsigned int jenkins_hash(const unsigned char *key)
+{
+ unsigned int hash = 0;
+
+ while (*key)
+ {
+ hash += *(key++);
+ hash += (hash << 10);
+ hash ^= (hash >> 6);
+ }
+ hash += (hash << 3);
+ hash ^= (hash >> 11);
+ hash += (hash << 15);
+ return hash;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
--- /dev/null
+/* This file is part of Pazpar2.
+ Copyright (C) 2006-2009 Index Data
+
+Pazpar2 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
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+#ifndef JENKINS_HASH_H
+#define JENKINS_HASH_H
+
+unsigned int jenkins_hash(const unsigned char *key);
+
+#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
#include <libxml/parser.h>
#include <yaz/nmem.h>
+#include "jenkins_hash.h"
#include <marchash.h>
-// Jenkins one-at-a-time hash (from pp2 reclists.c, wikipedia)
-static unsigned int hash(const unsigned char *key)
-{
- unsigned int hash = 0;
-
- while (*key)
- {
- hash += *(key++);
- hash += (hash << 10);
- hash ^= (hash >> 6);
- }
- hash += (hash << 3);
- hash ^= (hash >> 11);
- hash += (hash << 15);
- return hash;
-}
-
inline void strtrimcat(char *dest, const char *src)
{
const char *in;
struct marcfield *new;
struct marcfield *last;
- slot = hash((const unsigned char *) key) & MARCHASH_MASK;
+ slot = jenkins_hash((const unsigned char *) key) & MARCHASH_MASK;
new = marchash->table[slot];
last = NULL;
if (last)
cur = last->next;
else
- cur = marchash->table[hash((const unsigned char *)key) & MARCHASH_MASK];
+ cur = marchash->table[jenkins_hash((const unsigned char *)key) & MARCHASH_MASK];
while (cur)
{
if (!strcmp(cur->key, key))
#include "pazpar2.h"
#include "reclists.h"
+#include "jenkins_hash.h"
static struct reclist_sortparms *qsort_sortparms = 0; /* thread pr */
l->pointer = 0;
}
-// Jenkins one-at-a-time hash (from wikipedia)
-static unsigned int hash(const unsigned char *key)
-{
- unsigned int hash = 0;
-
- while (*key)
- {
- hash += *(key++);
- hash += (hash << 10);
- hash ^= (hash >> 6);
- }
- hash += (hash << 3);
- hash ^= (hash >> 11);
- hash += (hash << 15);
- return hash;
-}
-
struct reclist *reclist_create(NMEM nmem, int numrecs)
{
int hashsize = 1;
assert(merge_key);
assert(total);
- bucket = hash((unsigned char*) merge_key) & l->hashmask;
+ bucket = jenkins_hash((unsigned char*) merge_key) & l->hashmask;
for (p = &l->hashtable[bucket]; *p; p = &(*p)->next)
{
#include <yaz/yaz-util.h>
#include "termlists.h"
+#include "jenkins_hash.h"
// Discussion:
// As terms are found in incoming records, they are added to (or updated in) a
NMEM nmem;
};
-
-// Jenkins one-at-a-time hash (from wikipedia)
-static unsigned int hash(const unsigned char *key)
-{
- unsigned int hash = 0;
-
- while (*key)
- {
- hash += *(key++);
- hash += (hash << 10);
- hash ^= (hash >> 6);
- }
- hash += (hash << 3);
- hash ^= (hash >> 11);
- hash += (hash << 15);
- return hash;
-}
-
struct termlist *termlist_create(NMEM nmem, int numterms, int highscore_size)
{
int hashsize = 1;
for (cp = buf + strlen(buf); cp != buf && strchr(",. -", cp[-1]); cp--)
cp[-1] = '\0';
- bucket = hash((unsigned char *)buf) & tl->hashmask;
+ bucket = jenkins_hash((unsigned char *)buf) & tl->hashmask;
for (p = &tl->hashtable[bucket]; *p; p = &(*p)->next)
{
if (!strcmp(buf, (*p)->term.term))