X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=hashmap.c;h=22bc7c5b3bd6395847ecaa0bd086a832d59c9117;hb=6bcbdfb277bdc81b5ad6996b3fb005382a35c2ee;hp=d42f01ff5ae6f3494d5b427c64bc64406c35d576;hpb=17c8e0b33dc6d0fc975fb4ca1d78d859e77791a6;p=thirdparty%2Fgit.git diff --git a/hashmap.c b/hashmap.c index d42f01ff5a..22bc7c5b3b 100644 --- a/hashmap.c +++ b/hashmap.c @@ -186,26 +186,28 @@ void hashmap_free(struct hashmap *map, int free_entries) memset(map, 0, sizeof(*map)); } -void *hashmap_get(const struct hashmap *map, const void *key, const void *keydata) +void *hashmap_get(const struct hashmap *map, const struct hashmap_entry *key, + const void *keydata) { return *find_entry_ptr(map, key, keydata); } -void *hashmap_get_next(const struct hashmap *map, const void *entry) +struct hashmap_entry *hashmap_get_next(const struct hashmap *map, + const struct hashmap_entry *entry) { - struct hashmap_entry *e = ((struct hashmap_entry *) entry)->next; + struct hashmap_entry *e = entry->next; for (; e; e = e->next) if (entry_equals(map, entry, e, NULL)) return e; return NULL; } -void hashmap_add(struct hashmap *map, void *entry) +void hashmap_add(struct hashmap *map, struct hashmap_entry *entry) { unsigned int b = bucket(map, entry); /* add entry */ - ((struct hashmap_entry *) entry)->next = map->table[b]; + entry->next = map->table[b]; map->table[b] = entry; /* fix size and rehash if appropriate */ @@ -216,7 +218,8 @@ void hashmap_add(struct hashmap *map, void *entry) } } -void *hashmap_remove(struct hashmap *map, const void *key, const void *keydata) +void *hashmap_remove(struct hashmap *map, const struct hashmap_entry *key, + const void *keydata) { struct hashmap_entry *old; struct hashmap_entry **e = find_entry_ptr(map, key, keydata); @@ -238,7 +241,7 @@ void *hashmap_remove(struct hashmap *map, const void *key, const void *keydata) return old; } -void *hashmap_put(struct hashmap *map, void *entry) +void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry) { struct hashmap_entry *old = hashmap_remove(map, entry, NULL); hashmap_add(map, entry); @@ -293,15 +296,15 @@ const void *memintern(const void *data, size_t len) hashmap_init(&map, (hashmap_cmp_fn) pool_entry_cmp, NULL, 0); /* lookup interned string in pool */ - hashmap_entry_init(&key, memhash(data, len)); + hashmap_entry_init(&key.ent, memhash(data, len)); key.len = len; - e = hashmap_get(&map, &key, data); + e = hashmap_get(&map, &key.ent, data); if (!e) { /* not found: create it */ FLEX_ALLOC_MEM(e, data, data, len); - hashmap_entry_init(e, key.ent.hash); + hashmap_entry_init(&e->ent, key.ent.hash); e->len = len; - hashmap_add(&map, e); + hashmap_add(&map, &e->ent); } return e->data; }