From 43dccb30a4ad2f39d57a53af442c144e4c71bd45 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 4 Dec 2013 15:20:05 +0900 Subject: [PATCH] move xhash to another repo --- .gitmodules | 3 ++ extlib/xhash | 1 + extlib/xhash/xhash.h | 100 ------------------------------------------- 3 files changed, 4 insertions(+), 100 deletions(-) create mode 100644 .gitmodules create mode 160000 extlib/xhash delete mode 100644 extlib/xhash/xhash.h diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..4a2a1cb8 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "extlib/xhash"] + path = extlib/xhash + url = git://github.com/wasabiz/xhash.git diff --git a/extlib/xhash b/extlib/xhash new file mode 160000 index 00000000..350f8895 --- /dev/null +++ b/extlib/xhash @@ -0,0 +1 @@ +Subproject commit 350f8895bf888aceea87c38e38e19adfd604f9d2 diff --git a/extlib/xhash/xhash.h b/extlib/xhash/xhash.h deleted file mode 100644 index b20af2c3..00000000 --- a/extlib/xhash/xhash.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef XHASH_H__ -#define XHASH_H__ - -/* - * Copyright (c) 2013 by Yuichi Nishiwaki - */ - -#include -#include - -/* simple string to int hash table */ - -#define XHASH_INIT_SIZE 11 - -struct xh_entry { - struct xh_entry *next; - const char *key; - int val; -}; - -struct xhash { - struct xh_entry **buckets; - size_t size; -}; - -static inline struct xhash * -xh_new() -{ - struct xhash *x; - - x = (struct xhash *)malloc(sizeof(struct xhash)); - x->size = XHASH_INIT_SIZE; - x->buckets = (struct xh_entry **)calloc(XHASH_INIT_SIZE, sizeof(struct xh_entry *)); - return x; -} - -static int -xh_hash(const char *str) -{ - int hash = 0; - - while (*str) { - hash = hash * 31 + *str++; - } - return hash; -} - -static inline struct xh_entry * -xh_get(struct xhash *x, const char *key) -{ - int idx; - struct xh_entry *e; - - idx = xh_hash(key) % x->size; - for (e = x->buckets[idx]; e; e = e->next) { - if (strcmp(key, e->key) == 0) - return e; - } - return NULL; -} - -static inline struct xh_entry * -xh_put(struct xhash *x, const char *key, int val) -{ - int idx; - struct xh_entry *e; - - if ((e = xh_get(x, key))) { - e->val = val; - return e; - } - - idx = xh_hash(key) % x->size; - e = (struct xh_entry *)malloc(sizeof(struct xh_entry)); - e->next = x->buckets[idx]; - e->key = strdup(key); - e->val = val; - - return x->buckets[idx] = e; -} - -static inline void -xh_destory(struct xhash *x) -{ - int i; - struct xh_entry *e, *d; - - for (i = 0; i < x->size; ++i) { - e = x->buckets[i]; - while (e) { - d = e->next; - free((void*)e->key); - free(e); - e = d; - } - } - free(x); -} - -#endif