Document some functions defined in object.c

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Acked-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Feb 28, 2014 at 17:29 UTC 33bef7ea256e620c579aeff0e672b0becc79c75c
2 files changed +35 -1
object.c
+28 -1
@@ -43,14 +43,32 @@ int type_from_string(const char *str)
43 die("invalid object type \"%s\"", str);
44 }
45
46 +/*
47 + * Return a numerical hash value between 0 and n-1 for the object with
48 + * the specified sha1. n must be a power of 2. Please note that the
49 + * return value is *not* consistent across computer architectures.
50 + */
51 static unsigned int hash_obj(const unsigned char *sha1, unsigned int n)
52 {
53 unsigned int hash;
54 +
55 + /*
56 + * Since the sha1 is essentially random, we just take the
57 + * required number of bits directly from the first
58 + * sizeof(unsigned int) bytes of sha1. First we have to copy
59 + * the bytes into a properly aligned integer. If we cared
60 + * about getting consistent results across architectures, we
61 + * would have to call ntohl() here, too.
62 + */
63 memcpy(&hash, sha1, sizeof(unsigned int));
50 - /* Assumes power-of-2 hash sizes in grow_object_hash */
64 return hash & (n - 1);
65 }
66
67 +/*
68 + * Insert obj into the hash table hash, which has length size (which
69 + * must be a power of 2). On collisions, simply overflow to the next
70 + * empty bucket.
71 + */
72 static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
73 {
74 unsigned int j = hash_obj(obj->sha1, size);
@@ -63,6 +81,10 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
81 hash[j] = obj;
82 }
83
84 +/*
85 + * Look up the record for the given sha1 in the hash map stored in
86 + * obj_hash. Return NULL if it was not found.
87 + */
88 struct object *lookup_object(const unsigned char *sha1)
89 {
90 unsigned int i, first;
@@ -92,6 +114,11 @@ struct object *lookup_object(const unsigned char *sha1)
114 return obj;
115 }
116
117 +/*
118 + * Increase the size of the hash map stored in obj_hash to the next
119 + * power of 2 (but at least 32). Copy the existing values to the new
120 + * hash map.
121 + */
122 static void grow_object_hash(void)
123 {
124 int i;
object.h
+7
@@ -42,7 +42,14 @@ struct object {
42 extern const char *typename(unsigned int type);
43 extern int type_from_string(const char *str);
44
45 +/*
46 + * Return the current number of buckets in the object hashmap.
47 + */
48 extern unsigned int get_max_object_index(void);
49 +
50 +/*
51 + * Return the object from the specified bucket in the object hashmap.
52 + */
53 extern struct object *get_indexed_object(unsigned int);
54
55 /*