Skip to content

Commit 33bef7e

Browse files
mhaggergitster
authored andcommitted
Document some functions defined in object.c
Signed-off-by: Michael Haggerty <[email protected]> Acked-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f91e79 commit 33bef7e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

object.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,32 @@ int type_from_string(const char *str)
4343
die("invalid object type \"%s\"", str);
4444
}
4545

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+
*/
4651
static unsigned int hash_obj(const unsigned char *sha1, unsigned int n)
4752
{
4853
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+
*/
4963
memcpy(&hash, sha1, sizeof(unsigned int));
50-
/* Assumes power-of-2 hash sizes in grow_object_hash */
5164
return hash & (n - 1);
5265
}
5366

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+
*/
5472
static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
5573
{
5674
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
6381
hash[j] = obj;
6482
}
6583

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+
*/
6688
struct object *lookup_object(const unsigned char *sha1)
6789
{
6890
unsigned int i, first;
@@ -92,6 +114,11 @@ struct object *lookup_object(const unsigned char *sha1)
92114
return obj;
93115
}
94116

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+
*/
95122
static void grow_object_hash(void)
96123
{
97124
int i;

object.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ struct object {
4242
extern const char *typename(unsigned int type);
4343
extern int type_from_string(const char *str);
4444

45+
/*
46+
* Return the current number of buckets in the object hashmap.
47+
*/
4548
extern unsigned int get_max_object_index(void);
49+
50+
/*
51+
* Return the object from the specified bucket in the object hashmap.
52+
*/
4653
extern struct object *get_indexed_object(unsigned int);
4754

4855
/*

0 commit comments

Comments
 (0)