]> git.ipfire.org Git - thirdparty/squid.git/blame - include/hash.h
Source Format Enforcement (#1234)
[thirdparty/squid.git] / include / hash.h
CommitLineData
5c193dec 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
5c193dec
AJ
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
b5638623 9#ifndef SQUID_HASH_H
10#define SQUID_HASH_H
11
f52a7d75 12typedef void HASHFREE(void *);
13typedef int HASHCMP(const void *, const void *);
14typedef unsigned int HASHHASH(const void *, unsigned int);
f52a7d75 15
4b4693f9
FC
16class hash_link {
17public:
18 hash_link() : key(nullptr), next(nullptr) {}
186477c1 19 void *key;
f52a7d75 20 hash_link *next;
21};
22
4b4693f9
FC
23class hash_table {
24public:
f52a7d75 25 hash_link **buckets;
26 HASHCMP *cmp;
27 HASHHASH *hash;
28 unsigned int size;
29 unsigned int current_slot;
30 hash_link *next;
31 int count;
32};
33
e6ccf245 34SQUIDCEXTERN hash_table *hash_create(HASHCMP *, int, HASHHASH *);
35SQUIDCEXTERN void hash_join(hash_table *, hash_link *);
36SQUIDCEXTERN void hash_remove_link(hash_table *, hash_link *);
37SQUIDCEXTERN int hashPrime(int n);
4a8b20e8 38SQUIDCEXTERN hash_link *hash_lookup(hash_table *, const void *);
e6ccf245 39SQUIDCEXTERN void hash_first(hash_table *);
4a8b20e8 40SQUIDCEXTERN hash_link *hash_next(hash_table *);
e6ccf245 41SQUIDCEXTERN void hash_last(hash_table *);
42SQUIDCEXTERN hash_link *hash_get_bucket(hash_table *, unsigned int);
43SQUIDCEXTERN void hashFreeMemory(hash_table *);
44SQUIDCEXTERN void hashFreeItems(hash_table *, HASHFREE *);
45SQUIDCEXTERN HASHHASH hash_string;
46SQUIDCEXTERN HASHHASH hash4;
c85e510f 47SQUIDCEXTERN const char *hashKeyStr(const hash_link *);
f52a7d75 48
49/*
50 * Here are some good prime number choices. It's important not to
51 * choose a prime number that is too close to exact powers of 2.
52 *
53 * HASH_SIZE 103 // prime number < 128
54 * HASH_SIZE 229 // prime number < 256
55 * HASH_SIZE 467 // prime number < 512
56 * HASH_SIZE 977 // prime number < 1024
57 * HASH_SIZE 1979 // prime number < 2048
58 * HASH_SIZE 4019 // prime number < 4096
59 * HASH_SIZE 6037 // prime number < 6144
60 * HASH_SIZE 7951 // prime number < 8192
61 * HASH_SIZE 12149 // prime number < 12288
62 * HASH_SIZE 16231 // prime number < 16384
63 * HASH_SIZE 33493 // prime number < 32768
64 * HASH_SIZE 65357 // prime number < 65536
65 */
f53969cc 66#define DEFAULT_HASH_SIZE 7951 /* prime number < 8192 */
b5638623 67
68#endif /* SQUID_HASH_H */
f53969cc 69