1 #include "git-compat-util.h"
5 static int oidmap_neq(const void *hashmap_cmp_fn_data UNUSED
,
6 const struct hashmap_entry
*e1
,
7 const struct hashmap_entry
*e2
,
10 const struct oidmap_entry
*a
, *b
;
12 a
= container_of(e1
, const struct oidmap_entry
, internal_entry
);
13 b
= container_of(e2
, const struct oidmap_entry
, internal_entry
);
16 return !oideq(&a
->oid
, (const struct object_id
*) keydata
);
17 return !oideq(&a
->oid
, &b
->oid
);
20 void oidmap_init(struct oidmap
*map
, size_t initial_size
)
22 hashmap_init(&map
->map
, oidmap_neq
, NULL
, initial_size
);
25 void oidmap_free(struct oidmap
*map
, int free_entries
)
30 /* TODO: make oidmap itself not depend on struct layouts */
31 hashmap_clear_(&map
->map
, free_entries
? 0 : -1);
34 void *oidmap_get(const struct oidmap
*map
, const struct object_id
*key
)
39 return hashmap_get_from_hash(&map
->map
, oidhash(key
), key
);
42 void *oidmap_remove(struct oidmap
*map
, const struct object_id
*key
)
44 struct hashmap_entry entry
;
49 hashmap_entry_init(&entry
, oidhash(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
, oidhash(&to_put
->oid
));
61 return hashmap_put(&map
->map
, &to_put
->internal_entry
);