]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/helper/test-hashmap.c
hashmap: use *_entry APIs to wrap container_of
[thirdparty/git.git] / t / helper / test-hashmap.c
index aaf17b0ddf9e8ddd1270f613f8c71841c6644eb9..e82cbfdee272a8573c625cf5417518a7885497f7 100644 (file)
@@ -37,7 +37,7 @@ static struct test_entry *alloc_test_entry(unsigned int hash,
        size_t klen = strlen(key);
        size_t vlen = strlen(value);
        struct test_entry *entry = xmalloc(st_add4(sizeof(*entry), klen, vlen, 2));
-       hashmap_entry_init(entry, hash);
+       hashmap_entry_init(&entry->ent, hash);
        memcpy(entry->key, key, klen + 1);
        memcpy(entry->key + klen + 1, value, vlen + 1);
        return entry;
@@ -103,8 +103,8 @@ static void perf_hashmap(unsigned int method, unsigned int rounds)
 
                        /* add entries */
                        for (i = 0; i < TEST_SIZE; i++) {
-                               hashmap_entry_init(entries[i], hashes[i]);
-                               hashmap_add(&map, entries[i]);
+                               hashmap_entry_init(&entries[i]->ent, hashes[i]);
+                               hashmap_add(&map, &entries[i]->ent);
                        }
 
                        hashmap_free(&map, 0);
@@ -116,8 +116,8 @@ static void perf_hashmap(unsigned int method, unsigned int rounds)
                /* fill the map (sparsely if specified) */
                j = (method & TEST_SPARSE) ? TEST_SIZE / 10 : TEST_SIZE;
                for (i = 0; i < j; i++) {
-                       hashmap_entry_init(entries[i], hashes[i]);
-                       hashmap_add(&map, entries[i]);
+                       hashmap_entry_init(&entries[i]->ent, hashes[i]);
+                       hashmap_add(&map, &entries[i]->ent);
                }
 
                for (j = 0; j < rounds; j++) {
@@ -179,7 +179,7 @@ int cmd__hashmap(int argc, const char **argv)
                        entry = alloc_test_entry(hash, p1, p2);
 
                        /* add to hashmap */
-                       hashmap_add(&map, entry);
+                       hashmap_add(&map, &entry->ent);
 
                } else if (!strcmp("put", cmd) && p1 && p2) {
 
@@ -187,23 +187,23 @@ int cmd__hashmap(int argc, const char **argv)
                        entry = alloc_test_entry(hash, p1, p2);
 
                        /* add / replace entry */
-                       entry = hashmap_put(&map, entry);
+                       entry = hashmap_put(&map, &entry->ent);
 
                        /* print and free replaced entry, if any */
                        puts(entry ? get_value(entry) : "NULL");
                        free(entry);
 
                } else if (!strcmp("get", cmd) && p1) {
-
                        /* lookup entry in hashmap */
-                       entry = hashmap_get_from_hash(&map, hash, p1);
+                       entry = hashmap_get_entry_from_hash(&map, hash, p1,
+                                                       struct test_entry, ent);
 
                        /* print result */
                        if (!entry)
                                puts("NULL");
-                       while (entry) {
+                       hashmap_for_each_entry_from(&map, entry,
+                                               struct test_entry, ent) {
                                puts(get_value(entry));
-                               entry = hashmap_get_next(&map, entry);
                        }
 
                } else if (!strcmp("remove", cmd) && p1) {