blob: dbd71ebaf73044ea7d10d6686d6b193b32be6863 [file] [log] [blame]
Martin Ågrenbc626922020-12-31 12:56:23 +01001#ifndef HASH_LOOKUP_H
2#define HASH_LOOKUP_H
Junio C Hamano628522e2007-12-29 02:05:47 -08003
Jeff King8380dcd2021-01-28 01:20:23 -05004typedef const struct object_id *oid_access_fn(size_t index, const void *table);
Christian Couder96beef82009-04-04 22:59:26 +02005
Jeff King45ee13b2021-01-28 01:19:42 -05006int oid_pos(const struct object_id *oid,
Jeff King8380dcd2021-01-28 01:20:23 -05007 const void *table,
Jeff King45ee13b2021-01-28 01:19:42 -05008 size_t nr,
9 oid_access_fn fn);
Jonathan Tanb4e00f72018-02-13 10:39:39 -080010
11/*
Martin Ågrenbc626922020-12-31 12:56:23 +010012 * Searches for hash in table, using the given fanout table to determine the
Jonathan Tanb4e00f72018-02-13 10:39:39 -080013 * interval to search, then using binary search. Returns 1 if found, 0 if not.
14 *
15 * Takes the following parameters:
16 *
Martin Ågrenbc626922020-12-31 12:56:23 +010017 * - hash: the hash to search for
Jonathan Tanb4e00f72018-02-13 10:39:39 -080018 * - 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 Ågrenbc626922020-12-31 12:56:23 +010026 * element that is greater than hash (if the search is not successful)
Jonathan Tanb4e00f72018-02-13 10:39:39 -080027 *
28 * This function does not verify the validity of the fanout table.
29 */
Martin Ågrenbc626922020-12-31 12:56:23 +010030int bsearch_hash(const unsigned char *hash, const uint32_t *fanout_nbo,
Jonathan Tanb4e00f72018-02-13 10:39:39 -080031 const unsigned char *table, size_t stride, uint32_t *result);
Junio C Hamano628522e2007-12-29 02:05:47 -080032#endif