Skip to content

Commit 012ef0c

Browse files
committed
Replace pod_vector with owning_span in all data structures
- bit_vector, compact_vector, rank9, darray: rename pod_vector -> owning_span - cache_line_elias_fano, endpoints_sequence: refactor encode() to build into local std::vector then freeze via owning_span move-construction - Builder swap patterns converted to move-assignment - Update essentials submodule
1 parent 53375cb commit 012ef0c

7 files changed

Lines changed: 33 additions & 29 deletions

File tree

external/essentials

include/bit_vector.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct bit_vector //
4141

4242
void build(bit_vector& bv) {
4343
bv.m_num_bits = m_num_bits;
44-
bv.m_data.swap(m_data);
44+
bv.m_data = std::move(m_data);
4545
builder().swap(*this);
4646
}
4747

@@ -322,7 +322,7 @@ struct bit_vector //
322322
iterator begin() const { return get_iterator_at(0); }
323323

324324
uint64_t num_bits() const { return m_num_bits; }
325-
std::vector<uint64_t> const& data() const { return m_data; }
325+
essentials::owning_span<uint64_t> const& data() const { return m_data; }
326326

327327
uint64_t num_bytes() const { return sizeof(m_num_bits) + essentials::vec_bytes(m_data); }
328328

@@ -343,7 +343,7 @@ struct bit_vector //
343343

344344
protected:
345345
uint64_t m_num_bits;
346-
std::vector<uint64_t> m_data;
346+
essentials::owning_span<uint64_t> m_data;
347347

