18 namespace sort_profile_detail {
25 std::span<bit_view const>
spans() const noexcept {
return spans_; }
27 if (
done())
throw std::out_of_range(
"sort merge source end");
30 throw std::invalid_argument(
"sort merge source terminal mismatch");
37 if (comparison.order >= 0)
throw std::invalid_argument(
"sort merge input is not strictly ordered");
38 retain();
return comparison;
63 template <
class P,
class Native = sort_profile_array<P>,
class Compose = replace_native_value,
64 class Selector =
typename Native::stream_family::selector_type,
65 class Output = sort_profile_writer<P, Selector>>
68 using view_type =
decltype(std::declval<Native const &>().view());
83 while (work.
keys < budget && !
done()) {
85 if (comparison.order < 0) {
88 }
else if (comparison.order > 0) {
94 if constexpr (!std::is_same_v<Compose, replace_native_value> && std::is_invocable_v<Compose &, bit_view, bit_view, bit_view>) {
100 if constexpr (std::is_same_v<
decltype(value),
bit_view>)
109 }
catch (...) {
failed_ =
true;
throw; }
112 if (!
done() ||
finished_)
throw std::logic_error(
"unfinished sort merge");
114 catch (...) {
failed_ =
true;
throw; }
125 std::uint64_t common,
bit_view value, std::uint64_t limit) {
126 auto frame = source.
frame();
129 })) frame.retained_limit_bits = limit;
130 output_.append_frame(frame, source.
spans(), common, value);
133 if (!value)
throw std::invalid_argument(
"null sort merge input");
136 static std::uint64_t
advance(
auto & source) {
auto cmp = source.advance();
return cmp ? cmp->common_bits : 0; }
bool is_tombstone(Compose &compose, bit_view value, Key &&key)
Definition native_merge.h:37
void append(bit_string &target, bit_view source)
Definition profile.h:480
bit_comparison compare_spans(std::span< bit_view const > a, std::span< bit_view const > b, std::uint64_t first_a=0, std::uint64_t first_b=0)
Definition sort_profile.h:116
Definition active_engine.h:18
Merges ordered native streams incrementally with policy-specific value composition.
Navigates sort-owned bit records using shared sort seeds and sparse offsets.
bit_view view() const &
Definition profile.h:178
Definition native_merge.h:148
std::uint64_t input_records
Definition native_merge.h:150
std::uint64_t keys
Definition native_merge.h:149
Definition sort_profile_merge.h:19
std::vector< bit_view > spans_
Definition sort_profile_merge.h:48
bit_string materialize() const
Definition sort_profile_merge.h:40
std::uint64_t ordinal_
Definition sort_profile_merge.h:49
bool done() const noexcept
Definition sort_profile_merge.h:23
View view_
Definition sort_profile_merge.h:46
std::uint64_t length_
Definition sort_profile_merge.h:49
std::optional< bit_comparison > advance()
Definition sort_profile_merge.h:26
merge_source(View view)
Definition sort_profile_merge.h:20
auto const & frame() const noexcept
Definition sort_profile_merge.h:24
void retain()
Definition sort_profile_merge.h:50
std::span< bit_view const > spans() const noexcept
Definition sort_profile_merge.h:25
sort_profile_frame frame_
Definition sort_profile_merge.h:47
Definition sort_profile.h:163
std::array< bit_view, 2 > literal
Definition sort_profile.h:165
std::uint64_t next_offset
Definition sort_profile.h:164
std::uint64_t key_units
Definition sort_profile.h:164
std::uint64_t retained
Definition sort_profile.h:164
Definition sort_profile_merge.h:66
sort_profile_merge_builder(Output output, source_pointer older, source_pointer newer, Compose compose={})
Definition sort_profile_merge.h:71
Output output_
Definition sort_profile_merge.h:119
std::uint64_t materialized_keys() const noexcept
Definition sort_profile_merge.h:78
sort_profile_detail::merge_source< view_type > left_
Definition sort_profile_merge.h:118
std::uint64_t materialized_keys_
Definition sort_profile_merge.h:122
Compose compose_
Definition sort_profile_merge.h:120
auto finish()
Definition sort_profile_merge.h:111
bool failed_
Definition sort_profile_merge.h:123
sort_profile_detail::merge_source< view_type > right_
Definition sort_profile_merge.h:118
bool failed() const noexcept
Definition sort_profile_merge.h:75
std::uint64_t left_common_
Definition sort_profile_merge.h:122
bool done() const noexcept
Definition sort_profile_merge.h:74
native_merge_progress step(std::uint64_t budget=1)
Definition sort_profile_merge.h:79
bool finished_
Definition sort_profile_merge.h:123
bool finished() const noexcept
Definition sort_profile_merge.h:76
source_pointer older_
Definition sort_profile_merge.h:117
source_pointer newer_
Definition sort_profile_merge.h:117
static std::uint64_t advance(auto &source)
Definition sort_profile_merge.h:136
native_merge_progress progress() const noexcept
Definition sort_profile_merge.h:77
std::shared_ptr< Native const > source_pointer
Definition sort_profile_merge.h:67
native_merge_progress progress_
Definition sort_profile_merge.h:121
decltype(std::declval< Native const & >().view()) view_type
Definition sort_profile_merge.h:68
bit_comparison compare() const
Definition sort_profile_merge.h:137
void append(sort_profile_detail::merge_source< view_type > const &source, std::uint64_t common, bit_view value, std::uint64_t limit)
Definition sort_profile_merge.h:124
std::uint64_t right_common_
Definition sort_profile_merge.h:122
static source_pointer checked(source_pointer value)
Definition sort_profile_merge.h:132
sort_profile_merge_builder(source_pointer older, source_pointer newer, Compose compose={})
Definition sort_profile_merge.h:69