]> git.ipfire.org Git - thirdparty/squid.git/blob - src/CacheDigest.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / CacheDigest.h
1 /*
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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
9 /* DEBUG: section 70 Cache Digest */
10
11 #ifndef SQUID_CACHEDIGEST_H_
12 #define SQUID_CACHEDIGEST_H_
13
14 #include "mem/forward.h"
15 #include "store_key_md5.h"
16
17 class CacheDigestGuessStats;
18 class StoreEntry;
19
20 class CacheDigest
21 {
22 MEMPROXY_CLASS(CacheDigest);
23 public:
24 CacheDigest(uint64_t capacity, uint8_t bpe);
25 ~CacheDigest();
26
27 // NP: only used by broken unit-test
28 /// produce a new identical copy of the digest object
29 CacheDigest *clone() const;
30
31 /// reset the digest mask and counters
32 void clear();
33
34 /// changes mask size to fit newCapacity, resets bits to 0
35 void updateCapacity(uint64_t newCapacity);
36
37 void add(const cache_key * key);
38 void remove(const cache_key * key);
39
40 /// \returns true if the key belongs to the digest
41 bool contains(const cache_key * key) const;
42
43 /// percentage of mask bits which are used
44 double usedMaskPercent() const;
45
46 /// calculate the size of mask required to digest up to
47 /// a specified capacity and bitsize.
48 static uint32_t CalcMaskSize(uint64_t cap, uint8_t bpe);
49
50 private:
51 void init(uint64_t newCapacity);
52
53 public:
54 /* public, read-only */
55 uint64_t count; /* number of digested entries */
56 uint64_t del_count; /* number of deletions performed so far */
57 uint64_t capacity; /* expected maximum for .count, not a hard limit */
58 char *mask; /* bit mask */
59 uint32_t mask_size; /* mask size in bytes */
60 int8_t bits_per_entry; /* number of bits allocated for each entry from capacity */
61 };
62
63 void cacheDigestGuessStatsUpdate(CacheDigestGuessStats * stats, int real_hit, int guess_hit);
64 void cacheDigestGuessStatsReport(const CacheDigestGuessStats * stats, StoreEntry * sentry, const char *label);
65 void cacheDigestReport(CacheDigest * cd, const char *label, StoreEntry * e);
66
67 #endif /* SQUID_CACHEDIGEST_H_ */
68