26 namespace profile_detail {
34 if constexpr (P::fixed_width)
36 error_detail::raise<std::invalid_argument>(
"native writer width disagrees with fixed policy");
42 :
data_(std::exchange(other.data_, {})),
offsets_(std::move(other.offsets_)),
common_(other.common_),
44 finished_(std::exchange(other.finished_,
true)) {}
47 data_ = std::exchange(other.data_, {});
offsets_ = std::move(other.offsets_);
common_ = other.common_;
48 count_ = std::exchange(other.count_, 0);
50 finished_ = std::exchange(other.finished_,
true);
56 bool failed() const noexcept {
return false; }
59 if (
finished_) error_detail::raise<std::logic_error>(
"native profile writer is finished");
67 if ((literal.
size() & (P::bits_per_unit - 1)) || (value.size() & (P::bits_per_unit - 1)))
68 error_detail::raise<std::invalid_argument>(
"native writer record length disagrees with policy units");
69 auto value_units = value.size() >> P::unit_shift;
71 error_detail::raise<std::invalid_argument>(
"native writer value disagrees with common width");
73 error_detail::raise<std::invalid_argument>(
"native writer invalid known prefix");
74 auto literal_units = literal.
size() >> P::unit_shift;
75 auto key_units = retained + literal_units;
78 auto saved_offsets =
offsets_.size();
80 auto block =
count_ % P::codec_block_size == 0;
88 std::array<std::byte, 30> control;
89 auto end = control.data();
90 auto count = [&](std::uint64_t n) {
91 while (n >= 128) { *end++ = std::byte((n & 127) | 128); n >>= 7; }
92 *end++ = std::byte(n);
96 if (!
common_) count(value_units);
97 auto control_bytes = std::uint64_t(end - control.data());
98 auto payload_bits =
add(literal.
size(), value.size());
100 std::memcpy(
data_.
bytes.data() + (saved_bits >> 3), control.data(),
static_cast<std::size_t
>(control_bytes));
101 auto at = saved_bits + (control_bytes << 3);
105 if (block) write_count<P>(
data_, retained);
107 write_count<P>(
data_, literal_units);
126 offsets_.push_back(extent - stride);
167 :
output_(std::move(other.output_)),
previous_(std::exchange(other.previous_, {})) {}
169 if (
this != &other) {
170 output_ = std::move(other.output_);
previous_ = std::exchange(other.previous_, {});
183 if ((key.size() & (P::bits_per_unit - 1)) || (value.size() & (P::bits_per_unit - 1)))
184 error_detail::raise<std::invalid_argument>(
"native writer record length disagrees with policy units");
185 auto common =
output_.common_value_width();
186 if (common && (value.size() >> P::unit_shift) != *common)
187 error_detail::raise<std::invalid_argument>(
"native writer value disagrees with common width");
188 auto comparison = compare_common_bits<typename P::architecture>(
previous_.
view(), key);
189 if (
output_.size() && comparison.order >= 0)
190 error_detail::raise<std::invalid_argument>(
"native writer keys must be strictly increasing");
191 auto retained = std::min(comparison.common_bits, retained_limit_bits.value_or(comparison.common_bits)) >> P::unit_shift;
192 auto retained_bits = retained * P::bits_per_unit;
197 error_detail::raise<std::length_error>(
"profile bit string too large");
199 auto literal = key.subview(retained_bits, key.size() - retained_bits);
200 output_.append(retained, literal, value);
209 auto result =
output_.finish();
std::uint64_t add(std::uint64_t a, std::uint64_t b)
Definition profile.h:39
std::uint64_t multiply(std::uint64_t a, std::uint64_t b)
Definition profile.h:44
std::uint64_t byte_count(std::uint64_t bits) noexcept
Definition profile.h:50
void resize(bit_string &value, std::uint64_t bits)
Definition profile.h:465
void copy_into(bit_string &target, std::uint64_t first, bit_view source)
Definition profile.h:474
void copy_bits(std::byte *target, std::uint64_t first, bit_view source) noexcept
Definition profile.h:123
void append(bit_string &target, bit_view source)
Definition profile.h:480
Definition active_engine.h:18
stream_role
Definition policy.h:25
Declares Everett's profile support.
std::vector< std::byte > bytes
Definition profile.h:167
bit_view view() const &
Definition profile.h:178
std::uint64_t bit_size
Definition profile.h:168
std::uint64_t size() const noexcept
Definition profile.h:64
bool empty() const noexcept
Definition profile.h:65
Definition profile.h:1168
profile_metadata metadata_
Definition profile.h:1259
elias_fano offsets_
Definition profile.h:1258
std::vector< std::byte > bytes_
Definition profile.h:1256
Definition native_writer.h:30
std::vector< std::uint64_t > offsets_
Definition native_writer.h:146
void append(std::uint64_t retained, bit_view literal, bit_view value)
Definition native_writer.h:65
std::optional< std::uint64_t > common_
Definition native_writer.h:147
profile_array< P > finish()
Definition native_writer.h:121
std::uint64_t count_
Definition native_writer.h:148
bool failed() const noexcept
Definition native_writer.h:56
native_output & operator=(native_output &&other) noexcept
Definition native_writer.h:45
void require_active() const
Definition native_writer.h:58
native_output & operator=(native_output const &)=delete
native_output(native_output const &)=delete
std::uint64_t size() const noexcept
Definition native_writer.h:54
native_output(std::optional< std::uint64_t > common_value_width)
Definition native_writer.h:32
std::optional< std::uint64_t > common_value_width() const noexcept
Definition native_writer.h:57
native_output(native_output &&other) noexcept
Definition native_writer.h:41
P policy_type
Definition native_writer.h:31
bit_string data_
Definition native_writer.h:145
bool finished() const noexcept
Definition native_writer.h:55
bool finished_
Definition native_writer.h:150
std::uint64_t previous_units_
Definition native_writer.h:149
Definition native_writer.h:158
bit_string previous_
Definition native_writer.h:216
profile_native_writer(profile_native_writer const &)=delete
std::optional< std::uint64_t > common_value_width() const noexcept
Definition native_writer.h:177
void append(profile_record const &record)
Definition native_writer.h:204
profile_native_writer & operator=(profile_native_writer const &)=delete
static constexpr stream_role role
Definition native_writer.h:160
void append(bit_view key, bit_view value, std::optional< std::uint64_t > retained_limit_bits={})
Definition native_writer.h:181
std::uint64_t size() const noexcept
Definition native_writer.h:175
profile_native_writer(profile_native_writer &&other) noexcept
Definition native_writer.h:166
profile_native_writer(std::optional< std::uint64_t > common_value_width=P::value_width)
Definition native_writer.h:162
P policy_type
Definition native_writer.h:159
bool finished() const noexcept
Definition native_writer.h:176
profile_detail::native_output< P > output_
Definition native_writer.h:215
profile_array< P > finish()
Definition native_writer.h:208
profile_native_writer & operator=(profile_native_writer &&other) noexcept
Definition native_writer.h:168
std::optional< std::uint64_t > retained_limit_bits
Definition profile.h:299
bit_string key
Definition profile.h:295
bit_string value
Definition profile.h:296