Skip to content

Commit 8fbb558

Browse files
peffgitster
authored andcommitted
khash: rename kh_oid_t to kh_oid_set
khash lets us define a hash as either a map or a set (i.e., with no "value" type). For the oid maps we define, "oid" is the set and "oid_map" is the map. As the bug in the previous commit shows, it's easy to pick the wrong one. So let's make the names more distinct: "oid_set" and "oid_map". An alternative naming scheme would be to actually name the type after the key/value types. So e.g., "oid" _would_ be the set, since it has no value type. And "oid_map" would become "oid_void" or similar (and "oid_pos" becomes "oid_int"). That's better in some ways: it's more regular, and a given map type can be more reasily reused in multiple contexts (e.g., something storing an "int" that isn't a "pos"). But it's also slightly less descriptive. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4ed43d1 commit 8fbb558

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

khash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static inline int oid_equal(struct object_id a, struct object_id b)
342342
return oideq(&a, &b);
343343
}
344344

345-
KHASH_INIT(oid, struct object_id, int, 0, oid_hash, oid_equal)
345+
KHASH_INIT(oid_set, struct object_id, int, 0, oid_hash, oid_equal)
346346

347347
KHASH_INIT(oid_map, struct object_id, void *, 1, oid_hash, oid_equal)
348348

oidset.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@ void oidset_init(struct oidset *set, size_t initial_size)
55
{
66
memset(&set->set, 0, sizeof(set->set));
77
if (initial_size)
8-
kh_resize_oid(&set->set, initial_size);
8+
kh_resize_oid_set(&set->set, initial_size);
99
}
1010

1111
int oidset_contains(const struct oidset *set, const struct object_id *oid)
1212
{
13-
khiter_t pos = kh_get_oid(&set->set, *oid);
13+
khiter_t pos = kh_get_oid_set(&set->set, *oid);
1414
return pos != kh_end(&set->set);
1515
}
1616

1717
int oidset_insert(struct oidset *set, const struct object_id *oid)
1818
{
1919
int added;
20-
kh_put_oid(&set->set, *oid, &added);
20+
kh_put_oid_set(&set->set, *oid, &added);
2121
return !added;
2222
}
2323

2424
int oidset_remove(struct oidset *set, const struct object_id *oid)
2525
{
26-
khiter_t pos = kh_get_oid(&set->set, *oid);
26+
khiter_t pos = kh_get_oid_set(&set->set, *oid);
2727
if (pos == kh_end(&set->set))
2828
return 0;
29-
kh_del_oid(&set->set, pos);
29+
kh_del_oid_set(&set->set, pos);
3030
return 1;
3131
}
3232

3333
void oidset_clear(struct oidset *set)
3434
{
35-
kh_release_oid(&set->set);
35+
kh_release_oid_set(&set->set);
3636
oidset_init(set, 0);
3737
}

oidset.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* A single oidset; should be zero-initialized (or use OIDSET_INIT).
2121
*/
2222
struct oidset {
23-
kh_oid_t set;
23+
kh_oid_set_t set;
2424
};
2525

2626
#define OIDSET_INIT { { 0 } }
@@ -62,7 +62,7 @@ int oidset_remove(struct oidset *set, const struct object_id *oid);
6262
void oidset_clear(struct oidset *set);
6363

6464
struct oidset_iter {
65-
kh_oid_t *set;
65+
kh_oid_set_t *set;
6666
khiter_t iter;
6767
};
6868

0 commit comments

Comments
 (0)