20 namespace sort_profile_file_detail {
23 inline void append_words(std::vector<std::byte> & out, std::span<std::uint64_t const> words) {
24 out.resize(words.size() << 3);
25 for (std::size_t i = 0; i != words.size(); ++i)
file_detail::put(out, i << 3, 8, words[i]);
35 owned_(std::move(other.owned_)),
active_(std::exchange(other.active_,
false)) {}
39 parts_ = other.parts_;
owned_ = std::move(other.owned_);
active_ = std::exchange(other.active_,
false);
46 for (
unsigned i = 0; i != 4; ++i) directory[i] = std::byte(
"KV03"[i]);
48 auto const & metadata = source.
metadata();
55 directory[48] = std::byte(ef.low_width);
59 result.
words(1, ef.low); result.
words(2, ef.high); result.
words(4, ef.sparse);
61 auto & samples = result.
owned_[3]; samples.resize(ef.samples.size() << 4);
62 for (std::size_t i = 0; i != ef.samples.size(); ++i) {
66 result.
parts_[3] = samples;
67 std::uint64_t end = directory.size();
68 for (std::size_t i = 0; i != result.
parts_.size(); ++i) {
75 result.
header_.common_value_width = metadata.common_value_width;
82 std::vector<std::span<std::
byte const>>
chunks() const & {
84 std::vector<std::span<std::byte const>> result{
directory_};
88 if (gap) result.push_back(std::span(
zero_).first(gap));
89 result.push_back(part); end += gap + part.size();
93 std::vector<std::span<std::byte const>>
chunks() const && = delete;
95 std::vector<std::byte> body;
96 for (
auto part :
chunks()) body.insert(body.end(), part.begin(), part.end());
107 std::array<std::span<std::byte const>, 8>
parts_;
108 std::array<std::vector<std::byte>, 8>
owned_;
111 void words(std::size_t slot, std::span<std::uint64_t const> source) {
116 template <
class P,
class Selector = registry_selector<
typename P::registry_type>>
struct mapped_sort_profile {
121 auto header = source.
header();
auto body = source.
body();
auto bytes = body.bytes();
124 throw std::invalid_argument(
"sort profile file extent or kind");
125 for (
unsigned i = 0; i != 4; ++i)
126 if (bytes[i] != std::byte(
"KV03"[i]))
throw std::invalid_argument(
"sort profile file revision");
128 throw std::invalid_argument(
"sort profile section revision");
130 std::array<std::span<std::byte const>, 8> parts;
131 std::uint64_t end = 192;
132 for (std::size_t i = 0; i != parts.size(); ++i) {
135 throw std::invalid_argument(
"sort profile section range");
136 parts[i] = bytes.subspan(first, count); end = first + count;
138 if (end != bytes.size())
throw std::invalid_argument(
"trailing sort profile sections");
139 auto metadata = profile_detail::initial_metadata<P, stream_role::native>();
141 metadata.record_count = header.record_count; metadata.terminal_key_units =
file_detail::get(bytes, 16, 8);
142 metadata.common_value_width = header.common_value_width;
143 metadata.policy_fixed_values = header.policy_value_width.has_value();
144 metadata.policy_value_width = header.policy_value_width.value_or(0);
149 throw std::invalid_argument(
"sort profile bit section extent");
150 auto blocks = header.record_count / P::codec_block_size + (header.record_count % P::codec_block_size != 0);
153 file_detail::get(bytes, 24, 8), unsigned(std::to_integer<unsigned char>(bytes[48]))};
154 view_type view({parts[0], metadata.extent}, ef, metadata, {parts[5], dictionary_bits},
156 return {std::move(source), std::move(body), std::move(
view)};
167 auto bytes =
body_.
bytes(); std::uint64_t end = 192;
168 for (
unsigned i = 0; i != 8; ++i) {
170 section_detail::zero(bytes.subspan(end, first - end),
"nonzero sort profile section gap"); end = first + count;
173 if ((bits.size() & 7) && (std::to_integer<unsigned>(bits.storage().back()) & ((1u << (8 - (bits.size() & 7))) - 1)))
174 throw std::invalid_argument(
"sort profile tail padding");
185 template <
class P,
class Selector = registry_selector<
typename P::registry_type>>
struct mapped_sort_cola {
191 using pair_type = std::shared_ptr<mapped_sort_cola const>;
201 bool(index->main_id()) !=
bool(
main) || (
main && *index->main_id() !=
main->identity()) ||
202 bool(
secondary) !=
bool(secondary_id) || index->secondary_id() != secondary_id)
203 throw std::invalid_argument(
"sort COLA pinned identity mismatch");
204 if (index->borrowed(0).size() != (
main ?
main->group_count() : 0) ||
206 throw std::invalid_argument(
"sort COLA sample count mismatch");
210 {index->false_borrow_bits(0), index->false_borrow_bits(1)}, {index->cut_lcps(0), index->cut_lcps(1)}, index->virtual_size()};
229 std::shared_ptr<mapped_cola_index<P>
const>
index_;
Enumerates native matches along a COLA main chain and its terminal secondaries.
Encodes two-target COLA routing in portable IX03 sections.
Binds mapped COLA main and secondary targets with exact immutable pins.
void put(std::span< std::byte > bytes, std::size_t at, unsigned width, std::uint64_t value) noexcept
Definition file.h:70
std::uint64_t get(std::span< std::byte const > bytes, std::size_t at, unsigned width) noexcept
Definition file.h:65
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
std::uint64_t align(std::uint64_t value) noexcept
Definition sections.h:68
void zero(std::span< std::byte const > bytes, char const *message)
Definition sections.h:71
void append_words(std::vector< std::byte > &out, std::span< std::uint64_t const > words)
Definition sort_profile_file.h:23
constexpr std::size_t descriptors
Definition sort_profile_file.h:22
constexpr std::size_t section_count
Definition sort_profile_file.h:21
constexpr std::size_t directory_bytes
Definition sort_profile_file.h:21
Definition active_engine.h:18
void scan_mapped_cola(Blob const &source)
Definition mapped_cola.h:202
file_open_mode
Definition file.h:32
std::vector< std::byte > encode_file(file_header< P > const &header, std::span< std::byte const > body)
Definition file.h:221
Navigates sort-owned bit records using shared sort seeds and sparse offsets.
Definition cola_index.h:114
std::uint64_t virtual_size() const noexcept
Definition cola_index.h:144
borrowed_view const & borrowed(unsigned route) const
Definition cola_index.h:136
std::uint64_t group_count() const noexcept
Definition cola_index.h:145
Definition elias_fano.h:212
Definition sort_profile_file.h:29
std::vector< std::byte > materialize() const
Definition sort_profile_file.h:94
encoded_sort_sections & operator=(encoded_sort_sections const &)=delete
encoded_sort_sections & operator=(encoded_sort_sections &&other) noexcept
Definition sort_profile_file.h:36
static encoded_sort_sections from(sort_profile_array< P, Selector > const &&)=delete
void require_active() const
Definition sort_profile_file.h:110
std::vector< std::span< std::byte const > > chunks() const &&=delete
std::array< std::vector< std::byte >, 8 > owned_
Definition sort_profile_file.h:108
std::vector< std::span< std::byte const > > chunks() const &
Definition sort_profile_file.h:82
encoded_sort_sections()=default
std::array< std::byte, 8 > zero_
Definition sort_profile_file.h:106
encoded_sort_sections(encoded_sort_sections const &)=delete
std::array< std::span< std::byte const >, 8 > parts_
Definition sort_profile_file.h:107
std::array< std::byte, 192 > directory_
Definition sort_profile_file.h:105
file_header< P > const & header() const &&=delete
object_seal_receipt seal(std::filesystem::path const &root, object_id const &id, object_attempt_id const &attempt) const
Definition sort_profile_file.h:99
bool active_
Definition sort_profile_file.h:109
file_header< P > header_
Definition sort_profile_file.h:104
file_header< P > const & header() const &
Definition sort_profile_file.h:80
void words(std::size_t slot, std::span< std::uint64_t const > source)
Definition sort_profile_file.h:111
encoded_sort_sections(encoded_sort_sections &&other) noexcept
Definition sort_profile_file.h:33
static encoded_sort_sections from(sort_profile_array< P, Selector > const &source)
Definition sort_profile_file.h:43
file_header< P > header() const
Definition file.h:268
mapped_slice body() const
Definition file.h:269
Definition cola_sections.h:266
Definition mapped_file.h:81
std::span< std::byte const > bytes() const &noexcept
Definition mapped_file.h:99
bool empty() const noexcept
Definition mapped_file.h:97
Definition sort_profile_file.h:185
void scan() const
Definition sort_profile_file.h:225
index_pointer index_object() const noexcept
Definition sort_profile_file.h:218
blob_identity identity_
Definition sort_profile_file.h:227
view_type view_
Definition sort_profile_file.h:232
std::shared_ptr< index_type const > index_pointer
Definition sort_profile_file.h:190
std::shared_ptr< mapped_cola_index< P > const > index_
Definition sort_profile_file.h:229
std::shared_ptr< mapped_sort_cola const > pair_type
Definition sort_profile_file.h:191
native_pointer secondary_
Definition sort_profile_file.h:231
view_type view() const &&=delete
auto const & identity() const &noexcept
Definition sort_profile_file.h:214
std::uint64_t virtual_size() const noexcept
Definition sort_profile_file.h:221
P policy_type
Definition sort_profile_file.h:186
std::uint64_t group_count() const noexcept
Definition sort_profile_file.h:222
mapped_sort_cola & operator=(mapped_sort_cola &&)=delete
static pair_type bind(blob_identity identity, native_pointer native, std::shared_ptr< mapped_cola_index< P > const > index, pair_type main={}, native_pointer secondary={}, std::optional< object_id > secondary_id={})
Definition sort_profile_file.h:197
std::shared_ptr< native_type const > native_pointer
Definition sort_profile_file.h:188
auto const & identity() const &&=delete
native_pointer native_
Definition sort_profile_file.h:228
mapped_sort_cola(mapped_sort_cola &&)=delete
mapped_sort_cola & operator=(mapped_sort_cola const &)=delete
view_type view() const &
Definition sort_profile_file.h:223
pair_type main_
Definition sort_profile_file.h:230
mapped_sort_cola(blob_identity identity, native_pointer native, std::shared_ptr< mapped_cola_index< P > const > index, pair_type main, native_pointer secondary, view_type view)
Definition sort_profile_file.h:233
native_pointer native_owner() const noexcept
Definition sort_profile_file.h:216
native_pointer native_object() const noexcept
Definition sort_profile_file.h:217
cola_index_view< P, sort_profile_family< P, Selector > > view_type
Definition sort_profile_file.h:192
native_pointer secondary_target() const noexcept
Definition sort_profile_file.h:220
mapped_sort_cola(mapped_sort_cola const &)=delete
pair_type main_target() const noexcept
Definition sort_profile_file.h:219
Definition sort_profile_file.h:116
mapped_slice body_
Definition sort_profile_file.h:179
void require_active() const
Definition sort_profile_file.h:177
mapped_sort_profile(file< P > source, mapped_slice body, view_type view)
Definition sort_profile_file.h:181
std::uint64_t size() const
Definition sort_profile_file.h:164
view_type view() const &&=delete
file< P > source_
Definition sort_profile_file.h:178
static mapped_sort_profile from_slice(mapped_slice source, file_open_mode mode=file_open_mode::checked)
Definition sort_profile_file.h:159
view_type view() const &
Definition sort_profile_file.h:162
void scan() const
Definition sort_profile_file.h:165
view_type view_
Definition sort_profile_file.h:180
P policy_type
Definition sort_profile_file.h:117
static mapped_sort_profile open(std::filesystem::path const &path)
Definition sort_profile_file.h:158
static mapped_sort_profile open(file< P > source)
Definition sort_profile_file.h:120
Definition object_writer.h:39
Definition object_path.h:38
Definition object_writer.h:88
static object_seal_receipt seal(std::filesystem::path const &root, object_id const &id, object_attempt_id const &attempt, file_header< P > const &header, std::span< std::span< std::byte const > const > chunks, Ops &ops)
Definition object_writer.h:164
static sample_view little_endian(std::span< std::byte const > bytes)
Definition word_view.h:92
Definition sort_profile.h:405
auto const & data() const &noexcept
Definition sort_profile.h:417
std::uint64_t size() const noexcept
Definition sort_profile.h:414
std::span< std::uint64_t const > dictionary_offsets() const noexcept
Definition sort_profile.h:419
auto const & metadata() const noexcept
Definition sort_profile.h:415
auto const & dictionary() const &noexcept
Definition sort_profile.h:418
auto const & seeds() const &noexcept
Definition sort_profile.h:420
auto const & group_offsets() const &noexcept
Definition sort_profile.h:416
Definition sort_profile.h:397
Definition sort_profile.h:176
void scan() const
Definition sort_profile.h:281
std::uint64_t size() const noexcept
Definition sort_profile.h:206
bit_view seeds() const noexcept
Definition sort_profile.h:219
bit_view data() const noexcept
Definition sort_profile.h:216
bit_view dictionary() const noexcept
Definition sort_profile.h:217
static word_view little_endian(std::span< std::byte const > bytes)
Definition word_view.h:36