]> git.ipfire.org Git - thirdparty/git.git/blobdiff - hashmap.c
hashmap_get_next returns "struct hashmap_entry *"
[thirdparty/git.git] / hashmap.c
index d42f01ff5ae6f3494d5b427c64bc64406c35d576..22bc7c5b3bd6395847ecaa0bd086a832d59c9117 100644 (file)
--- 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;
 }