Skip to content

Commit eb2ed84

Browse files
authored
Merge pull request #488 from SYaoJun/223_hll
style(hll): Add braces to single-line if statements for consistency
2 parents a76a5dc + a46fc2f commit eb2ed84

7 files changed

Lines changed: 26 additions & 24 deletions

hll/include/CouponHashSet-internal.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ CouponHashSet<A>* CouponHashSet<A>::newSet(std::istream& is, const A& allocator)
176176
read(is, sketch->coupons_.data(), sketch->coupons_.size() * sizeof(uint32_t));
177177
}
178178

179-
if (!is.good())
180-
throw std::runtime_error("error reading from std::istream");
179+
if (!is.good()) { throw std::runtime_error("error reading from std::istream"); }
181180

182181
return ptr.release();
183182
}

hll/include/CouponList-internal.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ CouponList<A>* CouponList<A>::newList(std::istream& is, const A& allocator) {
162162
read(is, sketch->coupons_.data(), numToRead * sizeof(uint32_t));
163163
}
164164

165-
if (!is.good())
166-
throw std::runtime_error("error reading from std::istream");
165+
if (!is.good()) { throw std::runtime_error("error reading from std::istream"); }
167166

168167
return ptr.release();
169168
}

hll/include/CubicInterpolation-internal.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ static int recursiveFindStraddle(const double xArr[], const int l, const int r,
165165
throw std::logic_error("target value invariant violated in search");
166166
}
167167

168-
if (l+1 == r) return (l);
168+
if (l+1 == r) { return (l); }
169169
m = l + ((r-l)/2);
170-
if (xArr[m] <= x) return (recursiveFindStraddle<A>(xArr, m, r, x));
171-
else return (recursiveFindStraddle<A>(xArr, l, m, x));
170+
if (xArr[m] <= x) { return (recursiveFindStraddle<A>(xArr, m, r, x)); }
171+
else { return (recursiveFindStraddle<A>(xArr, l, m, x)); }
172172
}
173173

174174

