2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
4 * This file is part of StormByte-Buffer.
6 * StormByte-Buffer original source is dual-licensed:
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
19 * Both licenses apply only to original StormByte-Buffer source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte-Logger tree and
23 * the rest of the StormByte suite it vendors), which remains under its own
26 * Neither license grants any patent rights. Any patent licenses required
27 * to use this software or third-party components must be obtained separately
28 * from the patent holders.
30 * StormByte-Buffer is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU Lesser General Public License for more details.
35 * You should have received a copy of the GNU Lesser General Public License
36 * version 3 along with StormByte-Buffer. If not, see
37 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
39 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
44#include <StormByte/safe/heap.hxx>
45#include <StormByte/safe/map.hxx>
46#include <StormByte/safe/mutex.hxx>
47#include <StormByte/safe/set.hxx>
48#include <StormByte/safe/unique_lock.hxx>
49#include <StormByte/safe/vector.hxx>
50#include <StormByte/type_traits.hxx>
57 * @namespace StormByte
58 * @brief Root namespace of the StormByte C++ suite.
62 * @namespace StormByte::Buffer
63 * @brief Buffer module of the StormByte suite.
67 * @class Sink<T>::Implementation
68 * @brief Internal implementation class for Sink.
70 * Manages the map of key-to-Hopper buckets, thread synchronization,
71 * wiring condition variables, and pop selection algorithms. The gate,
72 * the signal and the words live on Base's heap.
74 template<Detail::HopperValue T>
75 class Sink<T>::Implementation {
77 * @brief Base-owned shared hopper.
79 using HopperOwner = StormByte::Safe::Shared<Hopper<T>>;
81 * @brief Hopper snapshots. Position is the round-robin order.
83 using HopperOwners = StormByte::Safe::Vector<HopperOwner>;
85 * @brief Keyed hoppers. Iteration order is the ascending key order published by Keys.
87 using HopperBuckets = StormByte::Safe::Map<int, HopperOwner>;
89 * @brief Hoppers this Sink writes, ordered by hopper identity.
91 using HopperWriters = StormByte::Safe::Set<HopperOwner>;
95 * @brief Constructs the Sink Implementation instance.
96 * @throws AllocationError The gate, the signal or a word cannot be allocated.
99 : m_rr(std::size_t{0}), m_consumer(nullptr), m_generation(nullptr), m_closed(false), m_drain(false) {}
102 * @brief Removes borrowed observers, marks closed and wakes wiring waiters.
104 ~Implementation() noexcept {
106 m_closed.store(true, Safe::MemoryOrder::Release);
107 m_wired.notify_all();
111 * @brief Enqueues an item into the hopper for key.
112 * @param key Bucket key identifier.
113 * @param item Item to push.
115 void Push(int key, T item) noexcept {
116 if constexpr (Type::NullablePointer<T>) {
122 Safe::UniqueLock lock(m_mutex);
123 m_wired.wait(lock, [this, key] {
124 return m_closed.load(Safe::MemoryOrder::Acquire)
125 || m_drain.load(Safe::MemoryOrder::Acquire)
126 || m_buckets.find(key) != m_buckets.end();
128 auto found = m_buckets.find(key);
129 if (m_closed.load(Safe::MemoryOrder::Acquire) || found == m_buckets.end())
131 hopper = (*found).second;
135 hopper->Push(std::move(item));
139 * @brief Weighted admission; never holds the Sink registration mutex during waiting.
140 * @param key Existing bucket key.
141 * @param item Moved only on success.
142 * @param bytes Logical entry weight.
143 * @param lease Optional shared charge.
144 * @param timeout Bounded wait.
145 * @param observer Borrowed wait observer.
146 * @return Explicit admission result.
148 QueueStatus Admit(int key, T& item, StormByte::ByteSize bytes, const ByteBudget::Lease* lease,
149 std::chrono::milliseconds timeout, AdmissionWaitObserver observer = {}) noexcept {
150 if (m_closed.load(Safe::MemoryOrder::Acquire))
151 return QueueStatus::Closed;
152 const auto hopper = Bucket(key);
154 return QueueStatus::Missing;
155 return hopper->Admit(item, bytes, lease, timeout, &m_closed, observer);
159 * @brief Change local ceilings on the shared queue.
160 * @param key Existing bucket key.
161 * @param limits Local limits.
162 * @return Ok or Missing.
164 QueueStatus Limits(int key, QueueLimits limits) noexcept {
165 const auto hopper = Bucket(key);
167 return QueueStatus::Missing;
168 hopper->Limits(limits);
169 return QueueStatus::Ok;
173 * @brief Attach shared accounting to an empty, idle hopper.
174 * @param key Existing bucket key.
175 * @param limits Local ceilings.
176 * @param budget Shared accounting.
177 * @return Explicit configuration result.
179 QueueStatus Configure(int key, QueueLimits limits, const ByteBudget& budget) noexcept {
180 const auto hopper = Bucket(key);
181 return hopper ? hopper->Configure(limits, budget) : QueueStatus::Missing;
185 * @brief Read current queue accounting.
186 * @param key Existing bucket key.
187 * @return Coherent snapshot, or Exists false if missing.
189 QueueSnapshot Snapshot(int key) const noexcept {
190 const auto hopper = Bucket(key);
191 return hopper ? hopper->Snapshot() : QueueSnapshot{};
195 * @brief Cancel weighted waiters on one shared hopper.
196 * @param key Existing bucket key.
198 void CancelPending(int key) noexcept {
199 const auto hopper = Bucket(key);
201 hopper->CancelPending();
205 * @brief Closes this Sink and releases its tracked writer holds.
206 * @note Notifies the borrowed consumer while holding its registration lock.
207 * @note Does not allocate.
209 void Close() noexcept {
210 Safe::UniqueLock lock(m_mutex);
211 m_closed.store(true, Safe::MemoryOrder::Release);
212 m_wired.notify_all();
214 for (auto it = m_writers.begin(); it != m_writers.end(); ++it)
215 (*it)->CloseWriter();
217 for (auto it = m_buckets.begin(); it != m_buckets.end(); ++it)
218 (*it).second->WakePending();
222 * @brief Closes and drains every connected hopper without allocating.
224 void Abort() noexcept {
226 Safe::UniqueLock lock(m_mutex);
227 m_closed.store(true, Safe::MemoryOrder::Release);
228 m_wired.notify_all();
231 std::size_t index = 0;
235 Safe::UniqueLock lock(m_mutex);
236 if (index >= static_cast<std::size_t>(m_order.size()))
238 hopper = m_order[index++];
245 * @brief Shares all existing hoppers with consumer.
246 * @param consumer Consumer Sink implementation reference.
248 void Bind(Implementation& consumer) {
249 if (this == &consumer)
251 Safe::UniqueLock ours;
252 Safe::UniqueLock theirs;
253 LockPair(m_mutex, consumer.m_mutex, ours, theirs);
254 const bool closed = m_closed.load(Safe::MemoryOrder::Acquire)
255 || consumer.m_closed.load(Safe::MemoryOrder::Acquire);
256 Safe::ConditionVariable* cv = consumer.m_consumer;
257 for (auto it = m_buckets.begin(); it != m_buckets.end(); ++it) {
258 consumer.RemoveObserver((*it).first, (*it).second);
262 (*it).second->Notify(*cv, &consumer, consumer.m_generation);
263 consumer.m_buckets[(*it).first] = (*it).second;
266 consumer.m_closed.store(true, Safe::MemoryOrder::Release);
267 consumer.RebuildOrder();
268 consumer.m_wired.notify_all();
269 consumer.SignalConsumer();
270 m_wired.notify_all();
274 * @brief Creates or shares the hopper for key with consumer.
275 * @param key Bucket key.
276 * @param consumer Consumer Sink implementation reference.
277 * @note Adds any extra writer while both Sink registration locks are held.
279 void Bind(int key, Implementation& consumer) {
280 if (this == &consumer)
282 Safe::UniqueLock ours;
283 Safe::UniqueLock theirs;
284 LockPair(m_mutex, consumer.m_mutex, ours, theirs);
285 const bool closed = m_closed.load(Safe::MemoryOrder::Acquire)
286 || consumer.m_closed.load(Safe::MemoryOrder::Acquire);
287 Safe::ConditionVariable* cv = consumer.m_consumer;
288 const bool existed = m_buckets.contains(key);
289 auto hopper = Ensure(key);
290 const bool already_writer = existed && consumer.m_writers.contains(hopper);
291 if (existed && !already_writer && !closed) {
292 consumer.m_writers.insert(hopper);
295 consumer.RemoveObserver(key, hopper);
299 hopper->Notify(*cv, &consumer, consumer.m_generation);
300 consumer.m_buckets[key] = hopper;
302 consumer.m_closed.store(true, Safe::MemoryOrder::Release);
303 consumer.RebuildOrder();
304 consumer.m_wired.notify_all();
305 consumer.SignalConsumer();
306 m_wired.notify_all();
310 * @brief Sets Drain mode.
312 void Drain() noexcept {
314 Safe::UniqueLock lock(m_mutex);
315 m_drain.store(true, Safe::MemoryOrder::Release);
317 m_wired.notify_all();
321 * @brief Checks if Drain was set.
322 * @return true if draining.
324 bool Draining() const noexcept {
325 return m_drain.load(Safe::MemoryOrder::Acquire);
329 * @brief Registers condition variable for consumer notifications.
330 * @param consumer Condition variable reference.
331 * @param generation Optional borrowed stored-event counter.
333 void Notify(Safe::ConditionVariable& consumer, Safe::Atomic<std::size_t>* generation = nullptr) noexcept {
334 Safe::UniqueLock lock(m_mutex);
335 m_consumer = &consumer;
336 m_generation = generation;
337 for (auto it = m_order.begin(); it != m_order.end(); ++it)
338 (*it)->Notify(consumer, this, generation);
342 * @brief Drops the consumer condition variable on this Sink and its hoppers.
344 void Unnotify() noexcept {
345 Safe::UniqueLock lock(m_mutex);
346 m_consumer = nullptr;
347 m_generation = nullptr;
348 for (auto it = m_order.begin(); it != m_order.end(); ++it) {
350 (*it)->Unnotify(this);
355 * @brief Snapshot of wired keys in map order.
356 * @return Keys, empty if none.
358 StormByte::Safe::Vector<int> Keys() const noexcept {
359 Safe::UniqueLock lock(m_mutex);
360 StormByte::Safe::Vector<int> keys;
361 keys.reserve(m_buckets.size());
362 for (auto it = m_buckets.begin(); it != m_buckets.end(); ++it)
363 keys.push_back((*it).first);
368 * @brief Number of wired hoppers.
369 * @return Bucket count.
371 StormByte::Size Buckets() const noexcept {
372 Safe::UniqueLock lock(m_mutex);
373 return StormByte::Size{m_buckets.size()};
377 * @brief Whether key is wired.
378 * @param key Bucket key.
379 * @return true if present.
381 bool Contains(int key) const noexcept {
382 return static_cast<bool>(Bucket(key));
386 * @brief Gets capacity of key hopper.
387 * @param key Bucket key.
388 * @return Capacity value.
390 StormByte::Size Capacity(int key) const noexcept {
391 const auto hopper = Bucket(key);
393 return StormByte::Size{0};
394 return hopper->Capacity();
398 * @brief Sets capacity of key hopper.
399 * @param key Bucket key.
400 * @param capacity New capacity.
402 void Capacity(int key, StormByte::Size capacity) noexcept {
403 Safe::UniqueLock lock(m_mutex);
404 auto found = m_buckets.find(key);
405 if (found != m_buckets.end() && (*found).second)
406 (*found).second->Capacity(capacity);
410 * @brief Gets pending item count of key hopper.
411 * @param key Bucket key.
412 * @return Item count.
414 StormByte::Size Size(int key) const noexcept {
415 const auto hopper = Bucket(key);
417 return StormByte::Size{0};
418 return hopper->Size();
422 * @brief Checks if key hopper is full.
423 * @param key Bucket key.
424 * @return true if full.
426 bool Full(int key) const noexcept {
427 const auto hopper = Bucket(key);
430 return hopper->Full();
434 * @brief Whether key hopper has no items.
435 * @param key Bucket key.
436 * @return true if missing or empty.
438 bool Empty(int key) const noexcept {
439 const auto hopper = Bucket(key);
442 return hopper->Empty();
446 * @brief Whether producers marked Eof on key hopper.
447 * @param key Bucket key.
448 * @return Hopper EoF, or false if missing.
450 bool EoF(int key) const noexcept {
451 const auto hopper = Bucket(key);
454 return hopper->EoF();
458 * @brief Whether key hopper has an item or is finished.
459 * @param key Bucket key.
460 * @return false if missing.
462 bool Ready(int key) const noexcept {
463 const auto hopper = Bucket(key);
466 return !hopper->Empty() || hopper->EoF();
470 * @brief Copy of front item of key hopper. Does not dequeue.
471 * @param key Bucket key.
472 * @return Front or default T.
474 T Front(int key) const noexcept requires Type::CopyConstructible<T> && std::is_nothrow_copy_constructible_v<T> {
475 const auto hopper = Bucket(key);
478 return hopper->Front();
482 * @brief Pops item using default selection.
483 * @return Popped item or default T.
490 * @brief Pops item using specified selection function.
491 * @param select Borrowed bucket index chooser, or null for round-robin.
492 * @return Popped item or default T.
494 T Pop(const typename Sink<T>::Select* select) noexcept {
495 return Pop([select](StormByte::Size& output, StormByte::Size count) {
496 return select ? select->Call(output, count) : StormByte::Safe::Status::Success;
497 }, select == nullptr);
501 * @brief Pops using a synchronous chooser without retaining or copying its captures.
502 * @tparam Selector Callable writing a bucket index and returning a Safe status.
503 * @param select Borrowed chooser, invoked before any item is removed.
504 * @param round_robin Whether to use the default order instead of invoking the chooser.
505 * @return Popped item, or default T on failure, exception or empty buckets.
507 template<typename Selector>
508 T Pop(Selector&& select, bool round_robin) noexcept {
509 HopperOwners hoppers;
511 Safe::UniqueLock lock(m_mutex);
512 m_wired.wait(lock, [this] {
513 return m_closed.load(Safe::MemoryOrder::Acquire) || !m_order.empty();
519 const std::size_t count = static_cast<std::size_t>(hoppers.size());
520 std::size_t start = 0;
523 StormByte::Size output{0};
524 if (std::invoke(select, output, StormByte::Size{count}) != StormByte::Safe::Status::Success)
526 start = static_cast<std::size_t>(output) % count;
533 start = m_rr.fetch_add(std::size_t{1}, Safe::MemoryOrder::Relaxed) % count;
536 for (std::size_t offset = 0; offset < count; ++offset) {
537 const auto& hopper = hoppers[(start + offset) % count];
538 if (!hopper->Empty())
539 return hopper->Pop();
545 * @brief Pops from one key only.
546 * @param key Bucket key.
547 * @return Item or default T.
549 T Pop(int key) noexcept {
552 Safe::UniqueLock lock(m_mutex);
553 m_wired.wait(lock, [this, key] {
554 return m_closed.load(Safe::MemoryOrder::Acquire)
555 || m_buckets.contains(key);
557 auto found = m_buckets.find(key);
558 if (found == m_buckets.end() || !(*found).second)
560 hopper = (*found).second;
562 return hopper->Pop();
566 * @brief Checks if Sink is finished.
567 * @return true if closed and all hoppers drained.
569 bool EoF() const noexcept {
570 const auto hoppers = Order();
572 return m_closed.load(Safe::MemoryOrder::Acquire);
573 for (auto it = hoppers.begin(); it != hoppers.end(); ++it) {
583 * @brief Checks if Pop can return immediately.
584 * @return true if item is ready or EoF reached.
586 bool Ready() const noexcept {
587 const auto hoppers = Order();
589 return m_closed.load(Safe::MemoryOrder::Acquire);
591 for (auto it = hoppers.begin(); it != hoppers.end(); ++it) {
602 * @brief Locks two gates in address order.
603 * @param left First gate.
604 * @param right Second gate.
605 * @param first Lock that owns the lower address.
606 * @param second Lock that owns the higher address.
608 static void LockPair(Safe::Mutex& left, Safe::Mutex& right, Safe::UniqueLock& first, Safe::UniqueLock& second) {
609 if (&left < &right) {
610 first = Safe::UniqueLock(left);
611 second = Safe::UniqueLock(right);
614 first = Safe::UniqueLock(right);
615 second = Safe::UniqueLock(left);
619 * @brief Publishes a consumer event after state changes. Caller holds m_mutex.
621 void SignalConsumer() noexcept {
622 if (m_generation != nullptr) {
623 m_generation->fetch_add(std::size_t{1}, Safe::MemoryOrder::Release);
624 m_generation->notify_all();
626 if (m_consumer != nullptr)
627 m_consumer->notify_all();
631 * @brief Removes this registration from a replaced hopper. Caller holds m_mutex.
632 * @param key Bucket being rebound.
633 * @param replacement New hopper whose observer must not be removed.
635 void RemoveObserver(int key, const HopperOwner& replacement) noexcept {
636 const auto found = m_buckets.find(key);
637 if (found == m_buckets.end() || (*found).second == replacement)
639 for (auto it = m_buckets.begin(); it != m_buckets.end(); ++it) {
640 if ((*it).first != key && (*it).second == (*found).second)
643 (*found).second->Unnotify(this);
647 * @brief Ensures hopper for key exists. Caller holds m_mutex.
648 * @param key Bucket key.
649 * @return Shared hopper instance.
651 HopperOwner Ensure(int key) {
652 auto found = m_buckets.find(key);
653 if (found != m_buckets.end())
654 return (*found).second;
655 auto hopper = HopperOwner::template MakePointer<Hopper<T>>();
656 Safe::ConditionVariable* cv = m_consumer;
658 hopper->Notify(*cv, this, m_generation);
659 m_buckets.emplace(key, hopper);
660 m_writers.insert(hopper);
666 * @brief Rebuilds order vector from m_buckets. Caller holds m_mutex.
668 void RebuildOrder() {
670 m_order.reserve(m_buckets.size());
671 for (auto it = m_buckets.begin(); it != m_buckets.end(); ++it)
672 m_order.push_back((*it).second);
676 * @brief Returns snapshot of current hoppers in order.
677 * @return Vector of hoppers.
679 HopperOwners Order() const {
680 Safe::UniqueLock lock(m_mutex);
685 * @brief Retrieves hopper for key.
686 * @param key Bucket key.
687 * @return Hopper pointer or nullptr.
689 HopperOwner Bucket(int key) const {
690 Safe::UniqueLock lock(m_mutex);
691 auto found = m_buckets.find(key);
692 if (found == m_buckets.end())
694 return (*found).second;
698 * @brief Guards buckets, order, observer registration and direct notification.
700 mutable Safe::Mutex m_mutex;
702 * @brief Waits for bucket binding or closure.
704 Safe::ConditionVariable m_wired;
706 * @brief Base-owned map of keys to Base-owned hoppers.
708 HopperBuckets m_buckets;
710 * @brief Base-owned set of hoppers this Sink writes.
712 HopperWriters m_writers;
714 * @brief Base-owned hopper order for Pop.
716 HopperOwners m_order;
718 * @brief Round-robin counter.
720 Safe::Atomic<std::size_t> m_rr;
722 * @brief Borrowed consumer condition variable guarded by m_mutex.
724 Safe::ConditionVariable* m_consumer;
726 * @brief Borrowed event counter guarded by m_mutex.
728 Safe::Atomic<std::size_t>* m_generation;
730 * @brief Closed flag.
732 Safe::Atomic<bool> m_closed;
734 * @brief Drain mode flag.
736 Safe::Atomic<bool> m_drain;
739 template<Detail::HopperValue T>
741 : m_io(::new (StormByte::Safe::Heap::Allocate(sizeof(Implementation))) Implementation()),
742 m_owner(m_io, nullptr, [](void* context) noexcept {
743 static_cast<Implementation*>(context)->~Implementation();
744 StormByte::Safe::Heap::Free(context);
746 static_assert(alignof(Implementation) <= __STDCPP_DEFAULT_NEW_ALIGNMENT__);
749 template<Detail::HopperValue T>
750 Sink<T>::~Sink() noexcept {
755 template<Detail::HopperValue T>
756 void Sink<T>::Push(int key, T item) noexcept {
757 m_io->Push(key, std::move(item));
760 template<Detail::HopperValue T>
761 QueueStatus Sink<T>::TryPush(int key, T& item, StormByte::ByteSize bytes) noexcept {
762 return m_io->Admit(key, item, bytes, nullptr, std::chrono::milliseconds{0});
765 template<Detail::HopperValue T>
766 QueueStatus Sink<T>::TryPush(int key, T& item, const ByteBudget::Lease& lease) noexcept {
767 return m_io->Admit(key, item, lease.Bytes(), &lease, std::chrono::milliseconds{0});
770 template<Detail::HopperValue T>
771 QueueStatus Sink<T>::PushFor(int key, T& item, StormByte::ByteSize bytes, std::chrono::milliseconds timeout,
772 AdmissionWaitObserver observer) noexcept {
773 return m_io->Admit(key, item, bytes, nullptr, timeout, observer);
776 template<Detail::HopperValue T>
777 QueueStatus Sink<T>::PushFor(int key, T& item, const ByteBudget::Lease& lease,
778 std::chrono::milliseconds timeout, AdmissionWaitObserver observer) noexcept {
779 return m_io->Admit(key, item, lease.Bytes(), &lease, timeout, observer);
782 template<Detail::HopperValue T>
783 QueueStatus Sink<T>::Limits(int key, QueueLimits limits) noexcept {
784 return m_io->Limits(key, limits);
787 template<Detail::HopperValue T>
788 QueueStatus Sink<T>::Configure(int key, QueueLimits limits, const ByteBudget& budget) noexcept {
789 return m_io->Configure(key, limits, budget);
792 template<Detail::HopperValue T>
793 QueueSnapshot Sink<T>::Snapshot(int key) const noexcept {
794 return m_io->Snapshot(key);
797 template<Detail::HopperValue T>
798 void Sink<T>::CancelPending(int key) noexcept {
799 m_io->CancelPending(key);
802 template<Detail::HopperValue T>
803 void Sink<T>::Eof() noexcept {
807 template<Detail::HopperValue T>
808 void Sink<T>::Abort() noexcept {
812 template<Detail::HopperValue T>
813 Sink<T>::Lane::Lane(Sink& from, int key) noexcept
814 : m_from(&from), m_key(key) {}
816 template<Detail::HopperValue T>
817 typename Sink<T>::Lane Sink<T>::To(int key) noexcept {
818 return Lane(*this, key);
821 template<Detail::HopperValue T>
822 Sink<T>& Sink<T>::Lane::operator>>(Sink& dest) noexcept {
823 m_from->m_io->Bind(m_key, *dest.m_io);
827 template<Detail::HopperValue T>
828 Sink<T>& Sink<T>::operator>>(Sink& dest) noexcept {
829 m_io->Bind(*dest.m_io);
833 template<Detail::HopperValue T>
834 Sink<T>& Sink<T>::operator<<(Sink& src) noexcept {
839 template<Detail::HopperValue T>
840 Sink<T>& Sink<T>::operator<<(Lane lane) noexcept {
845 template<Detail::HopperValue T>
846 void Sink<T>::Drain() noexcept {
850 template<Detail::HopperValue T>
851 bool Sink<T>::Draining() const noexcept {
852 return m_io->Draining();
855 template<Detail::HopperValue T>
856 void Sink<T>::Notify(Safe::ConditionVariable& consumer) noexcept {
857 m_io->Notify(consumer);
860 template<Detail::HopperValue T>
861 void Sink<T>::Notify(Safe::ConditionVariable& consumer, Safe::Atomic<std::size_t>& generation) noexcept {
862 m_io->Notify(consumer, &generation);
865 template<Detail::HopperValue T>
866 void Sink<T>::Unnotify() noexcept {
870 template<Detail::HopperValue T>
871 StormByte::Safe::Vector<int> Sink<T>::Keys() const noexcept {
875 template<Detail::HopperValue T>
876 StormByte::Size Sink<T>::Buckets() const noexcept {
877 return m_io->Buckets();
880 template<Detail::HopperValue T>
881 bool Sink<T>::Contains(int key) const noexcept {
882 return m_io->Contains(key);
885 template<Detail::HopperValue T>
886 StormByte::Size Sink<T>::Capacity(int key) const noexcept {
887 return m_io->Capacity(key);
890 template<Detail::HopperValue T>
891 void Sink<T>::Capacity(int key, StormByte::Size capacity) noexcept {
892 m_io->Capacity(key, capacity);
895 template<Detail::HopperValue T>
896 StormByte::Size Sink<T>::Size(int key) const noexcept {
897 return m_io->Size(key);
900 template<Detail::HopperValue T>
901 bool Sink<T>::Full(int key) const noexcept {
902 return m_io->Full(key);
905 template<Detail::HopperValue T>
906 bool Sink<T>::Empty(int key) const noexcept {
907 return m_io->Empty(key);
910 template<Detail::HopperValue T>
911 bool Sink<T>::EoF(int key) const noexcept {
912 return m_io->EoF(key);
915 template<Detail::HopperValue T>
916 bool Sink<T>::Ready(int key) const noexcept {
917 return m_io->Ready(key);
920 template<Detail::HopperValue T>
921 T Sink<T>::Front(int key) const noexcept requires Type::CopyConstructible<T> && std::is_nothrow_copy_constructible_v<T> {
922 return m_io->Front(key);
925 template<Detail::HopperValue T>
926 T Sink<T>::Pop() noexcept {
930 template<Detail::HopperValue T>
931 T Sink<T>::Pop(const Select& select) noexcept {
932 return m_io->Pop(&select);
935 template<Detail::HopperValue T>
936 template<typename Selector>
937 requires (!Type::SameAs<std::remove_cvref_t<Selector>, typename Sink<T>::Select>) &&
938 requires(Selector& select, StormByte::Size count) {
939 { std::invoke(select, count) } -> Type::SameAs<StormByte::Size>;
941 T Sink<T>::Pop(Selector&& select) noexcept {
942 return m_io->Pop([&select](StormByte::Size& output, StormByte::Size count) {
943 output = std::invoke(select, count);
944 return StormByte::Safe::Status::Success;
948 template<Detail::HopperValue T>
949 T Sink<T>::Pop(int key) noexcept {
950 return m_io->Pop(key);
953 template<Detail::HopperValue T>
954 bool Sink<T>::EoF() const noexcept {
958 template<Detail::HopperValue T>
959 bool Sink<T>::Ready() const noexcept {
960 return m_io->Ready();