Skip to content

Commit 5081a4d

Browse files
committed
fixup??? Add a function to determine unique prefixes for a list of strings
This is needed to accommodate for stricter checking of the `hashmap_*()` function family. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 4fecc01 commit 5081a4d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

prefix-map.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
#include "prefix-map.h"
33

44
static int map_cmp(const void *unused_cmp_data,
5-
const void *entry,
6-
const void *entry_or_key,
5+
const struct hashmap_entry *entry,
6+
const struct hashmap_entry *entry_or_key,
77
const void *unused_keydata)
88
{
9-
const struct prefix_map_entry *a = entry;
10-
const struct prefix_map_entry *b = entry_or_key;
9+
const struct prefix_map_entry *a =
10+
container_of(entry, const struct prefix_map_entry, e);
11+
const struct prefix_map_entry *b =
12+
container_of(entry_or_key, const struct prefix_map_entry, e);
1113

1214
return a->prefix_length != b->prefix_length ||
1315
strncmp(a->name, b->name, a->prefix_length);
@@ -20,8 +22,8 @@ static void add_prefix_entry(struct hashmap *map, const char *name,
2022
result->name = name;
2123
result->prefix_length = prefix_length;
2224
result->item = item;
23-
hashmap_entry_init(result, memhash(name, prefix_length));
24-
hashmap_add(map, result);
25+
hashmap_entry_init(&result->e, memhash(name, prefix_length));
26+
hashmap_add(map, &result->e);
2527
}
2628

2729
static void init_prefix_map(struct prefix_map *prefix_map,
@@ -48,8 +50,8 @@ static void add_prefix_item(struct prefix_map *prefix_map,
4850
break;
4951

5052
e.prefix_length = j;
51-
hashmap_entry_init(&e, memhash(e.name, j));
52-
e2 = hashmap_get(&prefix_map->map, &e, NULL);
53+
hashmap_entry_init(&e.e, memhash(e.name, j));
54+
e2 = hashmap_get_entry(&prefix_map->map, &e, e, NULL);
5355
if (!e2) {
5456
/* prefix is unique at this stage */
5557
item->prefix_length = j;
@@ -105,5 +107,5 @@ void find_unique_prefixes(struct prefix_item **list, size_t nr,
105107
init_prefix_map(&prefix_map, min_length, max_length);
106108
for (i = 0; i < nr; i++)
107109
add_prefix_item(&prefix_map, list[i]);
108-
hashmap_free(&prefix_map.map, 1);
110+
hashmap_free_entries(&prefix_map.map, struct prefix_map_entry, e);
109111
}

0 commit comments

Comments
 (0)