2 * decorate.c - decorate a git object with some arbitrary
9 static unsigned int hash_obj(const struct object *obj, unsigned int n)
11 return sha1hash(obj->oid.hash) % n;
14 static void *insert_decoration(struct decoration *n, const struct object *base, void *decoration)
17 struct decoration_entry *entries = n->entries;
18 unsigned int j = hash_obj(base, size);
20 while (entries[j].base) {
21 if (entries[j].base == base) {
22 void *old = entries[j].decoration;
23 entries[j].decoration = decoration;
29 entries[j].base = base;
30 entries[j].decoration = decoration;
35 static void grow_decoration(struct decoration *n)
38 int old_size = n->size;
39 struct decoration_entry *old_entries = n->entries;
41 n->size = (old_size + 1000) * 3 / 2;
42 n->entries = xcalloc(n->size, sizeof(struct decoration_entry));
45 for (i = 0; i < old_size; i++) {
46 const struct object *base = old_entries[i].base;
47 void *decoration = old_entries[i].decoration;
51 insert_decoration(n, base, decoration);
56 void *add_decoration(struct decoration *n, const struct object *obj,
61 if (nr > n->size * 2 / 3)
63 return insert_decoration(n, obj, decoration);
66 void *lookup_decoration(struct decoration *n, const struct object *obj)
70 /* nothing to lookup */
73 j = hash_obj(obj, n->size);
75 struct decoration_entry *ref = n->entries + j;
77 return ref->decoration;