Everett
Loading...
Searching...
No Matches
profile_index.h
Go to the documentation of this file.
1
13#pragma once
14
15#include <everett/profile.h>
16#include <everett/rank_groups.h>
17
18#include <cstddef>
19#include <cstdint>
20#include <span>
21#include <utility>
22#include <vector>
23
24namespace everett {
25 template <class P, class Native, class Output> struct index_builder;
26 namespace profile_detail {
27 template <class P> struct index_output;
28 template <class P> struct index_metadata {
30 std::vector<std::byte> false_borrows;
31 std::vector<std::uint64_t> cut_lcps;
32 std::uint64_t virtual_count = 0;
33 };
34 }
35
36 // An owning index artifact, independent of native storage. Construction uses
37 // a pinned source and trusted samples of one exact target. The caller keeps
38 // those dependencies pinned through sealing and publication of this artifact.
39 template <class P> struct profile_index {
40 using policy_type = P;
42 static constexpr std::uint64_t group_size = P::group_size;
43
44 // A terminal pair has no borrowed occurrences. Construct its zero
45 // directories from the admitted native count without visiting native keys.
46 static profile_index native_only(std::uint64_t count) {
47 auto groups = count / group_size + (count % group_size != 0);
48 std::vector<std::uint64_t> cuts;
49 if (groups > cuts.max_size()) error_detail::raise<std::length_error>("native index is too large");
50 cuts.resize(static_cast<std::size_t>(groups), 0);
51 auto ranks = rank_groups<group_size>::build(cuts, count);
52 return profile_index(borrowed_array::build({}), std::move(ranks), {}, std::move(cuts), count);
53 }
54
55 borrowed_array const & borrowed() const & noexcept { return borrowed_; }
56 borrowed_array const & borrowed() const && = delete;
57 rank_groups<group_size> const & interleave() const & noexcept { return interleave_; }
58 rank_groups<group_size> const & interleave() const && = delete;
59 std::span<std::byte const> false_borrow_bits() const & noexcept { return false_borrows_; }
60 std::span<std::byte const> false_borrow_bits() const && = delete;
61 std::span<std::uint64_t const> cut_lcps() const & noexcept { return cut_lcps_; }
62 std::span<std::uint64_t const> cut_lcps() const && = delete;
63 std::uint64_t virtual_size() const noexcept { return virtual_count_; }
64 std::uint64_t native_size() const noexcept { return virtual_count_ - borrowed_.size(); }
65
66 private:
67 template <class, class, class> friend struct index_builder;
68 friend struct profile_detail::index_output<P>;
69
72 std::vector<std::byte> false_borrows_;
73 std::vector<std::uint64_t> cut_lcps_;
74 std::uint64_t virtual_count_;
75
77 std::vector<std::byte> false_borrows, std::vector<std::uint64_t> cut_lcps,
78 std::uint64_t virtual_count)
79 : borrowed_(std::move(borrowed)), interleave_(std::move(interleave)),
80 false_borrows_(std::move(false_borrows)), cut_lcps_(std::move(cut_lcps)),
81 virtual_count_(virtual_count) {}
82 };
83 namespace profile_detail {
84 // Default index output owns borrowed FC bytes. Alternate outputs share the
85 // same builder and consume this known adjacent-key comparison synchronously.
86 template <class P> struct index_output {
87 using policy_type = P;
88 index_output() = default;
89 index_output(index_output const &) = delete;
90 index_output & operator=(index_output const &) = delete;
93 std::uint64_t size() const noexcept { return writer_.size(); }
94 bool finished() const noexcept { return writer_.finished(); }
95 bool failed() const noexcept { return false; }
96 void append_known(bit_view key, std::uint64_t common_bits) { writer_.append_known(key, common_bits); }
98 auto borrowed = writer_.finish();
99 return profile_index<P>(std::move(borrowed), std::move(metadata.interleave),
100 std::move(metadata.false_borrows), std::move(metadata.cut_lcps), metadata.virtual_count);
101 }
102 private:
104 };
105 }
106
107}
Definition active_engine.h:18
Declares Everett's profile support.
Declares Everett's rank groups support.
Definition profile.h:56
Definition index_builder.h:47
std::uint64_t size() const noexcept
Definition profile.h:1240
static profile_array build(std::span< profile_record const > records, std::span< std::uint64_t const > prefix_ceilings={}, std::uint64_t restart_factor=0)
Definition profile.h:1173
Definition profile.h:1280
Definition profile_index.h:28
std::vector< std::uint64_t > cut_lcps
Definition profile_index.h:31
rank_groups< P::group_size > interleave
Definition profile_index.h:29
std::vector< std::byte > false_borrows
Definition profile_index.h:30
std::uint64_t virtual_count
Definition profile_index.h:32
Definition profile_index.h:86
index_output(index_output &&)=default
profile_borrowed_writer< P > writer_
Definition profile_index.h:103
P policy_type
Definition profile_index.h:87
index_output(index_output const &)=delete
index_output & operator=(index_output const &)=delete
void append_known(bit_view key, std::uint64_t common_bits)
Definition profile_index.h:96
bool failed() const noexcept
Definition profile_index.h:95
profile_index< P > finish(index_metadata< P > metadata)
Definition profile_index.h:97
std::uint64_t size() const noexcept
Definition profile_index.h:93
index_output & operator=(index_output &&)=default
bool finished() const noexcept
Definition profile_index.h:94
Definition profile_index.h:39
std::uint64_t virtual_count_
Definition profile_index.h:74
std::uint64_t virtual_size() const noexcept
Definition profile_index.h:63
std::span< std::uint64_t const > cut_lcps() const &&=delete
std::span< std::byte const > false_borrow_bits() const &&=delete
borrowed_array const & borrowed() const &&=delete
rank_groups< group_size > const & interleave() const &noexcept
Definition profile_index.h:57
borrowed_array borrowed_
Definition profile_index.h:70
std::vector< std::byte > false_borrows_
Definition profile_index.h:72
profile_index(borrowed_array borrowed, rank_groups< group_size > interleave, std::vector< std::byte > false_borrows, std::vector< std::uint64_t > cut_lcps, std::uint64_t virtual_count)
Definition profile_index.h:76
P policy_type
Definition profile_index.h:40
static profile_index native_only(std::uint64_t count)
Definition profile_index.h:46
std::span< std::uint64_t const > cut_lcps() const &noexcept
Definition profile_index.h:61
rank_groups< group_size > interleave_
Definition profile_index.h:71
borrowed_array const & borrowed() const &noexcept
Definition profile_index.h:55
std::uint64_t native_size() const noexcept
Definition profile_index.h:64
std::vector< std::uint64_t > cut_lcps_
Definition profile_index.h:73
static constexpr std::uint64_t group_size
Definition profile_index.h:42
std::span< std::byte const > false_borrow_bits() const &noexcept
Definition profile_index.h:59
rank_groups< group_size > const & interleave() const &&=delete
Definition rank_groups.h:241
static rank_groups build(std::span< std::uint64_t const > source, std::uint64_t count)
Definition rank_groups.h:247