summary refs log tree commit diff
path: root/misc/hashtable.h
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2006-09-12 21:21:34 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2006-09-12 21:21:34 +0000
commit8695ecdf1886eb23bf72b738bfa26080877810e6 (patch)
treeaaac4e47e0eeacd0dcc1d9dd742578a82c013cb3 /misc/hashtable.h
parent848de36107edd65fc9135afe22f8f486af390393 (diff)
downloadbtpd-8695ecdf1886eb23bf72b738bfa26080877810e6.tar.gz
btpd-8695ecdf1886eb23bf72b738bfa26080877810e6.zip
Pointers to different things need not be represented in the same way.
Use the fact that we only can store structs in the table to make the
complex pointer use safe. Unfortunately the equal and hash functions
need to take void * arguments.

Diffstat (limited to 'misc/hashtable.h')
-rw-r--r--misc/hashtable.h27
1 files changed, 14 insertions, 13 deletions
diff --git a/misc/hashtable.h b/misc/hashtable.h
index 2dd227d..84a8e0b 100644
--- a/misc/hashtable.h
+++ b/misc/hashtable.h
@@ -5,28 +5,29 @@ struct htbl_iter {
     struct _htbl *tbl;
     size_t bi;
     size_t cnt;
-    void *obj;
+    struct _any *obj;
 };
 
 struct _htbl *_htbl_create(int (*equal)(const void *, const void *),
     uint32_t (*hash)(const void *), size_t keyoff, size_t chainoff);
 void _htbl_free(struct _htbl *tbl);
-void _htbl_insert(struct _htbl *tbl, void *o);
-void *_htbl_remove(struct _htbl *tbl, const void *key);
-void *_htbl_find(struct _htbl *tbl, const void *key);
-void _htbl_tov(struct _htbl *tb, void **v);
+void _htbl_insert(struct _htbl *tbl, struct _any *o);
+struct _any *_htbl_remove(struct _htbl *tbl, const void *key);
+struct _any *_htbl_find(struct _htbl *tbl, const void *key);
+void _htbl_tov(struct _htbl *tb, struct _any **v);
 size_t _htbl_size(struct _htbl *tbl);
 void _htbl_iter_init(struct _htbl *tbl, struct htbl_iter *it);
-void *_htbl_iter_next(struct htbl_iter *it);
+struct _any *_htbl_iter_next(struct htbl_iter *it);
 
-#define HTBLTYPE(name, type, ktype, kname, cname) \
+#define HTBL_ENTRY(name) struct _any *name
+
+#define HTBL_TYPE(name, type, ktype, kname, cname) \
 __attribute__((always_inline)) static inline struct name * \
-name##_create(int (*equal)(const ktype *, const ktype *), \
-    uint32_t (*hash)(const ktype *)) \
+name##_create(int (*equal)(const void *, const void *), \
+    uint32_t (*hash)(const void *)) \
 { \
     return (struct name *) \
-      _htbl_create((int (*)(const void *, const void *))equal, \
-        (uint32_t (*)(const void *))hash, offsetof(struct type, kname), \
+      _htbl_create(equal, hash, offsetof(struct type, kname), \
         offsetof(struct type, cname)); \
 } \
 \
@@ -51,12 +52,12 @@ name##_free(struct name *tbl) \
 __attribute__((always_inline)) static inline void \
 name##_insert(struct name *tbl, struct type *o) \
 { \
-    _htbl_insert((struct _htbl *)tbl, o); \
+    _htbl_insert((struct _htbl *)tbl, (struct _any *)o); \
 } \
 __attribute__((always_inline)) static inline void \
 name##_tov(struct name *tbl, struct type **v) \
 { \
-    _htbl_tov((struct _htbl *)tbl, (void **)v); \
+    _htbl_tov((struct _htbl *)tbl, (struct _any **)v); \
 } \
 \
 __attribute__((always_inline)) static inline size_t \