xo-arena: CircularBuffer utest + bugfixes

This commit is contained in:
Roland Conybeare 2026-01-11 16:54:30 -05:00
commit 516b57ae81
6 changed files with 114 additions and 10 deletions

View file

@ -20,6 +20,7 @@ namespace xo {
/** optional name, for diagnostics **/
std::string name_;
/** hard maximum buffer size = reserved virtual memory.
* However actual max will be this value rounded up to at least page size.
* Buffer will generally map much less than this amount of memory
**/
std::size_t max_capacity_ = 0;

View file

@ -79,6 +79,7 @@ namespace xo {
const_span_type reserved_range() const noexcept { return reserved_range_; }
const_span_type mapped_range() const noexcept { return mapped_range_; }
const_span_type occupied_range() const noexcept { return occupied_range_; }
const_span_type input_range() const noexcept { return input_range_; }
/** verify DCircularBuffer invariants.
* Act on failure according to policy @p p
@ -98,6 +99,8 @@ namespace xo {
/** @defgroup mm-circularbuffer-nonconst-methods CircularBuffer non-const methods **/
///@{
span_type input_range() noexcept { return input_range_; }
/** copy memory in span @p r into buffer starting at the end of
* @ref occupied_range_. Map new physical memory as needed.
* On success returns empty suffix of @p r.
@ -139,7 +142,7 @@ namespace xo {
* Caller represents that it won't need to read this memory again
* unless overlaps with a pinned span.
**/
void consume(span_type r);
void consume(const_span_type input);
/** pin memory range @p r. circular buffer will not touch
* addresses that appear in any pinned range.

View file

@ -28,6 +28,9 @@ namespace xo {
/** typealias for span size (in units of CharT) **/
using size_type = std::uint64_t;
/** typealias for span elements **/
using value_type = CharT;
///@}
public:
@ -58,7 +61,8 @@ namespace xo {
* A null span can be concatenated with any other span
* without triggering matching-endpoint asserts.
**/
static span make_null() { return span(static_cast<CharT*>(nullptr), static_cast<CharT*>(nullptr)); }
static span make_null() { return span(static_cast<CharT*>(nullptr),
static_cast<CharT*>(nullptr)); }
/** @brief create span for C-style string @p cstr **/
static span from_cstr(const CharT * cstr) {
@ -69,13 +73,21 @@ namespace xo {
}
/** @brief create span from std::string @p str **/
static span from_string(const std::string& str) {
static span from_string(const std::string & str) {
CharT * lo = &(*str.begin());
CharT * hi = &(*str.end());
return span(lo, hi);
}
/** @brief create span from std::string @p str **/
static span from_string_view(const std::string_view & sv) {
CharT * lo = &(*sv.begin());
CharT * hi = &(*sv.end());
return span(lo, hi);
}
/** @brief concatenate two contiguous spans */
static span concat(const span & span1, const span & span2) {
if (span1.is_null())
@ -119,6 +131,11 @@ namespace xo {
return (other.lo() <= lo_) && (hi_ <= other.hi());
}
/** convert to string view **/
std::string_view to_string_view() const {
return std::string_view((const char *)lo_, (const char *)hi_);
}
///@}
/** @defgroup span-general-methods **/