-
Notifications
You must be signed in to change notification settings - Fork 1
Add segmented sliding-window storage #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #pragma once | ||
|
|
||
| /** | ||
| * @file split_span.h | ||
| * @brief Allocation-free logical ranges split across at most two spans. | ||
| */ | ||
|
|
||
| #include <array> | ||
| #include <cstddef> | ||
| #include <span> | ||
|
|
||
| namespace pixie { | ||
|
|
||
| /** | ||
| * @brief A logical contiguous sequence stored in at most two physical spans. | ||
| * | ||
| * @details Empty input spans are canonicalized away. Iteration visits only | ||
| * non-empty physical spans in logical order. The descriptor owns no elements; | ||
| * its spans follow the lifetime and invalidation rules of their backing | ||
| * storage. | ||
| * | ||
| * @tparam T Viewed element type, optionally const-qualified. | ||
| */ | ||
| template <class T> | ||
| class SplitSpan { | ||
| public: | ||
| using span_type = std::span<T>; | ||
| using const_iterator = typename std::array<span_type, 2>::const_iterator; | ||
|
|
||
| /** @brief Construct an empty logical range. */ | ||
| constexpr SplitSpan() = default; | ||
|
|
||
| /** @brief Construct a range stored in one physical span. */ | ||
| constexpr explicit SplitSpan(span_type segment) | ||
| : segments_{segment, {}}, segment_count_(segment.empty() ? 0 : 1) {} | ||
|
|
||
| /** @brief Construct a range stored in up to two physical spans. */ | ||
| constexpr SplitSpan(span_type first, span_type second) { | ||
| if (first.empty()) { | ||
| first = second; | ||
| second = {}; | ||
| } | ||
| segments_ = {first, second}; | ||
| segment_count_ = static_cast<std::size_t>(!first.empty()) + | ||
| static_cast<std::size_t>(!second.empty()); | ||
| } | ||
|
|
||
| /** @brief Return the total number of logical elements. */ | ||
| constexpr std::size_t size() const noexcept { | ||
| return segments_[0].size() + segments_[1].size(); | ||
| } | ||
|
|
||
| /** @brief Return whether the logical range is empty. */ | ||
| constexpr bool empty() const noexcept { return segment_count_ == 0; } | ||
|
|
||
| /** @brief Return the number of non-empty physical segments. */ | ||
| constexpr std::size_t segment_count() const noexcept { | ||
| return segment_count_; | ||
| } | ||
|
|
||
| /** @brief Iterate over the non-empty physical segments in logical order. */ | ||
| constexpr const_iterator begin() const noexcept { return segments_.begin(); } | ||
|
|
||
| /** @brief Return the end iterator for the non-empty physical segments. */ | ||
| constexpr const_iterator end() const noexcept { | ||
| return segments_.begin() + static_cast<std::ptrdiff_t>(segment_count_); | ||
| } | ||
|
|
||
| private: | ||
| std::array<span_type, 2> segments_{}; | ||
| std::size_t segment_count_ = 0; | ||
| }; | ||
|
|
||
| } // namespace pixie |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add canonical Doxygen contracts for
begin_position_impl(),end_position_impl(), and bothsegments_impl()variants. The facade now requires these hooks—and serialization depends on them—but only documents the public wrappers, leaving implementers without the required invariants for absolute positions, range validation, segment ordering, and lifetime/invalidation behavior. Concrete-class comments do not replace the CRTP extension-point contract.AGENTS.md reference: AGENTS.md:L86-L92
Useful? React with 👍 / 👎.