diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-12-03 13:10:33 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-01-02 14:10:48 -0500 |
commit | cfab9f0755e3f7f0b49879ed9771fd2d325051a2 (patch) | |
tree | f20ef088fbc39db5c1b42d8fba5e9f42b08a78a9 /src/common/di_ops.h | |
parent | 014e69054d5a09664753d149eb5556ec059bcb11 (diff) | |
download | tor-cfab9f0755e3f7f0b49879ed9771fd2d325051a2.tar.gz tor-cfab9f0755e3f7f0b49879ed9771fd2d325051a2.zip |
Add a data-invariant linear-search map structure
I'm going to use this for looking op keys server-side for ntor.
Diffstat (limited to 'src/common/di_ops.h')
-rw-r--r-- | src/common/di_ops.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/common/di_ops.h b/src/common/di_ops.h index 8f0bb698f9..a86f56c966 100644 --- a/src/common/di_ops.h +++ b/src/common/di_ops.h @@ -27,5 +27,19 @@ int tor_memeq(const void *a, const void *b, size_t sz); #define fast_memeq(a,b,c) (0==memcmp((a),(b),(c))) #define fast_memneq(a,b,c) (0!=memcmp((a),(b),(c))) +/** A type for a map from DIGEST256_LEN-byte blobs to void*, such that + * data lookups take an amount of time proportional only to the size + * of the map, and not to the position or presence of the item in the map. + * + * Not efficient for large maps! */ +typedef struct di_digest256_map_t di_digest256_map_t; +typedef void (*dimap_free_fn)(void *); + +void dimap_free(di_digest256_map_t *map, dimap_free_fn free_fn); +void dimap_add_entry(di_digest256_map_t **map, + const uint8_t *key, void *val); +void *dimap_search(const di_digest256_map_t *map, const uint8_t *key, + void *dflt_val); + #endif |