]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/CacheDigest.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / CacheDigest.h
index 46f7478e6c65f1fe5b818fc21238993ea1cbca53..9fc266bb8ac7e8844cbff6abac9c6324a72dcd12 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
 #ifndef SQUID_CACHEDIGEST_H_
 #define SQUID_CACHEDIGEST_H_
 
-/* for cache_key */
-#include "typedefs.h"
+#include "mem/forward.h"
+#include "store_key_md5.h"
 
 class CacheDigestGuessStats;
 class StoreEntry;
 
-// currently a POD
 class CacheDigest
 {
+    MEMPROXY_CLASS(CacheDigest);
+public:
+    CacheDigest(uint64_t capacity, uint8_t bpe);
+    ~CacheDigest();
+
+    // NP: only used by broken unit-test
+    /// produce a new identical copy of the digest object
+    CacheDigest *clone() const;
+
+    /// reset the digest mask and counters
+    void clear();
+
+    /// changes mask size to fit newCapacity, resets bits to 0
+    void updateCapacity(uint64_t newCapacity);
+
+    void add(const cache_key * key);
+    void remove(const cache_key * key);
+
+    /// \returns true if the key belongs to the digest
+    bool contains(const cache_key * key) const;
+
+    /// percentage of mask bits which are used
+    double usedMaskPercent() const;
+
+    /// calculate the size of mask required to digest up to
+    /// a specified capacity and bitsize.
+    static uint32_t CalcMaskSize(uint64_t cap, uint8_t bpe);
+
+private:
+    void init(uint64_t newCapacity);
+
 public:
     /* public, read-only */
-    char *mask;         /* bit mask */
-    int mask_size;      /* mask size in bytes */
-    int capacity;       /* expected maximum for .count, not a hard limit */
-    int bits_per_entry;     /* number of bits allocated for each entry from capacity */
-    int count;          /* number of digested entries */
-    int del_count;      /* number of deletions performed so far */
+    uint64_t count;          /* number of digested entries */
+    uint64_t del_count;      /* number of deletions performed so far */
+    uint64_t capacity;       /* expected maximum for .count, not a hard limit */
+    char *mask;              /* bit mask */
+    uint32_t mask_size;      /* mask size in bytes */
+    int8_t bits_per_entry;   /* number of bits allocated for each entry from capacity */
 };
 
-CacheDigest *cacheDigestCreate(int capacity, int bpe);
-void cacheDigestDestroy(CacheDigest * cd);
-CacheDigest *cacheDigestClone(const CacheDigest * cd);
-void cacheDigestClear(CacheDigest * cd);
-void cacheDigestChangeCap(CacheDigest * cd, int new_cap);
-int cacheDigestTest(const CacheDigest * cd, const cache_key * key);
-void cacheDigestAdd(CacheDigest * cd, const cache_key * key);
-void cacheDigestDel(CacheDigest * cd, const cache_key * key);
-size_t cacheDigestCalcMaskSize(int cap, int bpe);
-int cacheDigestBitUtil(const CacheDigest * cd);
 void cacheDigestGuessStatsUpdate(CacheDigestGuessStats * stats, int real_hit, int guess_hit);
 void cacheDigestGuessStatsReport(const CacheDigestGuessStats * stats, StoreEntry * sentry, const char *label);
 void cacheDigestReport(CacheDigest * cd, const char *label, StoreEntry * e);
 
 #endif /* SQUID_CACHEDIGEST_H_ */
+