Skip to content

Commit 16a9c33

Browse files
authored
cppcoreguidelines-pro-type-member-init (#349)
1 parent 7449d78 commit 16a9c33

27 files changed

+100
-107
lines changed

.clang-tidy

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ Checks: |
1212
readability-else-after-return,
1313
readability-implicit-bool-conversion,
1414
readability-uppercase-literal-suffix,
15+
readability-container-size-empty,
1516
modernize-loop-convert,
1617
modernize-use-equals-default,
1718
modernize-use-using,
1819
cppcoreguidelines-special-member-functions,
20+
cppcoreguidelines-pro-type-member-init,
1921
-hicpp-signed-bitwise,
2022
-modernize-use-trailing-return-type,
2123
-fuchsia-overloaded-operator,
2224
-fuchsia-default-arguments-calls,
2325
-fuchsia-trailing-return,
24-
-llvm-header-guard
26+
-llvm-header-guard,
27+
-google-runtime-references

include/pisa/bit_vector.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class bit_vector {
352352
mapper::mappable_vector<uint64_t> const& data() const { return m_bits; }
353353

354354
struct enumerator {
355-
enumerator() : m_bv(0), m_pos(uint64_t(-1)) {}
355+
enumerator() = default;
356356

357357
enumerator(bit_vector const& bv, size_t pos) : m_bv(&bv), m_pos(pos), m_buf(0), m_avail(0)
358358
{
@@ -416,10 +416,10 @@ class bit_vector {
416416
m_avail = 64;
417417
}
418418

419-
bit_vector const* m_bv;
420-
size_t m_pos;
421-
uint64_t m_buf;
422-
size_t m_avail;
419+
bit_vector const* m_bv{0};
420+
std::uint64_t m_pos{std::numeric_limits<std::uint64_t>::max()};
421+
std::uint64_t m_buf{0};
422+
std::uint64_t m_avail{0};
423423
};
424424

425425
struct unary_enumerator {
@@ -510,7 +510,7 @@ class bit_vector {
510510
};
511511

512512
protected:
513-
size_t m_size;
513+
size_t m_size{0};
514514
mapper::mappable_vector<uint64_t> m_bits;
515515
};
516516

include/pisa/block_freq_index.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace pisa {
1111
template <typename BlockCodec, bool Profile = false>
1212
class block_freq_index {
1313
public:
14-
block_freq_index() : m_size(0) {}
14+
block_freq_index() = default;
1515

1616
class builder {
1717
public:
@@ -126,8 +126,8 @@ class block_freq_index {
126126

127127
private:
128128
global_parameters m_params;
129-
size_t m_size;
130-
size_t m_num_docs;
129+
size_t m_size{0};
130+
size_t m_num_docs{0};
131131
bit_vector m_endpoints;
132132
mapper::mappable_vector<uint8_t> m_lists;
133133
};

include/pisa/block_posting_list.hpp

+10-15
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,8 @@ struct block_posting_list {
7979

8080
class document_enumerator {
8181
public:
82-
document_enumerator(
83-
uint8_t const* data,
84-
uint64_t universe,
85-
size_t term_id = 0)
86-
: m_n(0) // just to silence warnings
87-
,
88-
m_base(TightVariableByte::decode(data, &m_n, 1)),
82+
document_enumerator(uint8_t const* data, uint64_t universe, size_t term_id = 0)
83+
: m_base(TightVariableByte::decode(data, &m_n, 1)),
8984
m_blocks(ceil_div(m_n, BlockCodec::block_size)),
9085
m_block_maxs(m_base),
9186
m_block_endpoints(m_block_maxs + 4 * m_blocks),
@@ -300,22 +295,22 @@ struct block_posting_list {
300295
}
301296
}
302297

303-
uint32_t m_n;
298+
uint32_t m_n{0};
304299
uint8_t const* m_base;
305300
uint32_t m_blocks;
306301
uint8_t const* m_block_maxs;
307302
uint8_t const* m_block_endpoints;
308303
uint8_t const* m_blocks_data;
309304
uint64_t m_universe;
310305

311-
uint32_t m_cur_block;
312-
uint32_t m_pos_in_block;
313-
uint32_t m_cur_block_max;
314-
uint32_t m_cur_block_size;
315-
uint32_t m_cur_docid;
306+
uint32_t m_cur_block{0};
307+
uint32_t m_pos_in_block{0};
308+
uint32_t m_cur_block_max{0};
309+
uint32_t m_cur_block_size{0};
310+
uint32_t m_cur_docid{0};
316311

317-
uint8_t const* m_freqs_block_data;
318-
bool m_freqs_decoded;
312+
uint8_t const* m_freqs_block_data{nullptr};
313+
bool m_freqs_decoded{false};
319314

320315
std::vector<uint32_t> m_docs_buf;
321316
std::vector<uint32_t> m_freqs_buf;

include/pisa/codec/block_codecs.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ struct interpolative_block {
170170

171171
struct optpfor_block {
172172
struct codec_type: FastPForLib::OPTPFor<4, FastPForLib::Simple16<false>> {
173-
uint8_t const* force_b;
173+
uint8_t const* force_b{nullptr};
174174

175175
uint32_t findBestB(const uint32_t* in, uint32_t len)
176176
{

include/pisa/codec/compact_elias_fano.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,11 @@ struct compact_elias_fano {
386386

387387
inline uint64_t pointer1(uint64_t i) const { return pointer(m_of.pointers1_offset, i); }
388388

389-
bit_vector const* m_bv;
390-
offsets m_of;
389+
bit_vector const* m_bv{nullptr};
390+
offsets m_of{};
391391

392-
uint64_t m_position;
393-
uint64_t m_value;
392+
uint64_t m_position{0};
393+
uint64_t m_value{0};
394394
bit_vector::unary_enumerator m_high_enumerator;
395395
};
396396
};

include/pisa/configuration.hpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,21 @@ class configuration {
1717
return instance;
1818
}
1919

20-
size_t quantization_bits;
21-
bool heuristic_greedy;
20+
size_t quantization_bits{8};
21+
bool heuristic_greedy{false};
2222

2323
private:
2424
configuration()
2525
{
26-
fillvar("PISA_HEURISTIC_GREEDY", heuristic_greedy, false);
27-
fillvar("PISA_QUANTIZTION_BITS", quantization_bits, 8);
26+
fillvar("PISA_HEURISTIC_GREEDY", heuristic_greedy);
27+
fillvar("PISA_QUANTIZTION_BITS", quantization_bits);
2828
}
2929

30-
template <typename T, typename T2>
31-
void fillvar(const char* envvar, T& var, T2 def)
30+
template <typename T>
31+
void fillvar(const char* envvar, T& var)
3232
{
3333
const char* val = std::getenv(envvar);
34-
if (!val || !strlen(val)) {
35-
var = def;
36-
} else {
34+
if (val && strlen(val)) {
3735
var = boost::lexical_cast<T>(val);
3836
}
3937
}

include/pisa/cursor/block_max_scored_cursor.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ struct block_max_scored_cursor {
1212
using enum_type = typename Index::document_enumerator;
1313
using wdata_enum = typename WandType::wand_data_enumerator;
1414

15+
block_max_scored_cursor() = delete;
16+
1517
enum_type docs_enum;
1618
wdata_enum w;
1719
float q_weight;
@@ -40,4 +42,4 @@ template <typename Index, typename WandType, typename Scorer>
4042
return cursors;
4143
}
4244

43-
} // namespace pisa
45+
} // namespace pisa

include/pisa/cursor/max_scored_cursor.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace pisa {
1010
template <typename Index>
1111
struct max_scored_cursor {
1212
using enum_type = typename Index::document_enumerator;
13+
max_scored_cursor() = delete;
1314
enum_type docs_enum;
1415
float q_weight;
1516
term_scorer_t scorer;

include/pisa/cursor/scored_cursor.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace pisa {
1010
template <typename Index>
1111
struct scored_cursor {
1212
using enum_type = typename Index::document_enumerator;
13+
scored_cursor() = delete;
1314
enum_type docs_enum;
1415
float q_weight;
1516
term_scorer_t scorer;

include/pisa/dec_time_prediction.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace pisa { namespace time_prediction {
5151

5252
class feature_vector {
5353
public:
54-
feature_vector() { std::fill(m_features.begin(), m_features.end(), 0); }
54+
feature_vector() = default;
5555

5656
float& operator[](feature_type f) { return m_features[(size_t)f]; }
5757
float const& operator[](feature_type f) const { return m_features[(size_t)f]; }
@@ -66,12 +66,12 @@ namespace pisa { namespace time_prediction {
6666
}
6767

6868
protected:
69-
std::array<float, num_features> m_features;
69+
std::array<float, num_features> m_features{};
7070
};
7171

7272
class predictor: public feature_vector {
7373
public:
74-
predictor() : m_bias(0) {}
74+
predictor() = default;
7575

7676
explicit predictor(std::vector<std::pair<std::string, float>> const& values)
7777
{
@@ -98,7 +98,7 @@ namespace pisa { namespace time_prediction {
9898
}
9999

100100
protected:
101-
float m_bias;
101+
float m_bias{0.0};
102102
};
103103

104104
inline void values_statistics(std::vector<uint32_t> values, feature_vector& f)

include/pisa/freq_index.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ class freq_index {
119119
reset();
120120
}
121121

122-
uint64_t m_cur_pos;
123-
uint64_t m_cur_docid;
122+
uint64_t m_cur_pos{0};
123+
uint64_t m_cur_docid{0};
124124
typename DocsSequence::enumerator m_docs_enum;
125125
typename FreqsSequence::enumerator m_freqs_enum;
126126
};

include/pisa/invert.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ namespace invert {
320320
spdlog::error(msg);
321321
throw std::runtime_error(msg);
322322
}
323-
if (dlist.size() == 0U) {
323+
if (dlist.empty()) {
324324
auto msg = fmt::format("Posting list must be non-empty (term {})", term_id);
325325
spdlog::error(msg);
326326
throw std::runtime_error(msg);

include/pisa/mappable/mapper.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ namespace pisa { namespace mapper {
275275
{
276276
detail::sizeof_visitor sizer(true);
277277
sizer(val, friendly_name);
278-
assert(sizer.size_tree()->children.size());
278+
assert(not sizer.size_tree()->children.empty());
279279
return sizer.size_tree()->children[0];
280280
}
281281

include/pisa/score_opt_partition.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct score_opt_partition {
7777
float v = std::get<1>(*end_it);
7878
sum += v;
7979

80-
while (max_queue.size() > 0 && max_queue.back() < std::get<1>(*end_it)) {
80+
while (not max_queue.empty() && max_queue.back() < std::get<1>(*end_it)) {
8181
max_queue.pop_back();
8282
}
8383

include/pisa/sequence/indexed_sequence.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct indexed_sequence {
138138
}
139139

140140
private:
141-
index_type m_type;
141+
index_type m_type{};
142142
boost::variant<compact_elias_fano::enumerator, compact_ranked_bitvector::enumerator, all_ones_sequence::enumerator>
143143
m_enumerator;
144144
};

include/pisa/sequence/partitioned_sequence.hpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct partitioned_sequence {
7979
}
8080

8181
uint64_t upper_bound = value;
82-
assert(cur_partition.size() > 0);
82+
assert(not cur_partition.empty());
8383
base_sequence_type::write(
8484
bv_sequences,
8585
cur_partition.begin(),
@@ -305,21 +305,21 @@ struct partitioned_sequence {
305305
}
306306

307307
global_parameters m_params;
308-
uint64_t m_partitions;
309-
uint64_t m_endpoints_offset;
310-
uint64_t m_endpoint_bits;
311-
uint64_t m_sequences_offset;
312-
uint64_t m_size;
313-
uint64_t m_universe;
314-
315-
uint64_t m_position;
316-
uint64_t m_cur_partition;
317-
uint64_t m_cur_begin;
318-
uint64_t m_cur_end;
319-
uint64_t m_cur_base;
320-
uint64_t m_cur_upper_bound;
321-
322-
bit_vector const* m_bv;
308+
uint64_t m_partitions{0};
309+
uint64_t m_endpoints_offset{0};
310+
uint64_t m_endpoint_bits{0};
311+
uint64_t m_sequences_offset{0};
312+
uint64_t m_size{0};
313+
uint64_t m_universe{0};
314+
315+
uint64_t m_position{0};
316+
uint64_t m_cur_partition{0};
317+
uint64_t m_cur_begin{0};
318+
uint64_t m_cur_end{0};
319+
uint64_t m_cur_base{0};
320+
uint64_t m_cur_upper_bound{0};
321+
322+
bit_vector const* m_bv{nullptr};
323323
compact_elias_fano::enumerator m_sizes;
324324
compact_elias_fano::enumerator m_upper_bounds;
325325
base_sequence_enumerator m_partition_enum;

include/pisa/sequence/strict_sequence.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct strict_sequence {
146146
}
147147

148148
private:
149-
index_type m_type;
149+
index_type m_type{};
150150
boost::variant<strict_elias_fano::enumerator, compact_ranked_bitvector::enumerator, all_ones_sequence::enumerator>
151151
m_enumerator;
152152
};

include/pisa/sequence/uniform_partitioned_sequence.hpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct uniform_partitioned_sequence {
7373
assert((p == partitions - 1) || cur_partition.size() == partition_size);
7474

7575
uint64_t upper_bound = value;
76-
assert(cur_partition.size() > 0);
76+
assert(not cur_partition.empty());
7777
base_sequence_type::write(
7878
bv_sequences,
7979
cur_partition.begin(),
@@ -284,21 +284,21 @@ struct uniform_partitioned_sequence {
284284
}
285285

286286
global_parameters m_params;
287-
uint64_t m_partitions;
288-
uint64_t m_endpoints_offset;
289-
uint64_t m_endpoint_bits;
290-
uint64_t m_sequences_offset;
291-
uint64_t m_size;
292-
uint64_t m_universe;
293-
294-
uint64_t m_position;
295-
uint64_t m_cur_partition;
296-
uint64_t m_cur_begin;
297-
uint64_t m_cur_end;
298-
uint64_t m_cur_base;
299-
uint64_t m_cur_upper_bound;
300-
301-
bit_vector const* m_bv;
287+
uint64_t m_partitions{0};
288+
uint64_t m_endpoints_offset{0};
289+
uint64_t m_endpoint_bits{0};
290+
uint64_t m_sequences_offset{0};
291+
uint64_t m_size{0};
292+
uint64_t m_universe{0};
293+
294+
uint64_t m_position{0};
295+
uint64_t m_cur_partition{0};
296+
uint64_t m_cur_begin{0};
297+
uint64_t m_cur_end{0};
298+
uint64_t m_cur_base{0};
299+
uint64_t m_cur_upper_bound{0};
300+
301+
bit_vector const* m_bv{nullptr};
302302
compact_elias_fano::enumerator m_upper_bounds;
303303
base_sequence_enumerator m_partition_enum;
304304
};

include/pisa/sequence_collection.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class sequence_collection {
101101

102102
private:
103103
global_parameters m_params;
104-
size_t m_size;
104+
size_t m_size{0};
105105
bitvector_collection m_sequences;
106106
};
107107
} // namespace pisa

0 commit comments

Comments
 (0)