summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Siegl <stesie@brokenpipe.de>2006-08-05 18:53:46 +0000
committerStefan Siegl <stesie@brokenpipe.de>2006-08-05 18:53:46 +0000
commite760d93255fdf3f0ffe39cf49a0b1ad4971412ef (patch)
tree1fafe85d91ebb15df439d8ed9f020f0f651d9925
parent8b0c7552cfa11c1704bc174478f3ceabb4ce14b1 (diff)
changed hashing algo to use some prime magic, fixed routines to use unsigned integers
-rw-r--r--src/netnode.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/netnode.c b/src/netnode.c
index dc9055262..092d03908 100644
--- a/src/netnode.c
+++ b/src/netnode.c
@@ -1,7 +1,7 @@
/**********************************************************
* netnode.c
*
- * Copyright(C) 2004, 2005 by Stefan Siegl <ssiegl@gmx.de>, Germany
+ * Copyright(C) 2004,2005,2006 by Stefan Siegl <stesie@brokenpipe.de>, Germany
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Publice License,
@@ -24,7 +24,7 @@
#include "fuse_i.h"
#include "fuse.h"
-#define HASH_BUCKETS 256
+#define HASH_BUCKETS 512
struct hash_element;
static struct hash_element {
@@ -44,14 +44,16 @@ ino_t fuse_next_inode = 1;
-static int
+static unsigned int
fuse_netnode_hash_value(const char *path)
{
- int hash = 0;
- int maxlen = 12; /* use the first 12 chars for hash generation only */
+ unsigned int hash = 0, a = 23, b = 251;
- while(maxlen -- && *path)
- hash += *(path ++);
+ while(*path)
+ {
+ hash = hash * a + *(path ++);
+ a *= b;
+ }
return hash % HASH_BUCKETS;
}
@@ -63,7 +65,9 @@ fuse_make_netnode(struct netnode *parent, const char *path)
{
struct hash_element *hash_el;
struct netnode *nn;
- int hash_value = fuse_netnode_hash_value(path);
+
+ unsigned int hash_value = fuse_netnode_hash_value(path);
+ DEBUG("make_netnode", "hash for '%s' is %u\n", path, hash_value);
DEBUG("netnodes_lock", "aquiring rwlock_reader_lock for %s.\n", path);
rwlock_reader_lock(&fuse_netnodes_lock);