StateToIdMap.ixx File
Policy mapping states to IDs. More...
Included Headers
#include <vector>
#include <span>
#include <helios-engine-config.h>
#include <cassert>
#include <bit>
#include <algorithm>
#include <cstddef>
#include <utility>
#include <helios.engine.core.types>
#include <helios.engine.state.types>
Namespaces Index
| namespace | helios |
| namespace | engine |
| namespace | state |
Classes Index
| class | StateToIdMap<TState, TId> |
|
Maps state enum values to lists of IDs. More... | |
Description
Policy mapping states to IDs.
File Listing
The file content with the documentation metadata removed is:
9#include <helios-engine-config.h>
23using namespace helios::engine::state::types;
24export namespace helios::engine::state {
38 class StateToIdMap {
58 size_t idx = 0;
59 while (st > 0) {
61 if ((st & 1) != 0) {
62 if (states_.size() <= idx) {
63 states_.resize(idx + 1);
66 states_[idx].push_back(id);
70 idx++;
71 st >>= 1;
86 StateToIdMap() {
87 states_.reserve(STATE_TO_IDMAP_DEFAULT_CAPACITY);
98 StateToIdMap& add(TState state, TId id) noexcept {
99 assert(!frozen_ && "Cannot add to a frozen map");
101 const auto st = static_cast<size_t>(std::to_underlying(state));
103 if (st == 0) {
107 update(st, id);
116 for (auto& v : states_) {
136 finalize();
154 assert((std::to_underlying(state) & (std::to_underlying(state) -1)) == 0 && "State must be a power of 2");
156 const auto stateIdx = static_cast<size_t>(std::countr_zero(std::to_underlying(state)));
158 if (states_.size() <= stateIdx) {
162 return states_[stateIdx];
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.