Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion count/include/count_min.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class count_min_sketch{
std::vector<W, Allocator> _sketch_array; // the array stored by the sketch
uint64_t _seed;
W _total_weight;
std::vector<uint64_t> hash_seeds;
std::vector<uint64_t, typename std::allocator_traits<Allocator>::template rebind_alloc<uint64_t>> hash_seeds;

enum flags {IS_EMPTY};
static const uint8_t PREAMBLE_LONGS_SHORT = 2; // Empty -> need second byte for sketch parameters
Expand Down
3 changes: 2 additions & 1 deletion count/include/count_min_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ _num_hashes(num_hashes),
_num_buckets(num_buckets),
_sketch_array((static_cast<uint64_t>(num_hashes) * num_buckets < 1<<30) ? static_cast<size_t>(num_hashes) * num_buckets : 0, 0, _allocator),
_seed(seed),
_total_weight(0) {
_total_weight(0),
hash_seeds(_allocator) {
if (num_buckets < 3) {
throw std::invalid_argument("Using fewer than 3 buckets incurs relative error greater than 1.");
}
Expand Down
17 changes: 17 additions & 0 deletions count/test/count_min_allocation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,21 @@ TEST_CASE("CountMin sketch test allocator: bytes serialize-deserialize non-empty
REQUIRE(test_allocator_net_allocations == 0);
}

TEST_CASE("CountMin sketch test allocator: hash seeds use the sketch's allocator", "[cm_sketch_alloc]") {
test_allocator_total_bytes = 0;
test_allocator_net_allocations = 0;
{
const uint8_t n_hashes = 5;
const uint32_t n_buckets = 100;
const long long sketch_bytes = n_hashes * n_buckets * sizeof(uint64_t) + n_hashes * sizeof(uint64_t);
count_min_sketch_test_alloc c(n_hashes, n_buckets, DEFAULT_SEED, alloc(0));
// the counters and the hash seeds, all through the sketch's allocator
REQUIRE(test_allocator_total_bytes == sketch_bytes);
count_min_sketch_test_alloc copy(c);
REQUIRE(test_allocator_total_bytes == 2 * sketch_bytes);
}
REQUIRE(test_allocator_total_bytes == 0);
REQUIRE(test_allocator_net_allocations == 0);
}

} // namespace datasketches
Loading