Skip to content
Open
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
17 changes: 8 additions & 9 deletions fi/include/frequent_items_sketch_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,28 @@ map(
allocator
)
{
if (lg_start_map_size > lg_max_map_size) throw std::invalid_argument("starting size must not be greater than maximum size");
if (lg_start_map_size > lg_max_map_size) { throw std::invalid_argument("starting size must not be greater than maximum size"); }
}

template<typename T, typename W, typename H, typename E, typename A>
void frequent_items_sketch<T, W, H, E, A>::update(const T& item, W weight) {
check_weight(weight);
if (weight == 0) return;
if (weight == 0) { return; }
total_weight += weight;
offset += map.adjust_or_insert(item, weight);
}

template<typename T, typename W, typename H, typename E, typename A>
void frequent_items_sketch<T, W, H, E, A>::update(T&& item, W weight) {
check_weight(weight);
if (weight == 0) return;
if (weight == 0) { return; }
total_weight += weight;
offset += map.adjust_or_insert(std::move(item), weight);
}

template<typename T, typename W, typename H, typename E, typename A>
void frequent_items_sketch<T, W, H, E, A>::merge(const frequent_items_sketch& other) {
if (other.is_empty()) return;
if (other.is_empty()) { return; }
const W merged_total_weight = total_weight + other.get_total_weight(); // for correction at the end
for (auto it: other.map) {
update(it.first, it.second);
Expand All @@ -77,7 +77,7 @@ void frequent_items_sketch<T, W, H, E, A>::merge(const frequent_items_sketch& ot

template<typename T, typename W, typename H, typename E, typename A>
void frequent_items_sketch<T, W, H, E, A>::merge(frequent_items_sketch&& other) {
if (other.is_empty()) return;
if (other.is_empty()) { return; }
const W merged_total_weight = total_weight + other.get_total_weight(); // for correction at the end
for (auto it: other.map) {
update(std::move(it.first), it.second);
Expand Down Expand Up @@ -105,7 +105,7 @@ template<typename T, typename W, typename H, typename E, typename A>
W frequent_items_sketch<T, W, H, E, A>::get_estimate(const T& item) const {
// if item is tracked estimate = weight + offset, otherwise 0
const W weight = map.get(item);
if (weight > 0) return weight + offset;
if (weight > 0) { return weight + offset; }
return 0;
}

Expand Down Expand Up @@ -210,7 +210,7 @@ void frequent_items_sketch<T, W, H, E, A>::serialize(std::ostream& os, const Ser
template<typename T, typename W, typename H, typename E, typename A>
template<typename SerDe>
size_t frequent_items_sketch<T, W, H, E, A>::get_serialized_size_bytes(const SerDe& sd) const {
if (is_empty()) return PREAMBLE_LONGS_EMPTY * sizeof(uint64_t);
if (is_empty()) { return PREAMBLE_LONGS_EMPTY * sizeof(uint64_t); }
size_t size = PREAMBLE_LONGS_NONEMPTY * sizeof(uint64_t) + map.get_num_active() * sizeof(W);
for (auto it: map) size += sd.size_of_item(it.first);
return size;
Expand Down Expand Up @@ -328,8 +328,7 @@ frequent_items_sketch<T, W, H, E, A> frequent_items_sketch<T, W, H, E, A>::deser
sketch.total_weight = total_weight;
sketch.offset = offset;
}
if (!is.good())
throw std::runtime_error("error reading from std::istream");
if (!is.good()) { throw std::runtime_error("error reading from std::istream"); }
return sketch;
}

Expand Down
10 changes: 5 additions & 5 deletions fi/include/reverse_purge_hash_map_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ states_(nullptr)
if (other.states_[i] > 0) {
new (&keys_[i]) K(other.keys_[i]);
values_[i] = other.values_[i];
if (--num == 0) break;
if (--num == 0) { break; }
}
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ reverse_purge_hash_map<K, V, H, E, A>::~reverse_purge_hash_map() {
for (uint32_t i = 0; i < size; i++) {
if (is_active(i)) {
keys_[i].~K();
if (--num_active_ == 0) break;
if (--num_active_ == 0) { break; }
}
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ V reverse_purge_hash_map<K, V, H, E, A>::get(const K& key) const {
const uint32_t mask = (1 << lg_cur_size_) - 1;
uint32_t probe = fmix64(H()(key)) & mask;
while (is_active(probe)) {
if (E()(keys_[probe], key)) return values_[probe];
if (E()(keys_[probe], key)) { return values_[probe]; }
probe = (probe + 1) & mask;
}
return 0;
Expand Down Expand Up @@ -271,7 +271,7 @@ void reverse_purge_hash_map<K, V, H, E, A>::hash_delete(uint32_t delete_index) {
probe = (probe + 1) & mask;
drift++;
// only used for theoretical analysis
if (drift >= DRIFT_LIMIT) throw std::logic_error("drift: " + std::to_string(drift) + " >= DRIFT_LIMIT");
if (drift >= DRIFT_LIMIT) { throw std::logic_error("drift: " + std::to_string(drift) + " >= DRIFT_LIMIT"); }
}
}

Expand All @@ -289,7 +289,7 @@ uint32_t reverse_purge_hash_map<K, V, H, E, A>::internal_adjust_or_insert(const
index = (index + 1) & mask;
drift++;
// only used for theoretical analysis
if (drift >= DRIFT_LIMIT) throw std::logic_error("drift limit reached");
if (drift >= DRIFT_LIMIT) { throw std::logic_error("drift limit reached"); }
}
// adding the key and value to the table
if (num_active_ > get_capacity()) {
Expand Down