summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/rbthash.h
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2009-10-05 07:42:02 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-10-06 07:05:07 -0700
commitf3e46f2cb44e95c453bfa20c870dca6e42fc9a7a (patch)
tree6304d7d0158b66afa0b181597d13988efeaedf45 /libglusterfs/src/rbthash.h
parent39243caeca3322801429afcef5094ea734438669 (diff)
core: Add rbtree based hash table
Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 145 (NFSv3 related additions to 2.1 task list) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=145
Diffstat (limited to 'libglusterfs/src/rbthash.h')
-rw-r--r--libglusterfs/src/rbthash.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/libglusterfs/src/rbthash.h b/libglusterfs/src/rbthash.h
new file mode 100644
index 000000000..5bfa6afd0
--- /dev/null
+++ b/libglusterfs/src/rbthash.h
@@ -0,0 +1,75 @@
+/*
+ Copyright (c) 2008-2009 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS 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 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS 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, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __RBTHASH_TABLE_H_
+#define __RBTHASH_TABLE_H_
+#include "rb.h"
+#include "locking.h"
+#include "mem-pool.h"
+#include "logging.h"
+
+#include <pthread.h>
+
+#define GF_RBTHASH_MEMPOOL 1048576
+#define GF_RBTHASH "rbthash"
+
+struct rbthash_bucket {
+ struct rb_table *bucket;
+ gf_lock_t bucketlock;
+};
+
+typedef struct rbthash_entry {
+ void *data;
+ void *key;
+ int keylen;
+ uint32_t keyhash;
+} rbthash_entry_t;
+
+typedef uint32_t (*rbt_hasher_t) (void *data, int len);
+typedef void (*rbt_data_destroyer_t) (void *data);
+
+typedef struct rbthash_table {
+ int size;
+ int numbuckets;
+ struct mem_pool *entrypool;
+ gf_lock_t tablelock;
+ struct rbthash_bucket *buckets;
+ rbt_hasher_t hashfunc;
+ rbt_data_destroyer_t dfunc;
+} rbthash_table_t;
+
+extern rbthash_table_t *
+rbthash_table_init (int buckets, rbt_hasher_t hfunc,
+ rbt_data_destroyer_t dfunc);
+
+extern int
+rbthash_insert (rbthash_table_t *tbl, void *data, void *key, int keylen);
+
+extern void *
+rbthash_get (rbthash_table_t *tbl, void *key, int keylen);
+
+extern void *
+rbthash_remove (rbthash_table_t *tbl, void *key, int keylen);
+
+extern void *
+rbthash_replace (rbthash_table_t *tbl, void *key, int keylen, void *newdata);
+
+extern void
+rbthash_table_destroy (rbthash_table_t *tbl);
+#endif