aboutsummaryrefslogtreecommitdiff
path: root/src/common/container.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-10-18 20:11:39 +0000
committerNick Mathewson <nickm@torproject.org>2005-10-18 20:11:39 +0000
commit5828f8920e1233870dfd0309073d116d08512767 (patch)
tree9dddb9145202cfbaf0cbb25f3a7cd32b6cb50767 /src/common/container.h
parent0349598928193b0865afd4868bf70e1fa17ef619 (diff)
downloadtor-5828f8920e1233870dfd0309073d116d08512767.tar.gz
tor-5828f8920e1233870dfd0309073d116d08512767.zip
Add a "Map from digest to void*" abstraction, since we already faked it in 3 places by encoding keys in hex and sticking them in a strmap.
svn:r5278
Diffstat (limited to 'src/common/container.h')
-rw-r--r--src/common/container.h37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/common/container.h b/src/common/container.h
index 9239c47cd3..50b20e4a42 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -108,27 +108,30 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
cmd; \
} } while (0)
+#define DECLARE_MAP_FNS(maptype, keytype, prefix) \
+ typedef struct maptype maptype; \
+ typedef struct prefix##entry_t prefix##iter_t; \
+ maptype* prefix##new(void); \
+ void* prefix##set(maptype *map, keytype key, void *val); \
+ void* prefix##get(maptype *map, keytype key); \
+ void* prefix##remove(maptype *map, keytype key); \
+ typedef void* (*prefix##foreach_fn)(keytype key, void *val, void *data); \
+ void prefix##foreach(maptype *map, prefix##foreach_fn fn, void *data); \
+ void prefix##free(maptype *map, void (*free_val)(void*)); \
+ int prefix##isempty(maptype *map); \
+ prefix##iter_t *prefix##iter_init(maptype *map); \
+ prefix##iter_t *prefix##iter_next(maptype *map, prefix##iter_t *iter); \
+ prefix##iter_t *prefix##iter_next_rmv(maptype *map, prefix##iter_t *iter); \
+ void prefix##iter_get(prefix##iter_t *iter, keytype *keyp, void **valp); \
+ int prefix##iter_done(prefix##iter_t *iter);
+
/* Map from const char * to void*. Implemented with a splay tree. */
-typedef struct strmap_t strmap_t;
-typedef struct strmap_entry_t strmap_iter_t;
-strmap_t* strmap_new(void);
-void* strmap_set(strmap_t *map, const char *key, void *val);
-void* strmap_get(strmap_t *map, const char *key);
-void* strmap_remove(strmap_t *map, const char *key);
+DECLARE_MAP_FNS(strmap_t, const char *, strmap_);
+DECLARE_MAP_FNS(digestmap_t, const char *, digestmap_);
+
void* strmap_set_lc(strmap_t *map, const char *key, void *val);
void* strmap_get_lc(strmap_t *map, const char *key);
void* strmap_remove_lc(strmap_t *map, const char *key);
-typedef void* (*strmap_foreach_fn)(const char *key, void *val, void *data);
-void strmap_foreach(strmap_t *map, strmap_foreach_fn fn, void *data);
-void strmap_free(strmap_t *map, void (*free_val)(void*));
-int strmap_isempty(strmap_t *map);
-
-strmap_iter_t *strmap_iter_init(strmap_t *map);
-strmap_iter_t *strmap_iter_next(strmap_t *map, strmap_iter_t *iter);
-strmap_iter_t *strmap_iter_next_rmv(strmap_t *map, strmap_iter_t *iter);
-void strmap_iter_get(strmap_iter_t *iter, const char **keyp, void **valp);
-
-int strmap_iter_done(strmap_iter_t *iter);
#endif