Skip to content

Commit a76a5dc

Browse files
authored
Merge pull request #490 from SYaoJun/223_fi
style(fi): Add braces to single-line if statements for consistency
2 parents 69c3773 + b444a2a commit a76a5dc

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

fi/include/frequent_items_sketch_impl.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,28 @@ map(
4545
allocator
4646
)
4747
{
48-
if (lg_start_map_size > lg_max_map_size) throw std::invalid_argument("starting size must not be greater than maximum size");
48+
if (lg_start_map_size > lg_max_map_size) { throw std::invalid_argument("starting size must not be greater than maximum size"); }
4949
}
5050

5151
template<typename T, typename W, typename H, typename E, typename A>
5252
void frequent_items_sketch<T, W, H, E, A>::update(const T& item, W weight) {
5353
check_weight(weight);
54-
if (weight == 0) return;
54+
if (weight == 0) { return; }
5555
total_weight += weight;
5656
offset += map.adjust_or_insert(item, weight);
5757
}
5858

5959
template<typename T, typename W, typename H, typename E, typename A>
6060
void frequent_items_sketch<T, W, H, E, A>::update(T&& item, W weight) {
6161
check_weight(weight);
62-
if (weight == 0) return;
62+
if (weight == 0) { return; }
6363
total_weight += weight;
6464
offset += map.adjust_or_insert(std::move(item), weight);
6565
}
6666

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

7878
template<typename T, typename W, typename H, typename E, typename A>
7979
void frequent_items_sketch<T, W, H, E, A>::merge(frequent_items_sketch&& other) {
80-
if (other.is_empty()) return;
80+
if (other.is_empty()) { return; }
8181
const W merged_total_weight = total_weight + other.get_total_weight(); // for correction at the end
8282
for (auto it: other.map) {
8383
update(std::move(it.first), it.second);
@@ -105,7 +105,7 @@ template<typename T, typename W, typename H, typename E, typename A>
105105
W frequent_items_sketch<T, W, H, E, A>::get_estimate(const T& item) const {
106106
// if item is tracked estimate = weight + offset, otherwise 0
107107
const W weight = map.get(item);
108-
if (weight > 0) return weight + offset;
108+
if (weight > 0) { return weight + offset; }
109109
return 0;
110110
}
111111

@@ -210,7 +210,7 @@ void frequent_items_sketch<T, W, H, E, A>::serialize(std::ostream& os, const Ser
210210
template<typename T, typename W, typename H, typename E, typename A>
211211
template<typename SerDe>
212212
size_t frequent_items_sketch<T, W, H, E, A>::get_serialized_size_bytes(const SerDe& sd) const {
213-
if (is_empty()) return PREAMBLE_LONGS_EMPTY * sizeof(uint64_t);
213+
if (is_empty()) { return PREAMBLE_LONGS_EMPTY * sizeof(uint64_t); }
214214
size_t size = PREAMBLE_LONGS_NONEMPTY * sizeof(uint64_t) + map.get_num_active() * sizeof(W);
215215
for (auto it: map) size += sd.size_of_item(it.first);
216216
return size;
@@ -328,8 +328,7 @@ frequent_items_sketch<T, W, H, E, A> frequent_items_sketch<T, W, H, E, A>::deser
328328
sketch.total_weight = total_weight;
329329
sketch.offset = offset;
330330
}
331-
if (!is.good())
332-
throw std::runtime_error("error reading from std::istream");
331+
if (!is.good()) { throw std::runtime_error("error reading from std::istream"); }
333332
return sketch;
334333
}
335334

fi/include/reverse_purge_hash_map_impl.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ states_(nullptr)
7474
if (other.states_[i] > 0) {
7575
new (&keys_[i]) K(other.keys_[i]);
7676
values_[i] = other.values_[i];
77-
if (--num == 0) break;
77+
if (--num == 0) { break; }
7878
}
7979
}
8080
}
@@ -105,7 +105,7 @@ reverse_purge_hash_map<K, V, H, E, A>::~reverse_purge_hash_map() {
105105
for (uint32_t i = 0; i < size; i++) {
106106
if (is_active(i)) {
107107
keys_[i].~K();
108-
if (--num_active_ == 0) break;
108+
if (--num_active_ == 0) { break; }
109109
}
110110
}
111111
}
@@ -166,7 +166,7 @@ V reverse_purge_hash_map<K, V, H, E, A>::get(const K& key) const {
166166
const uint32_t mask = (1 << lg_cur_size_) - 1;
167167
uint32_t probe = fmix64(H()(key)) & mask;
168168
while (is_active(probe)) {
169-
if (E()(keys_[probe], key)) return values_[probe];
169+
if (E()(keys_[probe], key)) { return values_[probe]; }
170170
probe = (probe + 1) & mask;
171171
}
172172
return 0;
@@ -271,7 +271,7 @@ void reverse_purge_hash_map<K, V, H, E, A>::hash_delete(uint32_t delete_index) {
271271
probe = (probe + 1) & mask;
272272
drift++;
273273
// only used for theoretical analysis
274-
if (drift >= DRIFT_LIMIT) throw std::logic_error("drift: " + std::to_string(drift) + " >= DRIFT_LIMIT");
274+
if (drift >= DRIFT_LIMIT) { throw std::logic_error("drift: " + std::to_string(drift) + " >= DRIFT_LIMIT"); }
275275
}
276276
}
277277

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

0 commit comments

Comments
 (0)