hll/include/Hll4Array-internal.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ uint8_t Hll4Array<A>::getSlot(uint32_t slotNo) const {
131131

132132
template<typename A>
133133
uint8_t Hll4Array<A>::adjustRawValue(uint32_t slot, uint8_t value) const {
134-
if (value != hll_constants::AUX_TOKEN) return value + this->curMin_;
134+
if (value != hll_constants::AUX_TOKEN) { return value + this->curMin_; }
135135
return auxHashMap_->mustFindValueFor(slot);
136136
}
137137

hll/include/HllArray-internal.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,16 @@ HllArray<A>* HllArray<A>::newHll(const void* bytes, size_t len, const A& allocat
142142
HllArray<A>* sketch = HllSketchImplFactory<A>::newHll(lgK, tgtHllType, startFullSizeFlag, allocator);
143143
sketch->putCurMin(curMin);
144144
sketch->putOutOfOrderFlag(oooFlag);
145-
if (!oooFlag) sketch->putHipAccum(hip);
145+
if (!oooFlag) { sketch->putHipAccum(hip); }
146146
sketch->putKxQ0(kxq0);
147147
sketch->putKxQ1(kxq1);
148148
sketch->putNumAtCurMin(numAtCurMin);
149149

150150
std::memcpy(sketch->hllByteArr_.data(), data + hll_constants::HLL_BYTE_ARR_START, arrayBytes);
151151

152-
if (auxHashMap != nullptr)
152+
if (auxHashMap != nullptr) {
153153
((Hll4Array<A>*)sketch)->putAuxHashMap(auxHashMap);
154+
}
154155

155156
aux_ptr.release();
156157
return sketch;
@@ -193,7 +194,7 @@ HllArray<A>* HllArray<A>::newHll(std::istream& is, const A& allocator) {
193194
const auto hip = read<double>(is);
194195
const auto kxq0 = read<double>(is);
195196
const auto kxq1 = read<double>(is);
196-
if (!oooFlag) sketch->putHipAccum(hip);
197+
if (!oooFlag) { sketch->putHipAccum(hip); }
197198
sketch->putKxQ0(kxq0);
198199
sketch->putKxQ1(kxq1);
199200

@@ -209,8 +210,7 @@ HllArray<A>* HllArray<A>::newHll(std::istream& is, const A& allocator) {
209210
((Hll4Array<A>*)sketch)->putAuxHashMap(auxHashMap);
210211
}
211212

212-
if (!is.good())
213-
throw std::runtime_error("error reading from std::istream");
213+
if (!is.good()) { throw std::runtime_error("error reading from std::istream"); }
214214

215215
return sketch_ptr.release();
216216
}
@@ -545,7 +545,7 @@ template<typename A>
545545
void HllArray<A>::hipAndKxQIncrementalUpdate(uint8_t oldValue, uint8_t newValue) {
546546
const uint32_t configK = 1 << this->getLgConfigK();
547547
// update hip BEFORE updating kxq
548-
if (!oooFlag_) hipAccum_ += configK / (kxq0_ + kxq1_);
548+
if (!oooFlag_) { hipAccum_ += configK / (kxq0_ + kxq1_); }
549549
// update kxq0 and kxq1; subtract first, then add
550550
if (oldValue < 32) { kxq0_ -= INVERSE_POWERS_OF_2[oldValue]; }
551551
else { kxq1_ -= INVERSE_POWERS_OF_2[oldValue]; }
@@ -648,7 +648,7 @@ array_(array), array_size_(array_size), index_(index), hll_type_(hll_type), exce
648648
{
649649
while (index_ < array_size_) {
650650
value_ = get_value(array_, index_, hll_type_, exceptions_, offset_);
651-
if (all_ || value_ != hll_constants::EMPTY) break;
651+
if (all_ || value_ != hll_constants::EMPTY) { break; }
652652
++index_;
653653
}
654654
}
@@ -657,7 +657,7 @@ template<typename A>
657657
typename HllArray<A>::const_iterator& HllArray<A>::const_iterator::operator++() {
658658
while (++index_ < array_size_) {
659659
value_ = get_value(array_, index_, hll_type_, exceptions_, offset_);
660-
if (all_ || value_ != hll_constants::EMPTY) break;
660+
if (all_ || value_ != hll_constants::EMPTY) { break; }
661661
}
662662
return *this;
663663
}

hll/include/HllUnion-internal.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ hll_sketch_alloc<A> hll_union_alloc<A>::get_result(target_hll_type target_type)
4444

4545
template<typename A>
4646
void hll_union_alloc<A>::update(const hll_sketch_alloc<A>& sketch) {
47-
if (sketch.is_empty()) return;
47+
if (sketch.is_empty()) { return; }
4848
union_impl(sketch, lg_max_k_);
4949
}
5050

5151
template<typename A>
5252
void hll_union_alloc<A>::update(hll_sketch_alloc<A>&& sketch) {
53-
if (sketch.is_empty()) return;
53+
if (sketch.is_empty()) { return; }
5454
if (gadget_.is_empty() && sketch.get_target_type() == HLL_8 && sketch.get_lg_config_k() <= lg_max_k_) {
5555
if (sketch.get_current_mode() == HLL || sketch.get_lg_config_k() == lg_max_k_) {
5656
gadget_ = std::move(sketch);
@@ -131,29 +131,33 @@ void hll_union_alloc<A>::coupon_update(uint32_t coupon) {
131131

132132
template<typename A>
133133
double hll_union_alloc<A>::get_estimate() const {
134-
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL)
134+
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL) {
135135
static_cast<HllArray<A>*>(gadget_.sketch_impl)->check_rebuild_kxq_cur_min();
136+
}
136137
return gadget_.get_estimate();
137138
}
138139

139140
template<typename A>
140141
double hll_union_alloc<A>::get_composite_estimate() const {
141-
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL)
142+
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL) {
142143
static_cast<HllArray<A>*>(gadget_.sketch_impl)->check_rebuild_kxq_cur_min();
144+
}
143145
return gadget_.get_composite_estimate();
144146
}
145147

146148
template<typename A>
147149
double hll_union_alloc<A>::get_lower_bound(uint8_t num_std_dev) const {
148-
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL)
150+
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL) {
149151
static_cast<HllArray<A>*>(gadget_.sketch_impl)->check_rebuild_kxq_cur_min();
152+
}
150153
return gadget_.get_lower_bound(num_std_dev);
151154
}
152155

153156
template<typename A>
154157
double hll_union_alloc<A>::get_upper_bound(uint8_t num_std_dev) const {
155-
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL)
158+
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL) {
156159
static_cast<HllArray<A>*>(gadget_.sketch_impl)->check_rebuild_kxq_cur_min();
160+
}
157161
return gadget_.get_upper_bound(num_std_dev);
158162
}
159163

hll/include/coupon_iterator-internal.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ template<typename A>
2828
coupon_iterator<A>::coupon_iterator(const uint32_t* array, size_t array_size, size_t index, bool all):
2929
array_(array), array_size_(array_size), index_(index), all_(all) {
3030
while (index_ < array_size_) {
31-
if (all_ || array_[index_] != hll_constants::EMPTY) break;
31+
if (all_ || array_[index_] != hll_constants::EMPTY) { break; }
3232
++index_;
3333
}
3434
}
3535

3636
template<typename A>
3737
coupon_iterator<A>& coupon_iterator<A>::operator++() {
3838
while (++index_ < array_size_) {
39-
if (all_ || array_[index_] != hll_constants::EMPTY) break;
39+
if (all_ || array_[index_] != hll_constants::EMPTY) { break; }
4040
}
4141
return *this;
4242
}

0 commit comments

Comments
 (0)