aboutsummaryrefslogtreecommitdiffstats
path: root/hash.h
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2001-12-10 17:02:43 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2001-12-10 17:02:43 +0000
commit14f4297a049dd0d33425fccb8281abdac5d67ad6 (patch)
tree66af16621c3dc1f36d42b671848a800f29be9da0 /hash.h
parent[w3m-dev 02650] (diff)
downloadw3m-14f4297a049dd0d33425fccb8281abdac5d67ad6.tar.gz
w3m-14f4297a049dd0d33425fccb8281abdac5d67ad6.zip
[w3m-dev 02651] search keymap using hash
From: Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
Diffstat (limited to 'hash.h')
-rw-r--r--hash.h63
1 files changed, 61 insertions, 2 deletions
diff --git a/hash.h b/hash.h
index 56d9505..5f1118f 100644
--- a/hash.h
+++ b/hash.h
@@ -1,4 +1,4 @@
-/* $Id: hash.h,v 1.3 2001/11/24 02:01:26 ukai Exp $ */
+/* $Id: hash.h,v 1.4 2001/12/10 17:02:44 ukai Exp $ */
#ifndef HASH_H
#define HASH_H
@@ -20,7 +20,8 @@ extern type getHash_##sym(Hash_##sym *t, keytype key, type failval);
defhash(char *, int, si)
defhash(char *, char *, ss)
-defhash(char *, void *, hist)
+defhash(char *, void *, sv)
+defhash(int, void *, iv)
#define defhashfunc(keytype,type,sym) \
Hash_##sym * \
newHash_##sym(int size)\
@@ -79,4 +80,62 @@ getHash_##sym(Hash_##sym *t, keytype key, type failval)\
return failval;\
return hi->value;\
}
+#define defhashfunc_i(keytype,type,sym) \
+Hash_##sym * \
+newHash_##sym(int size)\
+{\
+ struct Hash_##sym *hash;\
+ int i;\
+\
+ hash = (Hash_##sym*)GC_malloc(sizeof(Hash_##sym));\
+ hash->size = size;\
+ hash->tab = (HashItem_##sym**)GC_malloc(size*sizeof(HashItem_##sym*));\
+ for (i = 0; i < size; i++)\
+ hash->tab[i] = NULL;\
+ return hash;\
+}\
+\
+static HashItem_##sym* \
+lookupHash_##sym(Hash_##sym *t, keytype key, int *hashval_return)\
+{\
+ HashItem_##sym *hi;\
+\
+ *hashval_return = key%t->size;\
+ for (hi = t->tab[*hashval_return]; hi != NULL; hi = hi->next) {\
+ if (hi->key == key)\
+ return hi;\
+ }\
+ return NULL;\
+}\
+\
+void \
+putHash_##sym(Hash_##sym *t, keytype key, type value)\
+{\
+ int h;\
+ HashItem_##sym *hi;\
+\
+ hi = lookupHash_##sym(t,key,&h);\
+ if (hi) {\
+ hi->value = value;\
+ return;\
+ }\
+\
+ hi = (HashItem_##sym*)GC_malloc(sizeof(HashItem_##sym));\
+ hi->key = key;\
+ hi->value = value;\
+ hi->next = t->tab[h];\
+ t->tab[h] = hi;\
+}\
+\
+type \
+getHash_##sym(Hash_##sym *t, keytype key, type failval)\
+{\
+ int h;\
+ HashItem_##sym *hi;\
+\
+ hi = lookupHash_##sym(t,key,&h);\
+ if (hi == NULL)\
+ return failval;\
+ return hi->value;\
+}
#endif /* not HASH_H */