348348
template <typename Visitor, typename T>
349349
static void visit_impl(Visitor& visitor, T&& t) {

include/cache_line_elias_fano.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ struct cache_line_elias_fano {
5252

5353
const uint64_t num_blocks = (n + 44 - 1) / 44;
5454
const uint64_t num_bytes = num_blocks * 64;
55-
m_bits.resize(num_bytes);
56-
std::fill(m_bits.begin(), m_bits.end(), 0);
55+
std::vector<uint8_t> bits(num_bytes);
5756

58-
uint8_t* high = m_bits.data();
57+
uint8_t* high = bits.data();
5958
uint8_t* low = high + 4 // for lower bound high part of block
6059
+ 16; // for high bits
6160

@@ -100,6 +99,7 @@ struct cache_line_elias_fano {
10099
}
101100

102101
m_back = last;
102+
m_bits = essentials::owning_span<uint8_t>(std::move(bits));
103103
}
104104

105105
uint64_t access(uint64_t i) const {
@@ -149,7 +149,7 @@ struct cache_line_elias_fano {
149149
private:
150150
uint64_t m_back;
151151
uint64_t m_size;
152-
std::vector<uint8_t> m_bits;
152+
essentials::owning_span<uint8_t> m_bits;
153153

154154
template <typename Visitor, typename T>
155155
static void visit_impl(Visitor& visitor, T&& t) {

include/compact_vector.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ struct compact_vector //
195195
cv.m_size = m_size;
196196
cv.m_width = m_width;
197197
cv.m_mask = m_mask;
198-
cv.m_data.swap(m_data);
198+
cv.m_data = std::move(m_data);
199199
builder().swap(*this);
200200
}
201201

@@ -262,7 +262,7 @@ struct compact_vector //
262262
uint64_t back() const { return operator[](size() - 1); }
263263
uint64_t size() const { return m_size; }
264264
uint64_t width() const { return m_width; }
265-
std::vector<uint64_t> const& data() const { return m_data; }
265+
essentials::owning_span<uint64_t> const& data() const { return m_data; }
266266

267267
typedef enumerator<compact_vector> iterator;
268268
iterator get_iterator_at(uint64_t pos) const { return iterator(this, pos); }
@@ -293,7 +293,7 @@ struct compact_vector //
293293
uint64_t m_size;
294294
uint64_t m_width;
295295
uint64_t m_mask;
296-
std::vector<uint64_t> m_data;
296+
essentials::owning_span<uint64_t> m_data;
297297

298298
template <typename Visitor, typename T>
299299
static void visit_impl(Visitor& visitor, T&& t) {

include/darray.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct darray {
8181
darray() : m_positions(0) {}
8282

8383
void build(bit_vector const& B) {
84-
std::vector<uint64_t> const& data = B.data();
84+
auto const& data = B.data();
8585
std::vector<uint64_t> cur_block_positions;
8686
std::vector<int64_t> block_inventory;
8787
std::vector<uint16_t> subblock_inventory;
@@ -113,9 +113,9 @@ struct darray {
113113
flush_cur_block(cur_block_positions, block_inventory, subblock_inventory,
114114
overflow_positions);
115115
}
116-
m_block_inventory.swap(block_inventory);
117-
m_subblock_inventory.swap(subblock_inventory);
118-
m_overflow_positions.swap(overflow_positions);
116+
m_block_inventory = std::move(block_inventory);
117+
m_subblock_inventory = std::move(subblock_inventory);
118+
m_overflow_positions = std::move(overflow_positions);
119119

120120
// std::cout << "I: ";
121121
// for (auto x : m_block_inventory) { std::cout << x << ' '; }
@@ -174,7 +174,7 @@ struct darray {
174174
uint64_t reminder = i & (subblock_size - 1);
175175
if (!reminder) return start_pos;
176176

177-
std::vector<uint64_t> const& data = B.data();
177+
auto const& data = B.data();
178178
uint64_t word_idx = start_pos >> 6;
179179
uint64_t word_shift = start_pos & 63;
180180
uint64_t word = WordGetter()(data, word_idx) & (uint64_t(-1) << word_shift);
@@ -214,9 +214,9 @@ struct darray {
214214

215215
protected:
216216
uint64_t m_positions;
217-
std::vector<int64_t> m_block_inventory;
218-
std::vector<uint16_t> m_subblock_inventory;
219-
std::vector<uint64_t> m_overflow_positions;
217+
essentials::owning_span<int64_t> m_block_inventory;
218+
essentials::owning_span<uint16_t> m_subblock_inventory;
219+
essentials::owning_span<uint64_t> m_overflow_positions;
220220

221221
template <typename Visitor, typename T>
222222
static void visit_impl(Visitor& visitor, T&& t) {
@@ -262,11 +262,13 @@ struct darray {
262262
namespace util {
263263

264264
struct identity_getter {
265-
uint64_t operator()(std::vector<uint64_t> const& data, uint64_t i) const { return data[i]; }
265+
template <typename Vec>
266+
uint64_t operator()(Vec const& data, uint64_t i) const { return data[i]; }
266267
};
267268

268269
struct negating_getter {
269-
uint64_t operator()(std::vector<uint64_t> const& data, uint64_t i) const { return ~data[i]; }
270+
template <typename Vec>
271+
uint64_t operator()(Vec const& data, uint64_t i) const { return ~data[i]; }
270272
};
271273

272274
} // namespace util

include/endpoints_sequence.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ struct endpoints_sequence {
5050

5151
const uint64_t num_high_bits = n + (universe >> 8) + 1;
5252
bit_vector::builder bvb_high_bits(num_high_bits);
53-
m_low_bits.reserve(n);
53+
std::vector<uint8_t> low_bits;
54+
low_bits.reserve(n);
5455

5556
compact_vector::builder cvb_hints_0((universe + 256 - 1) / 256, // ceil(U/2^8)
5657
util::ceil_log2_uint64(num_high_bits));
@@ -59,7 +60,7 @@ struct endpoints_sequence {
5960
uint64_t prev_pos = 0;
6061
for (uint64_t i = 0; i != n; ++i, ++begin) {
6162
auto v = *begin;
62-
m_low_bits.push_back(v & 255);
63+
low_bits.push_back(v & 255);
6364
uint64_t high_part = v >> 8;
6465
uint64_t pos = high_part + i;
6566
bvb_high_bits.set(pos, 1);
@@ -72,6 +73,7 @@ struct endpoints_sequence {
7273
bvb_high_bits.build(m_high_bits);
7374
m_high_bits_d1.build(m_high_bits);
7475
cvb_hints_0.build(m_hints_0);
76+
m_low_bits = essentials::owning_span<uint8_t>(std::move(low_bits));
7577
}
7678

7779
struct iterator {
@@ -141,7 +143,7 @@ struct endpoints_sequence {
141143
uint64_t m_pos;
142144
uint64_t m_val;
143145
bit_vector::iterator m_high_bits_it;
144-
std::vector<uint8_t>::const_iterator m_low_bits_it;
146+
const uint8_t* m_low_bits_it;
145147

146148
void read_next_value() {
147149
assert(m_pos < m_ptr->size());
@@ -226,7 +228,7 @@ struct endpoints_sequence {
226228
bit_vector m_high_bits;
227229
DArray1 m_high_bits_d1;
228230
compact_vector m_hints_0;
229-
std::vector<uint8_t> m_low_bits;
231+
essentials::owning_span<uint8_t> m_low_bits;
230232

231233
template <typename Visitor, typename T>
232234
static void visit_impl(Visitor& visitor, T&& t) {

include/rank9.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct rank9 {
4646
rank9() {}
4747

4848
void build(bit_vector const& B) {
49-
std::vector<uint64_t> const& data = B.data();
49+
auto const& data = B.data();
5050
std::vector<uint64_t> block_rank_pairs;
5151
uint64_t next_rank = 0;
5252
uint64_t cur_subrank = 0;
@@ -81,7 +81,7 @@ struct rank9 {
8181
block_rank_pairs.push_back(0);
8282
}
8383

84-
m_block_rank_pairs.swap(block_rank_pairs);
84+
m_block_rank_pairs = std::move(block_rank_pairs);
8585
}
8686

8787
inline uint64_t num_ones() const { return *(m_block_rank_pairs.end() - 2); }
@@ -96,7 +96,7 @@ struct rank9 {
9696
uint64_t r = sub_block_rank(sub_block);
9797
uint64_t sub_left = i % 64;
9898
if (sub_left) {
99-
std::vector<uint64_t> const& data = B.data();
99+
auto const& data = B.data();
100100
r += util::popcount(data[sub_block] << (64 - sub_left));
101101
}
102102
return r;
@@ -146,7 +146,7 @@ struct rank9 {
146146
}
147147

148148
static const uint64_t block_size = 8; // in 64bit words
149-
std::vector<uint64_t> m_block_rank_pairs;
149+
essentials::owning_span<uint64_t> m_block_rank_pairs;
150150
};
151151

152152
} // namespace bits

0 commit comments

Comments
 (0)