MCPcopy Create free account
hub / github.com/ElementsProject/elements / ComputeMaxElements

Function ComputeMaxElements

src/minisketch/src/false_positives.h:91–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91size_t ComputeMaxElements(uint32_t bits, size_t capacity, uint32_t fpbits) {
92 if (bits == 0) return 0;
93 // Start with max_elements=capacity, and decrease max_elements until the corresponding capacity is capacity.
94 size_t max_elements = capacity;
95 while (true) {
96 size_t capacity_for_max_elements = ComputeCapacity(bits, max_elements, fpbits);
97 CHECK_SAFE(capacity_for_max_elements >= capacity);
98 if (capacity_for_max_elements <= capacity) return max_elements;
99 size_t adjust = capacity_for_max_elements - capacity;
100 // Decrementing max_elements by N will at most decrement the corresponding capacity by N.
101 // As the observed capacity is adjust too high, we can safely decrease max_elements by adjust.
102 // If that brings us into negative max_elements territory, no solution exists and we return 0.
103 if (max_elements < adjust) return 0;
104 max_elements -= adjust;
105 }
106}
107
108} // namespace
109

Callers 2

DecodeFPMethod · 0.85

Calls 1

ComputeCapacityFunction · 0.85

Tested by

no test coverage detected