]>
git.ipfire.org Git - thirdparty/git.git/blob - oidmap.c
4 static int oidmap_neq(const void *hashmap_cmp_fn_data
,
5 const void *entry
, const void *entry_or_key
,
8 const struct oidmap_entry
*entry_
= entry
;
10 return !oideq(&entry_
->oid
, (const struct object_id
*) keydata
);
11 return !oideq(&entry_
->oid
,
12 &((const struct oidmap_entry
*) entry_or_key
)->oid
);
15 static int hash(const struct object_id
*oid
)
18 memcpy(&hash
, oid
->hash
, sizeof(hash
));
22 void oidmap_init(struct oidmap
*map
, size_t initial_size
)
24 hashmap_init(&map
->map
, oidmap_neq
, NULL
, initial_size
);
27 void oidmap_free(struct oidmap
*map
, int free_entries
)
31 hashmap_free(&map
->map
, free_entries
);
34 void *oidmap_get(const struct oidmap
*map
, const struct object_id
*key
)
39 return hashmap_get_from_hash(&map
->map
, hash(key
), key
);
42 void *oidmap_remove(struct oidmap
*map
, const struct object_id
*key
)
44 struct hashmap_entry entry
;
49 hashmap_entry_init(&entry
, hash(key
));
50 return hashmap_remove(&map
->map
, &entry
, key
);
53 void *oidmap_put(struct oidmap
*map
, void *entry
)
55 struct oidmap_entry
*to_put
= entry
;
60 hashmap_entry_init(&to_put
->internal_entry
, hash(&to_put
->oid
));
61 return hashmap_put(&map
->map
, to_put
);