This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
fortuna/event_adder_impl.h

40 lines
891 B
C
Raw Normal View History

2021-12-08 03:58:18 +01:00
#ifndef FORTUNA_EVENT_ADDER_IMPL_H
#define FORTUNA_EVENT_ADDER_IMPL_H
#include "event_adder.h"
#include "pool.h"
#include <cstdint>
2021-12-08 03:58:18 +01:00
namespace fortuna {
namespace accumulator {
class EventAdderImpl final : public EventAdder {
public:
static constexpr const uint8_t p_size{32};
private:
uint8_t pool_id;
static unsigned int _source_id;
static accumulator::Pool _pools[p_size];
2021-12-08 03:58:18 +01:00
public:
2022-01-10 04:25:03 +01:00
EventAdderImpl(const unsigned int source_id,
const accumulator::Pool pools[p_size]) {
this->_source_id = source_id;
for (uint8_t i{0}; i < this->p_size; i++) {
this->_pools[i] = pools[i];
2021-12-08 03:58:18 +01:00
}
this->pool_id = 0;
2021-12-08 03:58:18 +01:00
}
void add(std::vector<char> event) override {
this->pool_id = static_cast<uint8_t>((this->pool_id + 1) % p_size);
_pools[this->pool_id].add_entropy(_source_id, event);
2021-12-08 03:58:18 +01:00
}
};
2022-01-10 04:25:03 +01:00
} // namespace accumulator
} // namespace fortuna
#endif // FORTUNA_EVENT_ADDER_IMPL_H