diff options
Diffstat (limited to 'blame.c')
-rw-r--r-- | blame.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -417,14 +417,15 @@ static void get_fingerprint(struct fingerprint *result, /* Ignore whitespace pairs */ if (hash == 0) continue; - hashmap_entry_init(entry, hash); + hashmap_entry_init(&entry->entry, hash); - found_entry = hashmap_get(&result->map, entry, NULL); + found_entry = hashmap_get_entry(&result->map, entry, + /* member name */ entry, NULL); if (found_entry) { found_entry->count += 1; } else { entry->count = 1; - hashmap_add(&result->map, entry); + hashmap_add(&result->map, &entry->entry); ++entry; } } @@ -432,7 +433,7 @@ static void get_fingerprint(struct fingerprint *result, static void free_fingerprint(struct fingerprint *f) { - hashmap_free(&f->map, 0); + hashmap_free(&f->map); free(f->entries); } @@ -449,10 +450,10 @@ static int fingerprint_similarity(struct fingerprint *a, struct fingerprint *b) struct hashmap_iter iter; const struct fingerprint_entry *entry_a, *entry_b; - hashmap_iter_init(&b->map, &iter); - - while ((entry_b = hashmap_iter_next(&iter))) { - if ((entry_a = hashmap_get(&a->map, entry_b, NULL))) { + hashmap_for_each_entry(&b->map, &iter, entry_b, + entry /* member name */) { + entry_a = hashmap_get_entry(&a->map, entry_b, entry, NULL); + if (entry_a) { intersection += entry_a->count < entry_b->count ? entry_a->count : entry_b->count; } @@ -470,10 +471,12 @@ static void fingerprint_subtract(struct fingerprint *a, struct fingerprint *b) hashmap_iter_init(&b->map, &iter); - while ((entry_b = hashmap_iter_next(&iter))) { - if ((entry_a = hashmap_get(&a->map, entry_b, NULL))) { + hashmap_for_each_entry(&b->map, &iter, entry_b, + entry /* member name */) { + entry_a = hashmap_get_entry(&a->map, entry_b, entry, NULL); + if (entry_a) { if (entry_a->count <= entry_b->count) - hashmap_remove(&a->map, entry_b, NULL); + hashmap_remove(&a->map, &entry_b->entry, NULL); else entry_a->count -= entry_b->count; } |