9#include <unordered_set>
22 SessionKey(
const char* s) : ptr_(s ? intern(s) : &empty_string()) {}
23 SessionKey(
const char* s, std::size_t count) : ptr_(intern(
std::string_view(s, count))) {}
39 ptr_ = s ? intern(s) : &empty_string();
43 void clear() noexcept { ptr_ = &empty_string(); }
44 bool empty() const noexcept {
return ptr_->empty(); }
45 std::size_t
size() const noexcept {
return ptr_->size(); }
46 std::size_t
length() const noexcept {
return ptr_->length(); }
47 const char*
c_str() const noexcept {
return ptr_->c_str(); }
48 const char*
data() const noexcept {
return ptr_->data(); }
50 const std::string&
string() const noexcept {
return *ptr_; }
51 operator const std::string&()
const noexcept {
return *ptr_; }
53 char operator[](std::size_t i)
const noexcept {
return (*ptr_)[i]; }
60 *
this =
SessionKey(*ptr_ + (extra ? extra :
""));
68 bool operator==(
const std::string& other)
const noexcept {
return *ptr_ == other; }
69 bool operator!=(
const std::string& other)
const noexcept {
return *ptr_ != other; }
70 bool operator<(
const std::string& other)
const noexcept {
return *ptr_ < other; }
72 bool operator==(std::string_view other)
const noexcept {
return *ptr_ == other; }
73 bool operator!=(std::string_view other)
const noexcept {
return *ptr_ != other; }
76 return other ? *ptr_ == other : ptr_->empty();
78 bool operator!=(
const char* other)
const noexcept {
return !(*
this == other); }
85 return a ? a == *b.ptr_ : b.ptr_->empty();
92 friend std::string
operator+(
const char* a,
const SessionKey& b) {
return (a ? a :
"") + b.string(); }
96 return os << *key.ptr_;
101 out.append(
reinterpret_cast<const char*
>(&
size),
sizeof(
size));
102 out.append(value.
data(), value.
size());
106 static const std::string& empty_string() {
107 static const std::string
empty;
111 static const std::string* intern(std::string_view s) {
112 if (s.empty())
return &empty_string();
113 static std::mutex mutex;
114 static std::unordered_set<std::string> pool;
115 std::lock_guard<std::mutex> lock(mutex);
116 auto it = pool.find(std::string(s));
117 if (it != pool.end())
return &*it;
118 auto [inserted, _] = pool.emplace(s);
122 const std::string* ptr_ = &empty_string();
157 uint64_t point_ordinal,
158 int64_t effective_time_ms)
noexcept {
159 return point_ordinal > birth.acceptance_ordinal
160 && effective_time_ms >= birth.decision_time_lower_bound;
163static_assert(std::is_nothrow_move_constructible_v<RunIdentity>);
164static_assert(std::is_nothrow_move_assignable_v<RunIdentity>);
165static_assert(std::is_nothrow_move_constructible_v<RequestHandle>);
166static_assert(std::is_nothrow_move_assignable_v<RequestHandle>);
167static_assert(std::is_nothrow_move_constructible_v<Birth>);
SessionKey & operator+=(const char *extra)
friend std::ostream & operator<<(std::ostream &os, const SessionKey &key)
char operator[](std::size_t i) const noexcept
SessionKey & operator=(const char *s)
friend bool operator==(const char *a, const SessionKey &b) noexcept
SessionKey & operator+=(const std::string &extra)
bool operator==(const char *other) const noexcept
SessionKey(const char *s)
bool operator!=(const char *other) const noexcept
bool operator!=(std::string_view other) const noexcept
SessionKey(const char *s, std::size_t count)
bool operator<(const SessionKey &other) const noexcept
bool empty() const noexcept
const char * data() const noexcept
friend bool operator!=(const std::string &a, const SessionKey &b) noexcept
SessionKey(const std::string &s)
const char * c_str() const noexcept
bool operator<(const std::string &other) const noexcept
SessionKey(std::string_view s)
std::size_t length() const noexcept
friend std::string operator+(const std::string &a, const SessionKey &b)
bool operator!=(const std::string &other) const noexcept
friend bool operator==(const std::string &a, const SessionKey &b) noexcept
const std::string & string() const noexcept
friend std::string operator+(const char *a, const SessionKey &b)
bool operator==(const SessionKey &other) const noexcept
friend std::string operator+(const SessionKey &a, const char *b)
bool operator!=(const SessionKey &other) const noexcept
friend bool operator<(const std::string &a, const SessionKey &b) noexcept
friend bool operator!=(const char *a, const SessionKey &b) noexcept
SessionKey(SessionKey &&) noexcept=default
friend std::string operator+(const SessionKey &a, const std::string &b)
bool operator==(const std::string &other) const noexcept
friend void append(std::string &out, const SessionKey &value)
friend std::string operator+(const SessionKey &a, const SessionKey &b)
SessionKey & operator=(const SessionKey &) noexcept=default
SessionKey & operator=(std::string_view s)
std::size_t size() const noexcept
SessionKey(const SessionKey &) noexcept=default
bool operator==(std::string_view other) const noexcept
bool operator==(const RunIdentity &a, const RunIdentity &b)
bool point_eligible(const Birth &birth, uint64_t point_ordinal, int64_t effective_time_ms) noexcept
bool operator!=(const RunIdentity &a, const RunIdentity &b)
uint64_t acceptance_ordinal
int64_t decision_time_lower_bound