types and casts
diff --git a/fi/include/frequent_items_sketch_impl.hpp b/fi/include/frequent_items_sketch_impl.hpp
index b9c9e55..593aa03 100644
--- a/fi/include/frequent_items_sketch_impl.hpp
+++ b/fi/include/frequent_items_sketch_impl.hpp
@@ -199,7 +199,7 @@
write(os, weights, sizeof(W) * num_items);
aw.deallocate(weights, num_items);
S().serialize(os, items, num_items);
- for (unsigned i = 0; i < num_items; i++) items[i].~T();
+ for (i = 0; i < num_items; i++) items[i].~T();
alloc.deallocate(items, num_items);
}
}
@@ -256,7 +256,7 @@
aw.deallocate(weights, num_items);
const size_t bytes_remaining = end_ptr - ptr;
ptr += S().serialize(ptr, bytes_remaining, items, num_items);
- for (unsigned i = 0; i < num_items; i++) items[i].~T();
+ for (i = 0; i < num_items; i++) items[i].~T();
alloc.deallocate(items, num_items);
}
return bytes;
@@ -266,20 +266,20 @@
class frequent_items_sketch<T, W, H, E, S, A>::items_deleter {
public:
items_deleter(uint32_t num, bool destroy, const A& allocator):
- allocator(allocator), num(num), destroy(destroy) {}
- void set_destroy(bool destroy) { this->destroy = destroy; }
+ allocator_(allocator), num_(num), destroy_(destroy) {}
+ void set_destroy(bool destroy) { destroy_ = destroy; }
void operator() (T* ptr) {
if (ptr != nullptr) {
- if (destroy) {
- for (uint32_t i = 0; i < num; ++i) ptr[i].~T();
+ if (destroy_) {
+ for (uint32_t i = 0; i < num_; ++i) ptr[i].~T();
}
- allocator.deallocate(ptr, num);
+ allocator_.deallocate(ptr, num_);
}
}
private:
- A allocator;
- uint32_t num;
- bool destroy;
+ A allocator_;
+ uint32_t num_;
+ bool destroy_;
};
template<typename T, typename W, typename H, typename E, typename S, typename A>
@@ -350,7 +350,7 @@
check_serial_version(serial_version);
check_family_id(family_id);
check_size(lg_cur_size, lg_max_size);
- ensure_minimum_memory(size, 1 << preamble_longs);
+ ensure_minimum_memory(size, 1ULL << preamble_longs);
frequent_items_sketch<T, W, H, E, S, A> sketch(lg_max_size, lg_cur_size, allocator);
if (!is_empty) {
diff --git a/fi/include/reverse_purge_hash_map_impl.hpp b/fi/include/reverse_purge_hash_map_impl.hpp
index beccea4..0b05d89 100644
--- a/fi/include/reverse_purge_hash_map_impl.hpp
+++ b/fi/include/reverse_purge_hash_map_impl.hpp
@@ -39,15 +39,15 @@
lg_cur_size_(lg_cur_size),
lg_max_size_(lg_max_size),
num_active_(0),
-keys_(allocator_.allocate(1 << lg_cur_size)),
+keys_(allocator_.allocate(1ULL << lg_cur_size)),
values_(nullptr),
states_(nullptr)
{
AllocV av(allocator_);
- values_ = av.allocate(1 << lg_cur_size);
+ values_ = av.allocate(1ULL << lg_cur_size);
AllocU16 au16(allocator_);
- states_ = au16.allocate(1 << lg_cur_size);
- std::fill(states_, states_ + (1 << lg_cur_size), 0);
+ states_ = au16.allocate(1ULL << lg_cur_size);
+ std::fill(states_, states_ + (1ULL << lg_cur_size), static_cast<uint16_t>(0));
}
template<typename K, typename V, typename H, typename E, typename A>
@@ -56,14 +56,14 @@
lg_cur_size_(other.lg_cur_size_),
lg_max_size_(other.lg_max_size_),
num_active_(other.num_active_),
-keys_(allocator_.allocate(1 << lg_cur_size_)),
+keys_(allocator_.allocate(1ULL << lg_cur_size_)),
values_(nullptr),
states_(nullptr)
{
AllocV av(allocator_);
- values_ = av.allocate(1 << lg_cur_size_);
+ values_ = av.allocate(1ULL << lg_cur_size_);
AllocU16 au16(allocator_);
- states_ = au16.allocate(1 << lg_cur_size_);
+ states_ = au16.allocate(1ULL << lg_cur_size_);
const uint32_t size = 1 << lg_cur_size_;
if (num_active_ > 0) {
auto num = num_active_;
@@ -177,7 +177,7 @@
template<typename K, typename V, typename H, typename E, typename A>
uint32_t reverse_purge_hash_map<K, V, H, E, A>::get_capacity() const {
- return (1 << lg_cur_size_) * LOAD_FACTOR;
+ return static_cast<uint32_t>((1 << lg_cur_size_) * LOAD_FACTOR);
}
template<typename K, typename V, typename H, typename E, typename A>
@@ -246,7 +246,7 @@
// if none are found, the status is changed
states_[delete_index] = 0; // mark as empty
keys_[delete_index].~K();
- uint32_t drift = 1;
+ uint16_t drift = 1;
const uint32_t mask = (1 << lg_cur_size_) - 1;
uint32_t probe = (delete_index + drift) & mask; // map length must be a power of 2
// advance until we find a free location replacing locations as needed
@@ -322,7 +322,7 @@
values_ = av.allocate(new_size);
AllocU16 au16(allocator_);
states_ = au16.allocate(new_size);
- std::fill(states_, states_ + new_size, 0);
+ std::fill(states_, states_ + new_size, static_cast<uint16_t>(0));
num_active_ = 0;
lg_cur_size_ = lg_new_size;
for (uint32_t i = 0; i < old_size; i++) {
diff --git a/fi/test/reverse_purge_hash_map_test.cpp b/fi/test/reverse_purge_hash_map_test.cpp
index a1a9c27..fedda6b 100644
--- a/fi/test/reverse_purge_hash_map_test.cpp
+++ b/fi/test/reverse_purge_hash_map_test.cpp
@@ -39,7 +39,7 @@
TEST_CASE("reverse purge hash map: iterator", "[frequent_items_sketch]") {
reverse_purge_hash_map<int> map(3, 4, std::allocator<int>());
for (int i = 0; i < 11; i++) map.adjust_or_insert(i, 1); // this should fit with no purge
- int sum = 0;
+ uint64_t sum = 0;
for (auto it: map) sum += it.second;
REQUIRE(sum == 11);
}