aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/containers/ring_buffer/ring_buffer.h
diff options
context:
space:
mode:
authormowgli <mowgli@yandex-team.ru>2022-02-10 16:49:25 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:25 +0300
commit56c39b3cf908e7202b1f7551a1653681e8015607 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/containers/ring_buffer/ring_buffer.h
parent89afbbe4ca0e02e386dd4df08f7945f190dc1b84 (diff)
downloadydb-56c39b3cf908e7202b1f7551a1653681e8015607.tar.gz
Restoring authorship annotation for <mowgli@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/containers/ring_buffer/ring_buffer.h')
-rw-r--r--library/cpp/containers/ring_buffer/ring_buffer.h134
1 files changed, 67 insertions, 67 deletions
diff --git a/library/cpp/containers/ring_buffer/ring_buffer.h b/library/cpp/containers/ring_buffer/ring_buffer.h
index e1f232712c..41220dcf6b 100644
--- a/library/cpp/containers/ring_buffer/ring_buffer.h
+++ b/library/cpp/containers/ring_buffer/ring_buffer.h
@@ -1,81 +1,81 @@
-#pragma once
-
-#include <util/generic/vector.h>
-#include <util/system/yassert.h>
-
-template <typename T>
-class TSimpleRingBuffer {
-public:
- TSimpleRingBuffer(size_t maxSize)
- : MaxSize(maxSize)
- {
- Items.reserve(MaxSize);
- }
-
+#pragma once
+
+#include <util/generic/vector.h>
+#include <util/system/yassert.h>
+
+template <typename T>
+class TSimpleRingBuffer {
+public:
+ TSimpleRingBuffer(size_t maxSize)
+ : MaxSize(maxSize)
+ {
+ Items.reserve(MaxSize);
+ }
+
TSimpleRingBuffer(const TSimpleRingBuffer&) = default;
TSimpleRingBuffer(TSimpleRingBuffer&&) = default;
TSimpleRingBuffer& operator=(const TSimpleRingBuffer&) = default;
TSimpleRingBuffer& operator=(TSimpleRingBuffer&&) = default;
- // First available item
- size_t FirstIndex() const {
- return Begin;
- }
-
- size_t AvailSize() const {
- return Items.size();
- }
-
- // Total number of items inserted
- size_t TotalSize() const {
- return FirstIndex() + AvailSize();
- }
-
- bool IsAvail(size_t index) const {
- return index >= FirstIndex() && index < TotalSize();
- }
-
- const T& operator[](size_t index) const {
+ // First available item
+ size_t FirstIndex() const {
+ return Begin;
+ }
+
+ size_t AvailSize() const {
+ return Items.size();
+ }
+
+ // Total number of items inserted
+ size_t TotalSize() const {
+ return FirstIndex() + AvailSize();
+ }
+
+ bool IsAvail(size_t index) const {
+ return index >= FirstIndex() && index < TotalSize();
+ }
+
+ const T& operator[](size_t index) const {
Y_ASSERT(IsAvail(index));
- return Items[RealIndex(index)];
- }
-
- T& operator[](size_t index) {
+ return Items[RealIndex(index)];
+ }
+
+ T& operator[](size_t index) {
Y_ASSERT(IsAvail(index));
- return Items[RealIndex(index)];
- }
-
- void PushBack(const T& t) {
- if (Items.size() < MaxSize) {
- Items.push_back(t);
- } else {
- Items[RealIndex(Begin)] = t;
- Begin += 1;
- }
- }
-
+ return Items[RealIndex(index)];
+ }
+
+ void PushBack(const T& t) {
+ if (Items.size() < MaxSize) {
+ Items.push_back(t);
+ } else {
+ Items[RealIndex(Begin)] = t;
+ Begin += 1;
+ }
+ }
+
void Clear() {
Items.clear();
Begin = 0;
}
-private:
- size_t RealIndex(size_t index) const {
- return index % MaxSize;
- }
-
-private:
- size_t MaxSize;
- size_t Begin = 0;
+private:
+ size_t RealIndex(size_t index) const {
+ return index % MaxSize;
+ }
+
+private:
+ size_t MaxSize;
+ size_t Begin = 0;
TVector<T> Items;
-};
-
-template <typename T, size_t maxSize>
-class TStaticRingBuffer: public TSimpleRingBuffer<T> {
-public:
- TStaticRingBuffer()
- : TSimpleRingBuffer<T>(maxSize)
- {
- }
-};
+};
+
+template <typename T, size_t maxSize>
+class TStaticRingBuffer: public TSimpleRingBuffer<T> {
+public:
+ TStaticRingBuffer()
+ : TSimpleRingBuffer<T>(maxSize)
+ {
+ }
+};