Martin Ågren | bc62692 | 2020-12-31 12:56:23 +0100 | [diff] [blame] | 1 | #ifndef HASH_LOOKUP_H |
| 2 | #define HASH_LOOKUP_H |
Junio C Hamano | 628522e | 2007-12-29 02:05:47 -0800 | [diff] [blame] | 3 | |
Jeff King | 8380dcd | 2021-01-28 01:20:23 -0500 | [diff] [blame] | 4 | typedef const struct object_id *oid_access_fn(size_t index, const void *table); |
Christian Couder | 96beef8 | 2009-04-04 22:59:26 +0200 | [diff] [blame] | 5 | |
Jeff King | 45ee13b | 2021-01-28 01:19:42 -0500 | [diff] [blame] | 6 | int oid_pos(const struct object_id *oid, |
Jeff King | 8380dcd | 2021-01-28 01:20:23 -0500 | [diff] [blame] | 7 | const void *table, |
Jeff King | 45ee13b | 2021-01-28 01:19:42 -0500 | [diff] [blame] | 8 | size_t nr, |
| 9 | oid_access_fn fn); |
Jonathan Tan | b4e00f7 | 2018-02-13 10:39:39 -0800 | [diff] [blame] | 10 | |
| 11 | /* |
Martin Ågren | bc62692 | 2020-12-31 12:56:23 +0100 | [diff] [blame] | 12 | * Searches for hash in table, using the given fanout table to determine the |
Jonathan Tan | b4e00f7 | 2018-02-13 10:39:39 -0800 | [diff] [blame] | 13 | * interval to search, then using binary search. Returns 1 if found, 0 if not. |
| 14 | * |
| 15 | * Takes the following parameters: |
| 16 | * |
Martin Ågren | bc62692 | 2020-12-31 12:56:23 +0100 | [diff] [blame] | 17 | * - hash: the hash to search for |
Jonathan Tan | b4e00f7 | 2018-02-13 10:39:39 -0800 | [diff] [blame] | 18 | * - fanout_nbo: a 256-element array of NETWORK-order 32-bit integers; the |
| 19 | * integer at position i represents the number of elements in table whose |
| 20 | * first byte is less than or equal to i |
| 21 | * - table: a sorted list of hashes with optional extra information in between |
| 22 | * - stride: distance between two consecutive elements in table (should be |
| 23 | * GIT_MAX_RAWSZ or greater) |
| 24 | * - result: if not NULL, this function stores the element index of the |
| 25 | * position found (if the search is successful) or the index of the least |
Martin Ågren | bc62692 | 2020-12-31 12:56:23 +0100 | [diff] [blame] | 26 | * element that is greater than hash (if the search is not successful) |
Jonathan Tan | b4e00f7 | 2018-02-13 10:39:39 -0800 | [diff] [blame] | 27 | * |
| 28 | * This function does not verify the validity of the fanout table. |
| 29 | */ |
Martin Ågren | bc62692 | 2020-12-31 12:56:23 +0100 | [diff] [blame] | 30 | int bsearch_hash(const unsigned char *hash, const uint32_t *fanout_nbo, |
Jonathan Tan | b4e00f7 | 2018-02-13 10:39:39 -0800 | [diff] [blame] | 31 | const unsigned char *table, size_t stride, uint32_t *result); |
Junio C Hamano | 628522e | 2007-12-29 02:05:47 -0800 | [diff] [blame] | 32 | #endif |