1- sha1 -array API
1+ oid -array API
22==============
33
4- The sha1 -array API provides storage and manipulation of sets of SHA-1
4+ The oid -array API provides storage and manipulation of sets of object
55identifiers. The emphasis is on storage and processing efficiency,
66making them suitable for large lists. Note that the ordering of items is
77not preserved over some operations.
88
99Data Structures
1010---------------
1111
12- `struct sha1_array `::
12+ `struct oid_array `::
1313
14- A single array of SHA-1 hashes . This should be initialized by
15- assignment from `SHA1_ARRAY_INIT `. The `sha1 ` member contains
14+ A single array of object IDs . This should be initialized by
15+ assignment from `OID_ARRAY_INIT `. The `oid ` member contains
1616 the actual data. The `nr` member contains the number of items in
1717 the set. The `alloc` and `sorted` members are used internally,
1818 and should not be needed by API callers.
1919
2020Functions
2121---------
2222
23- `sha1_array_append `::
24- Add an item to the set. The sha1 will be placed at the end of
23+ `oid_array_append `::
24+ Add an item to the set. The object ID will be placed at the end of
2525 the array (but note that some operations below may lose this
2626 ordering).
2727
28- `sha1_array_lookup `::
29- Perform a binary search of the array for a specific sha1 .
28+ `oid_array_lookup `::
29+ Perform a binary search of the array for a specific object ID .
3030 If found, returns the offset (in number of elements) of the
31- sha1 . If not found, returns a negative integer. If the array is
32- not sorted, this function has the side effect of sorting it.
31+ object ID . If not found, returns a negative integer. If the array
32+ is not sorted, this function has the side effect of sorting it.
3333
34- `sha1_array_clear `::
34+ `oid_array_clear `::
3535 Free all memory associated with the array and return it to the
3636 initial, empty state.
3737
38- `sha1_array_for_each_unique `::
38+ `oid_array_for_each_unique `::
3939 Efficiently iterate over each unique element of the list,
4040 executing the callback function for each one. If the array is
4141 not sorted, this function has the side effect of sorting it. If
@@ -47,25 +47,25 @@ Examples
4747--------
4848
4949-----------------------------------------
50- int print_callback(const unsigned char sha1[20] ,
50+ int print_callback(const struct object_id *oid ,
5151 void *data)
5252{
53- printf("%s\n", sha1_to_hex(sha1 ));
53+ printf("%s\n", oid_to_hex(oid ));
5454 return 0; /* always continue */
5555}
5656
5757void some_func(void)
5858{
59- struct sha1_array hashes = SHA1_ARRAY_INIT ;
60- unsigned char sha1[20] ;
59+ struct sha1_array hashes = OID_ARRAY_INIT ;
60+ struct object_id oid ;
6161
6262 /* Read objects into our set */
63- while (read_object_from_stdin(sha1 ))
64- sha1_array_append (&hashes, sha1 );
63+ while (read_object_from_stdin(oid.hash ))
64+ oid_array_append (&hashes, &oid );
6565
6666 /* Check if some objects are in our set */
67- while (read_object_from_stdin(sha1 )) {
68- if (sha1_array_lookup (&hashes, sha1 ) >= 0)
67+ while (read_object_from_stdin(oid.hash )) {
68+ if (oid_array_lookup (&hashes, &oid ) >= 0)
6969 printf("it's in there!\n");
7070
7171 /*
@@ -75,6 +75,6 @@ void some_func(void)
7575 * Instead, this will sort once and then skip duplicates
7676 * in linear time.
7777 */
78- sha1_array_for_each_unique (&hashes, print_callback, NULL);
78+ oid_array_for_each_unique (&hashes, print_callback, NULL);
7979}
8080-----------------------------------------
0 commit comments