summaryrefslogtreecommitdiffstats
path: root/ml/BitBufferCounter.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-12-01 06:15:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-12-01 06:15:04 +0000
commite970e0b37b8bd7f246feb3f70c4136418225e434 (patch)
tree0b67c0ca45f56f2f9d9c5c2e725279ecdf52d2eb /ml/BitBufferCounter.cc
parentAdding upstream version 1.31.0. (diff)
downloadnetdata-e970e0b37b8bd7f246feb3f70c4136418225e434.tar.xz
netdata-e970e0b37b8bd7f246feb3f70c4136418225e434.zip
Adding upstream version 1.32.0.upstream/1.32.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ml/BitBufferCounter.cc')
-rw-r--r--ml/BitBufferCounter.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/ml/BitBufferCounter.cc b/ml/BitBufferCounter.cc
new file mode 100644
index 000000000..5e1ab5aca
--- /dev/null
+++ b/ml/BitBufferCounter.cc
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "BitBufferCounter.h"
+
+using namespace ml;
+
+std::vector<bool> BitBufferCounter::getBuffer() const {
+ std::vector<bool> Buffer;
+
+ for (size_t Idx = start(); Idx != (start() + size()); Idx++)
+ Buffer.push_back(V[Idx % V.size()]);
+
+ return Buffer;
+}
+
+void BitBufferCounter::insert(bool Bit) {
+ if (N >= V.size())
+ NumSetBits -= (V[start()] == true);
+
+ NumSetBits += (Bit == true);
+ V[N++ % V.size()] = Bit;
+}
+
+void BitBufferCounter::print(std::ostream &OS) const {
+ std::vector<bool> Buffer = getBuffer();
+
+ for (bool B : Buffer)
+ OS << B;
+}