22#include <unordered_map>
23#include <unordered_set>
33 using pair_type = std::shared_ptr<mapped_blob const>;
43 if (!
native || !index)
throw std::invalid_argument(
"null Everett mapped pair component");
44 if (
identity.
native != index->native_id())
throw std::invalid_argument(
"Everett index names another native object");
45 auto const & expected = index->target_id();
46 if (
bool(expected) !=
bool(
target) || (expected && *expected !=
target->identity()))
47 throw std::invalid_argument(
"Everett mapped pair target identity mismatch");
48 if (index->borrowed().size() != (
target ?
target->group_count() : 0))
49 throw std::invalid_argument(
"Everett mapped pair sample count mismatch");
51 index->false_borrow_bits(), index->cut_lcps(), index->virtual_size());
78 return view_.search_window(group, lower, native_work, borrowed_work);
85 std::unordered_set<mapped_blob const *> seen;
86 std::unordered_set<native_type const *> native_seen;
87 for (
auto current =
this; current; current = current->target_.get()) {
88 if (!seen.insert(current).second)
throw std::invalid_argument(
"cyclic Everett mapped chain");
89 if (native_seen.insert(current->native_.get()).second) current->native_->scan();
90 current->index_->scan();
92 current->scan_samples();
98 std::shared_ptr<native_type const>
native_;
99 std::shared_ptr<index_type const>
index_;
114 if (
done())
throw std::out_of_range(
"Everett merged cursor at end");
124 bit_string previous_native, previous_borrowed;
125 bool had_native =
false;
126 std::uint64_t ordinal = 0, borrowed_count = 0, population = 0;
129 while (!cursor.
done()) {
130 auto key = cursor.
key();
131 auto group = ordinal / P::group_size;
132 if (ordinal % P::group_size == 0) {
133 auto lcp = borrowed_count ? compare_common_bits<typename P::architecture>(previous_borrowed.
view(), key).common_bits : 0;
134 if (cuts[group] != lcp)
throw std::invalid_argument(
"Everett cut LCP disagrees with keys");
135 if (ranks.template rank<typename P::architecture>(group) != borrowed_count)
throw std::invalid_argument(
"Everett rank disagrees with interleaving");
139 bool expected = had_native && compare_bits<typename P::architecture>(previous_native.
view(), key) == 0;
141 throw std::invalid_argument(
"Everett false-borrow flag disagrees with keys");
151 if (ordinal % P::group_size == 0 || cursor.
done())
152 if (ranks.class_at(group) != population)
153 throw std::invalid_argument(
"Everett rank population disagrees with keys");
156 throw std::invalid_argument(
"Everett merged stream count mismatch");
161 if (!samples.done())
throw std::invalid_argument(
"Everett borrowed stream has no target");
165 std::uint64_t ordinal = 0;
167 if (ordinal % P::group_size == 0) {
168 if (samples.done() || compare_bits<typename P::architecture>(samples.peek().key.prefix,
target.key()) != 0)
169 throw std::invalid_argument(
"Everett borrowed key is not the exact target sample");
175 if (!samples.done())
throw std::invalid_argument(
"Everett trailing borrowed target samples");
186 using native_pointer = std::shared_ptr<mapped_native<P>
const>;
187 using index_pointer = std::shared_ptr<mapped_index<P>
const>;
188 struct pending_pair {
blob_identity identity; native_pointer
native; index_pointer index; };
189 std::vector<pending_pair> pending;
190 std::unordered_set<std::string> seen;
191 std::unordered_map<std::string, native_pointer> natives;
192 std::optional<blob_identity> current = head;
194 if (!seen.insert(current->index.hex()).second)
throw std::invalid_argument(
"cyclic Everett object identities");
195 auto index = std::make_shared<mapped_index<P>
const>(
197 if (index->native_id() != current->native)
throw std::invalid_argument(
"Everett chain native identity mismatch");
198 auto found = natives.find(current->native.hex());
199 if (found == natives.end()) {
200 auto native = std::make_shared<mapped_native<P>
const>(
202 found = natives.emplace(current->native.hex(), std::move(
native)).first;
204 pending.push_back({*current, found->second, index});
205 current = index->target_id();
208 for (
auto i = pending.size(); i-- > 0;)
210 std::move(pending[i].index), std::move(pair));
Definition active_engine.h:18
stream_role
Definition policy.h:25
mapped_query_root< P > open_mapped_query(std::filesystem::path const &root, blob_identity const &head)
Definition mapped_blob.h:184
std::filesystem::path object_path(object_id const &id, file_kind kind)
Definition object_path.h:52
Prepares immutable catalog chains and enumerates every matching native segment.
Encodes portable blob sections and retains mmap-backed profile directories.
bit_view view() const &
Definition profile.h:178
static bit_string copy(bit_view source)
Definition profile.h:181
object_id native
Definition sections.h:35
Definition mapped_blob.h:108
bool is_borrowed() const
Definition mapped_blob.h:113
merged_cursor(mapped_blob const &source)
Definition mapped_blob.h:111
bool done() const noexcept
Definition mapped_blob.h:112
profile_cursor< P, stream_role::borrowed > borrowed
Definition mapped_blob.h:110
void advance()
Definition mapped_blob.h:119
profile_cursor< P, stream_role::native > native
Definition mapped_blob.h:109
bit_view key() const
Definition mapped_blob.h:118
Definition mapped_blob.h:31
profile_blob_window project(std::uint64_t group) const
Definition mapped_blob.h:74
static pair_type bind(blob_identity identity, std::shared_ptr< native_type const > native, std::shared_ptr< index_type const > index, pair_type target={})
Definition mapped_blob.h:41
word_view cut_lcps() const &&=delete
mapped_blob(mapped_blob const &)=delete
rank_groups_view< P::group_size > interleave() const &&=delete
mapped_blob & operator=(mapped_blob const &)=delete
std::uint64_t group_count() const noexcept
Definition mapped_blob.h:72
profile_view< P, stream_role::native > native() const &&=delete
profile_blob_view< P > view() const &&=delete
pair_type target() const noexcept
Definition mapped_blob.h:60
std::shared_ptr< native_type const > native_
Definition mapped_blob.h:98
P policy_type
Definition mapped_blob.h:32
std::shared_ptr< index_type const > index_object() const noexcept
Definition mapped_blob.h:59
mapped_blob(blob_identity identity, std::shared_ptr< native_type const > native, std::shared_ptr< index_type const > index, pair_type target, profile_blob_view< P > view)
Definition mapped_blob.h:103
profile_blob_window_result< P > search_window(std::uint64_t group, profile_query_context< P > const &lower, profile_comparison_work *native_work=nullptr, profile_comparison_work *borrowed_work=nullptr) const
Definition mapped_blob.h:75
bool false_borrow(std::uint64_t ordinal) const
Definition mapped_blob.h:73
void scan_samples() const
Definition mapped_blob.h:158
pair_type target_
Definition mapped_blob.h:100
profile_view< P, stream_role::native > native() const &
Definition mapped_blob.h:61
blob_identity const & identity() const &&=delete
rank_groups_view< P::group_size > interleave() const &noexcept
Definition mapped_blob.h:67
std::shared_ptr< index_type const > index_
Definition mapped_blob.h:99
std::uint64_t virtual_size() const noexcept
Definition mapped_blob.h:71
void scan() const
Definition mapped_blob.h:84
blob_identity identity_
Definition mapped_blob.h:97
mapped_blob(mapped_blob &&)=delete
mapped_blob & operator=(mapped_blob &&)=delete
profile_view< P, stream_role::borrowed > borrowed() const &&=delete
profile_blob_view< P > view_
Definition mapped_blob.h:101
profile_blob_view< P > view() const &
Definition mapped_blob.h:65
void scan_pair() const
Definition mapped_blob.h:122
blob_identity const & identity() const &noexcept
Definition mapped_blob.h:56
word_view cut_lcps() const &noexcept
Definition mapped_blob.h:69
std::shared_ptr< native_type const > native_object() const noexcept
Definition mapped_blob.h:58
std::shared_ptr< mapped_blob const > pair_type
Definition mapped_blob.h:33
Definition sections.h:486
static mapped_index open(file< P > source)
Definition sections.h:488
Definition sections.h:442
static mapped_profile open(file< P > source)
Definition sections.h:444
Definition profile_blob.h:73
Definition profile_blob.h:61
Definition profile_blob.h:37
Definition profile.h:1066
bool done() const noexcept
Definition profile.h:1091
profile_item< P > peek() const &
Definition profile.h:1093
void advance()
Definition profile.h:1103
static query_root adopt_prepared(pair_type source)
Definition query.h:60
Definition rank_groups.h:127
Definition word_view.h:31