23 template <
class P,
class Selector = registry_selector<
typename P::registry_type>>
struct sort_key_transport {
25 return sort_profile_query<P, S, Selector>(key);
35 return Selector::select(input, [&]<
class S>(std::type_identity<S> tag,
auto & source) ->
decltype(
auto) {
36 auto key = decode<S>(source.take_bits(source.remaining()));
37 return std::invoke(std::forward<F>(fn), tag, key);
42 template <
class P,
class Selector = registry_selector<
typename P::registry_type>>
struct sort_runtime_native {
47 using pointer = std::shared_ptr<sort_runtime_native const>;
52 if (!value)
throw std::invalid_argument(
"null owned sort runtime native");
56 if (!value)
throw std::invalid_argument(
"null mapped sort runtime native");
60 std::uint64_t
size()
const {
return view().size(); }
61 std::shared_ptr<array_type const>
owned() const noexcept {
return owned_; }
62 std::shared_ptr<mapped_type const>
mapped() const noexcept {
return mapped_; }
63 std::shared_ptr<native_seal const>
sealed() const noexcept {
return seal_; }
72 if (std::filesystem::canonical(receipt.
path) != std::filesystem::canonical(path))
73 throw std::invalid_argument(
"sealed native path differs from object identity");
76 auto binding = std::make_shared<native_binding<mapped_type>
const>(
78 result->seal_ = binding;
79 result->bindings_.get_or_create(binding->catalog, root, [&] {
return binding; });
84 std::shared_ptr<native_seal const>
seal_;
85 std::shared_ptr<array_type const>
owned_;
86 std::shared_ptr<mapped_type const>
mapped_;
91 namespace sort_runtime_detail {
94 template <
class P,
class Selector,
class Writer>
99 for (
auto const & record : records) {
100 auto key = record.key.
view();
101 auto comparison = compare_common_bits<typename P::architecture>(previous, key);
102 if (!first && comparison.order >= 0)
103 throw std::invalid_argument(
"sort native requires unique sorted keys");
105 Selector::select(input, [&]<
class S>(std::type_identity<S>,
auto & source) {
106 sort_codec_detail::validate_value_width<S>();
108 frame.
path = key.prefix(source.position());
113 std::array<bit_view, 1> spans{key};
114 writer.append_frame(frame, spans, comparison.common_bits, record.
value.view());
116 previous = key; first =
false;
121 template <
class P,
class Selector = registry_selector<
typename P::registry_type>>
struct sort_runtime_storage {
122 static_assert(P::unit == profile_unit::bit,
"sort runtime uses bit-addressed records");
128 template <
class Compose>
static auto make_merge(std::shared_ptr<native_type const> older,
129 std::shared_ptr<native_type const> newer, Compose compose) {
130 return std::make_unique<merge_type<Compose>>(std::move(older), std::move(newer), std::move(compose));
132 template <
class Merge>
static auto finish_merge(Merge & merge) {
return native_type::from_owned(merge.finish()); }
134 template <
class Node>
static auto make_index(std::shared_ptr<native_type const> native,
135 typename Node::pair_type main = {}, std::shared_ptr<native_type const>
secondary = {}) {
136 return std::make_unique<index_type<Node>>(std::move(native), std::move(main), std::move(secondary));
142 sort_runtime_detail::write_sorted_native<P, Selector>(writer, records);
143 return native_type::from_owned(writer.
finish());
150 template <
class P =
string_policy,
class Selector = registry_selector<
typename P::registry_type>,
151 class Storage = sort_runtime_storage<P, Selector>>
155 static auto open_storage(std::filesystem::path
const & root)
requires requires { Storage::open(root); } {
156 return Storage::open(root);
158 static auto open_storage(std::filesystem::path
const & root, std::string_view schema)
159 requires requires { Storage::open(root); } {
160 if constexpr (
requires { { Storage::open_for_schema(root, schema) } -> std::same_as<Storage>; })
161 return Storage::open_for_schema(root, schema);
162 else return Storage::open(root);
164 template <
class Options>
static auto open_storage(std::filesystem::path
const & root,
165 std::string_view schema, Options options)
166 requires requires { Storage::open_for_schema(root, schema, options); } {
167 return Storage::open_for_schema(root, schema, std::move(options));
170 if constexpr (std::same_as<typename P::registry_type, string_registry> &&
171 std::same_as<Selector, registry_selector<typename P::registry_type>>)
172 return "everett.optional-string/code0/sort-profile-v1";
void write_sorted_native(Writer &writer, std::span< profile_record const > records)
Definition sort_runtime.h:95
Definition active_engine.h:18
std::filesystem::path object_path(object_id const &id, file_kind kind)
Definition object_path.h:52
Executes redundant COLA slots with charged jobs and immutable frontiers.
Describes completed native and index objects retained by runtime owners.
Maps sort-owned KV03 records and binds their ordinary fractional indexes.
Merges sort-owned records while retaining inherited keys as borrowed spans.
bit_view view() const &
Definition profile.h:178
Definition catalog_bindings.h:25
Definition cola_index.h:496
auto finish()
Definition cola_index.h:581
Definition sort_profile_file.h:29
Definition sort_profile_file.h:185
Definition sort_profile_file.h:116
static mapped_sort_profile open(file< P > source)
Definition sort_profile_file.h:120
Definition runtime_seal.h:19
Definition object_path.h:38
Definition object_writer.h:88
std::filesystem::path path
Definition object_writer.h:91
object_id object
Definition object_writer.h:89
Definition redundant_runtime.h:918
Definition registry.h:122
Definition runtime_graph_sealer.h:22
Definition runtime_store.h:58
Definition sort_codec.h:56
Definition sort_codec.h:38
Definition sort_codec.h:401
Definition sort_runtime.h:23
static bit_string prefix()
Definition sort_runtime.h:27
static auto decode(bit_view bits)
Definition sort_runtime.h:30
static decltype(auto) dispatch(bit_view bits, F &&fn)
Definition sort_runtime.h:33
static bit_string encode(typename sort_codec< S >::key_codec::value_type const &key)
Definition sort_runtime.h:24
Definition sort_profile.h:405
Definition sort_profile.h:143
Definition sort_profile.h:397
Definition sort_profile.h:163
std::uint64_t key_units
Definition sort_profile.h:164
bool front_coded
Definition sort_profile.h:169
std::size_t leaf
Definition sort_profile.h:168
bit_view path
Definition sort_profile.h:167
std::optional< std::uint64_t > retained_limit_bits
Definition sort_profile.h:171
bit_view value
Definition sort_profile.h:166
Definition sort_profile.h:32
Definition sort_profile_merge.h:66
Definition sort_profile.h:531
array_type finish()
Definition sort_profile.h:569
Definition sort_runtime_context.h:33
Definition sort_runtime.h:152
static std::string default_schema()
Definition sort_runtime.h:169
static auto open_storage(std::filesystem::path const &root)
Definition sort_runtime.h:155
static auto open_storage(std::filesystem::path const &root, std::string_view schema, Options options)
Definition sort_runtime.h:164
static auto open_storage(std::filesystem::path const &root, std::string_view schema)
Definition sort_runtime.h:158
Definition sort_runtime.h:42
P policy_type
Definition sort_runtime.h:43
catalog_bindings< sort_runtime_native > mapped_owners_
Definition sort_runtime.h:83
static pointer from_owned(std::shared_ptr< array_type const > value)
Definition sort_runtime.h:51
sort_runtime_native(std::shared_ptr< array_type const > value)
Definition sort_runtime.h:87
std::shared_ptr< array_type const > owned_
Definition sort_runtime.h:85
std::uint64_t size() const
Definition sort_runtime.h:60
std::shared_ptr< mapped_type const > mapped() const noexcept
Definition sort_runtime.h:62
sort_runtime_native(std::shared_ptr< mapped_type const > value)
Definition sort_runtime.h:88
std::shared_ptr< array_type const > owned() const noexcept
Definition sort_runtime.h:61
std::shared_ptr< native_seal const > sealed() const noexcept
Definition sort_runtime.h:63
static pointer from_mapped(std::shared_ptr< mapped_type const > value)
Definition sort_runtime.h:55
std::shared_ptr< sort_runtime_native const > pointer
Definition sort_runtime.h:47
static pointer from_sealed(std::filesystem::path const &root, object_id catalog, object_seal_receipt receipt)
Definition sort_runtime.h:70
std::shared_ptr< native_seal const > seal_
Definition sort_runtime.h:84
auto view() const
Definition sort_runtime.h:59
static pointer from_owned(array_type value)
Definition sort_runtime.h:48
catalog_bindings< native_binding< mapped_type > > bindings_
Definition sort_runtime.h:82
std::shared_ptr< mapped_type const > mapped_
Definition sort_runtime.h:86
Definition sort_runtime.h:121
static auto sorted_native(std::span< profile_record const > records)
Definition sort_runtime.h:140
static auto make_index(std::shared_ptr< native_type const > native, typename Node::pair_type main={}, std::shared_ptr< native_type const > secondary={})
Definition sort_runtime.h:134
static auto empty()
Definition sort_runtime.h:139
static auto singleton(profile_record const &record)
Definition sort_runtime.h:145
static auto encode_native(sort_profile_array< P, Selector > const &value)
Definition sort_runtime.h:126
static auto finish_merge(Merge &merge)
Definition sort_runtime.h:132
static auto make_merge(std::shared_ptr< native_type const > older, std::shared_ptr< native_type const > newer, Compose compose)
Definition sort_runtime.h:128
static auto finish_index(index_type< Node > &index)
Definition sort_runtime.h:138
Connects sort-owned semantics to encoded COLA updates and immutable typed snapshots.