hashmap_entry_init(&k.ent, memhash(key, keylen));
k.key = key;
k.keylen = keylen;
- e = hashmap_get(&map->map, &k.ent, NULL);
+ e = hashmap_get_entry(&map->map, &k, NULL, struct attr_hash_entry, ent);
return e ? e->value : NULL;
}
continue;
hashmap_entry_init(&entry->entry, hash);
- found_entry = hashmap_get(&result->map, &entry->entry, NULL);
+ found_entry = hashmap_get_entry(&result->map, entry, NULL,
+ struct fingerprint_entry, entry);
if (found_entry) {
found_entry->count += 1;
} else {
hashmap_iter_init(&b->map, &iter);
while ((entry_b = hashmap_iter_next(&iter))) {
- if ((entry_a = hashmap_get(&a->map, &entry_b->entry, NULL))) {
+ entry_a = hashmap_get_entry(&a->map, entry_b, NULL,
+ struct fingerprint_entry, entry);
+ if (entry_a) {
intersection += entry_a->count < entry_b->count ?
entry_a->count : entry_b->count;
}
hashmap_iter_init(&b->map, &iter);
while ((entry_b = hashmap_iter_next(&iter))) {
- if ((entry_a = hashmap_get(&a->map, &entry_b->entry, NULL))) {
+ entry_a = hashmap_get_entry(&a->map, entry_b, NULL,
+ struct fingerprint_entry, entry);
+ if (entry_a) {
if (entry_a->count <= entry_b->count)
hashmap_remove(&a->map, &entry_b->entry, NULL);
else
static inline struct commit_name *find_commit_name(const struct object_id *peeled)
{
- return hashmap_get_from_hash(&names, oidhash(peeled), peeled);
+ return hashmap_get_entry_from_hash(&names, oidhash(peeled), peeled,
+ struct commit_name, entry);
}
static int replace_name(struct commit_name *e,
FLEX_ALLOC_STR(e, path, path);
hashmap_entry_init(&e->entry, strhash(path));
- existing = hashmap_get(map, &e->entry, NULL);
+ existing = hashmap_get_entry(map, e, NULL, struct pair_entry, entry);
if (existing) {
free(e);
e = existing;
hashmap_entry_init(&key.hash, memhash(orig, *len));
key.orig = orig;
key.orig_len = *len;
- ret = hashmap_get(map, &key.hash, NULL);
+ ret = hashmap_get_entry(map, &key, NULL, struct anonymized_entry, hash);
if (!ret) {
ret = xmalloc(sizeof(*ret));
for_each_string_list_item(remote_ref_item, &remote_refs_list) {
const char *refname = remote_ref_item->string;
struct ref *rm;
+ unsigned int hash = strhash(refname);
- item = hashmap_get_from_hash(&remote_refs, strhash(refname), refname);
+ item = hashmap_get_entry_from_hash(&remote_refs, hash, refname,
+ struct refname_hash_entry, ent);
if (!item)
BUG("unseen remote ref?");
if (rm->peer_ref) {
const char *refname = rm->peer_ref->name;
struct refname_hash_entry *peer_item;
+ unsigned int hash = strhash(refname);
- peer_item = hashmap_get_from_hash(&existing_refs,
- strhash(refname),
- refname);
+ peer_item = hashmap_get_entry_from_hash(&existing_refs,
+ hash, refname,
+ struct refname_hash_entry, ent);
if (peer_item) {
struct object_id *old_oid = &peer_item->oid;
oidcpy(&rm->peer_ref->old_oid, old_oid);
hashmap_entry_init(&k.ent, strhash(normalized_key));
k.key = normalized_key;
- found_entry = hashmap_get(&cs->config_hash, &k.ent, NULL);
+ found_entry = hashmap_get_entry(&cs->config_hash, &k, NULL,
+ struct config_set_element, ent);
free(normalized_key);
return found_entry;
}
memset(map, 0, sizeof(*map));
}
-void *hashmap_get(const struct hashmap *map, const struct hashmap_entry *key,
- const void *keydata)
+struct hashmap_entry *hashmap_get(const struct hashmap *map,
+ const struct hashmap_entry *key,
+ const void *keydata)
{
return *find_entry_ptr(map, key, keydata);
}
/* lookup interned string in pool */
hashmap_entry_init(&key.ent, memhash(data, len));
key.len = len;
- e = hashmap_get(&map, &key.ent, data);
+ e = hashmap_get_entry(&map, &key, data, struct pool_entry, ent);
if (!e) {
/* not found: create it */
FLEX_ALLOC_MEM(e, data, data, len);
* If an entry with matching hash code is found, `key` and `keydata` are passed
* to `hashmap_cmp_fn` to decide whether the entry matches the key.
*/
-void *hashmap_get(const struct hashmap *map, const struct hashmap_entry *key,
- const void *keydata);
+struct hashmap_entry *hashmap_get(const struct hashmap *map,
+ const struct hashmap_entry *key,
+ const void *keydata);
/*
* Returns the hashmap entry for the specified hash code and key data,
* `entry_or_key` parameter of `hashmap_cmp_fn` points to a hashmap_entry
* structure that should not be used in the comparison.
*/
-static inline void *hashmap_get_from_hash(const struct hashmap *map,
- unsigned int hash,
- const void *keydata)
+static inline struct hashmap_entry *hashmap_get_from_hash(
+ const struct hashmap *map,
+ unsigned int hash,
+ const void *keydata)
{
struct hashmap_entry key;
hashmap_entry_init(&key, hash);
return NULL;
hashmap_entry_init(&key.ent, strhash(dir));
key.dir = dir;
- return hashmap_get(hashmap, &key.ent, NULL);
+ return hashmap_get_entry(hashmap, &key, NULL,
+ struct dir_rename_entry, ent);
}
static int dir_rename_cmp(const void *unused_cmp_data,
hashmap_entry_init(&key.ent, strhash(target_file));
key.target_file = target_file;
- return hashmap_get(hashmap, &key.ent, NULL);
+ return hashmap_get_entry(hashmap, &key, NULL,
+ struct collision_entry, ent);
}
static int collision_cmp(void *unused_cmp_data,
struct dir_entry key;
hashmap_entry_init(&key.ent, hash);
key.namelen = namelen;
- return hashmap_get(&istate->dir_hash, &key.ent, name);
+ return hashmap_get_entry(&istate->dir_hash, &key, name,
+ struct dir_entry, ent);
}
static struct dir_entry *find_dir_entry(struct index_state *istate,
static struct delta_base_cache_entry *
get_delta_base_cache_entry(struct packed_git *p, off_t base_offset)
{
- struct hashmap_entry entry;
+ struct hashmap_entry entry, *e;
struct delta_base_cache_key key;
if (!delta_base_cache.cmpfn)
hashmap_entry_init(&entry, pack_entry_hash(p, base_offset));
key.p = p;
key.base_offset = base_offset;
- return hashmap_get(&delta_base_cache, &entry, &key);
+ e = hashmap_get(&delta_base_cache, &entry, &key);
+ return e ? container_of(e, struct delta_base_cache_entry, ent) : NULL;
}
static int delta_base_cache_key_eq(const struct delta_base_cache_key *a,
if (init_patch_id_entry(&patch, commit, ids))
return NULL;
- return hashmap_get(&ids->patches, &patch.ent, NULL);
+ return hashmap_get_entry(&ids->patches, &patch, NULL,
+ struct patch_id, ent);
}
struct patch_id *add_commit_patch_id(struct commit *commit,
static char *get_worktree_path(const struct used_atom *atom, const struct ref_array_item *ref)
{
- struct hashmap_entry entry;
+ struct hashmap_entry entry, *e;
struct ref_to_worktree_entry *lookup_result;
lazy_init_worktree_map();
hashmap_entry_init(&entry, strhash(ref->refname));
- lookup_result = hashmap_get(&(ref_to_worktree_map.map), &entry, ref->refname);
+ e = hashmap_get(&(ref_to_worktree_map.map), &entry, ref->refname);
- if (lookup_result)
- return xstrdup(lookup_result->wt->path);
- else
+ if (!e)
return xstrdup("");
+
+ lookup_result = container_of(e, struct ref_to_worktree_entry, ent);
+
+ return xstrdup(lookup_result->wt->path);
}
/*
const char *name)
{
struct ref_store_hash_entry *entry;
+ unsigned int hash;
if (!map->tablesize)
/* It's initialized on demand in register_ref_store(). */
return NULL;
- entry = hashmap_get_from_hash(map, strhash(name), name);
+ hash = strhash(name);
+ entry = hashmap_get_entry_from_hash(map, hash, name,
+ struct ref_store_hash_entry, ent);
return entry ? entry->refs : NULL;
}
{
struct remote *ret, *replaced;
struct remotes_hash_key lookup;
- struct hashmap_entry lookup_entry;
+ struct hashmap_entry lookup_entry, *e;
if (!len)
len = strlen(name);
lookup.len = len;
hashmap_entry_init(&lookup_entry, memhash(name, len));
- if ((ret = hashmap_get(&remotes_hash, &lookup_entry, &lookup)) != NULL)
- return ret;
+ e = hashmap_get(&remotes_hash, &lookup_entry, &lookup);
+ if (e)
+ return container_of(e, struct remote, ent);
ret = xcalloc(1, sizeof(struct remote));
ret->prune = -1; /* unspecified */
key.path = (char *)path;
oidset_init(&key.trees, 0);
- entry = hashmap_get(map, &key.ent, NULL);
+ entry = hashmap_get_entry(map, &key, NULL,
+ struct path_and_oids_entry, ent);
if (!entry) {
entry = xcalloc(1, sizeof(struct path_and_oids_entry));
hashmap_entry_init(&entry->ent, hash);
break;
}
- if ((entry = hashmap_get_from_hash(&subject2item,
- strhash(p), p)))
+ entry = hashmap_get_entry_from_hash(&subject2item,
+ strhash(p), p,
+ struct subject2item_entry,
+ entry);
+ if (entry)
/* found by title */
i2 = entry->i;
else if (!strchr(p, ' ') &&
hashmap_entry_init(&key.ent, strhash(cmd));
key.cmd = cmd;
- return hashmap_get(hashmap, &key.ent, NULL);
+ return hashmap_get_entry(hashmap, &key, NULL,
+ struct subprocess_entry, ent);
}
int subprocess_read_status(int fd, struct strbuf *status)
hashmap_entry_init(&key.ent, hash);
key.config = &key_config;
- entry = hashmap_get(&cache->for_path, &key.ent, NULL);
+ entry = hashmap_get_entry(&cache->for_path, &key, NULL,
+ struct submodule_entry, ent);
if (entry)
return entry->config;
return NULL;
hashmap_entry_init(&key.ent, hash);
key.config = &key_config;
- entry = hashmap_get(&cache->for_name, &key.ent, NULL);
+ entry = hashmap_get_entry(&cache->for_name, &key, NULL,
+ struct submodule_entry, ent);
if (entry)
return entry->config;
return NULL;