19 #include "ext/siphash.h"
27 return !strcmp(a->name, b->name);
31 static inline unsigned
34 return (
unsigned) siphash24g(a->name, strlen(a->name));
46 memset(map, 0,
sizeof(*map));
47 HT_INIT(namemap_ht, &map->ht);
56 if (map->names &&
id < (
unsigned)smartlist_len(map->names)) {
97 memcpy(u.n.name,
name, namelen);
98 u.n.name[namelen] = 0;
99 const mapped_name_t *found = HT_FIND(namemap_ht, &map->ht, &u.n);
102 tor_assert(smartlist_get(map->names, found->intval) == found);
103 return found->intval;
117 size_t namelen = strlen(
name);
136 size_t namelen = strlen(
name);
141 if (PREDICT_UNLIKELY(map->names == NULL))
148 unsigned new_id = (unsigned)smartlist_len(map->names);
154 memcpy(insert->name,
name, namelen+1);
155 insert->intval = new_id;
157 HT_INSERT(namemap_ht, &map->ht, insert);
167 if (PREDICT_UNLIKELY(map->names == NULL))
170 return smartlist_len(map->names);
182 HT_CLEAR(namemap_ht, &map->ht);
186 smartlist_free(map->names);
188 memset(map, 0,
sizeof(*map));
HT_PROTOTYPE(hs_circuitmap_ht, circuit_t, hs_circuitmap_node, hs_circuit_hash_token, hs_circuits_have_same_token)
void tor_free_(void *mem)
void * tor_reallocarray_(void *ptr, size_t sz1, size_t sz2)
Headers for util_malloc.c.
const char * namemap_fmt_name(const namemap_t *map, unsigned id)
const char * namemap_get_name(const namemap_t *map, unsigned id)
unsigned namemap_get_id(const namemap_t *map, const char *name)
size_t namemap_get_size(const namemap_t *map)
static unsigned namemap_get_id_unchecked(const namemap_t *map, const char *name, size_t namelen)
void namemap_init(namemap_t *map)
static unsigned mapped_name_hash(const mapped_name_t *a)
void namemap_clear(namemap_t *map)
static int mapped_name_eq(const mapped_name_t *a, const mapped_name_t *b)
unsigned namemap_get_or_create_id(namemap_t *map, const char *name)
Internal declarations for namemap structure.
#define MAX_NAMEMAP_NAME_LEN
int tor_snprintf(char *str, size_t size, const char *format,...)
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
Macros to manage assertions, fatal and non-fatal.