Skip to content

Commit 5487f1f

Browse files
committed
Add support for 0 capacity sketches
1 parent 2bec6d9 commit 5487f1f

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

include/minisketch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ int minisketch_implementation_supported(uint32_t bits, uint32_t implementation);
4242

4343
/** Construct a sketch for a given element size, implementation and capacity.
4444
*
45-
* If the combination of `bits` and `implementation` is unavailable, or if
46-
* `capacity` is 0, NULL is returned. If minisketch_implementation_supported
45+
* If the combination of `bits` and `implementation` is unavailable, or when
46+
* OOM occurs, NULL is returned. If minisketch_implementation_supported
4747
* returns 1 for the specified bits and implementation, this will always succeed
4848
* (except when allocation fails).
4949
*

src/minisketch.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,6 @@ int minisketch_implementation_supported(uint32_t bits, uint32_t implementation)
337337
}
338338

339339
minisketch* minisketch_create(uint32_t bits, uint32_t implementation, size_t capacity) {
340-
if (capacity == 0) {
341-
return nullptr;
342-
}
343340
try {
344341
Sketch* sketch = Construct(bits, implementation);
345342
if (sketch) {

src/test.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void TestExhaustive(uint32_t bits, size_t capacity) {
123123
/** Test properties of sketches with random elements put in. */
124124
void TestRandomized(uint32_t bits, size_t max_capacity, size_t iter) {
125125
std::random_device rnd;
126-
std::uniform_int_distribution<uint64_t> capacity_dist(1, std::min<uint64_t>(std::numeric_limits<uint64_t>::max() >> (64 - bits), max_capacity));
126+
std::uniform_int_distribution<uint64_t> capacity_dist(0, std::min<uint64_t>(std::numeric_limits<uint64_t>::max() >> (64 - bits), max_capacity));
127127
std::uniform_int_distribution<uint64_t> element_dist(1, std::numeric_limits<uint64_t>::max() >> (64 - bits));
128128
std::uniform_int_distribution<uint64_t> rand64(0, std::numeric_limits<uint64_t>::max());
129129
std::uniform_int_distribution<int64_t> size_offset_dist(-3, 3);
@@ -298,8 +298,11 @@ int main(int argc, char** argv) {
298298
TestRandomized(j, 4096, test_complexity / j);
299299
}
300300

301-
for (int weight = 2; weight <= 40; ++weight) {
302-
for (int bits = 2; bits <= 32 && bits <= weight; ++bits) {
301+
// Test capacity==0 together with all field sizes, and then
302+
// all combinations of bits and capacity up to a certain bits*capacity,
303+
// depending on test_complexity.
304+
for (int weight = 0; weight <= 40; ++weight) {
305+
for (int bits = 2; weight == 0 ? bits <= 64 : (bits <= 32 && bits <= weight); ++bits) {
303306
int capacity = weight / bits;
304307
if (capacity * bits != weight) continue;
305308
TestExhaustive(bits, capacity);

0 commit comments

Comments
 (0)