summaryrefslogtreecommitdiffstats
path: root/ml/BitBufferCounter.cc
blob: 5e1ab5aca38f9c23a135f62b42e9eb6bee73189e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;
}