MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / bloom_init

Function bloom_init

libCacheSim/dataStructure/bloom.c:89–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89int bloom_init(struct bloom *bloom, int entries, double error) {
90 bloom->ready = 0;
91
92 if (entries < 1000 || error == 0) {
93 return 1;
94 }
95
96 bloom->entries = entries;
97 bloom->error = error;
98
99 double num = log(bloom->error);
100 double denom = 0.480453013918201; // ln(2)^2
101 bloom->bpe = -(num / denom);
102
103 double dentries = (double)entries;
104 bloom->bits = (int)(dentries * bloom->bpe);
105
106 if (bloom->bits % 8) {
107 bloom->bytes = (bloom->bits / 8) + 1;
108 } else {
109 bloom->bytes = bloom->bits / 8;
110 }
111
112 bloom->hashes = (int)ceil(0.693147180559945 * bloom->bpe); // ln(2)
113
114 bloom->bf = (unsigned char *)calloc(bloom->bytes, sizeof(unsigned char));
115 if (bloom->bf == NULL) { // LCOV_EXCL_START
116 return 1;
117 } // LCOV_EXCL_STOP
118
119 bloom->ready = 1;
120 return 0;
121}
122
123int bloom_check(struct bloom *bloom, const void *buffer, int len) {
124 return bloom_check_add(bloom, buffer, len, 0);

Callers 1

bloom_init_sizeFunction · 0.85

Calls 1

logFunction · 0.85

Tested by

no test coverage detected