mmcfilters
Public API documentation
Loading...
Searching...
No Matches
GenerationStampSet.hpp
1#pragma once
2
3#include <algorithm>
4#include <cstddef>
5#include <cstdint>
6#include <memory>
7
8namespace mmcfilters {
9
31 using gen_t = uint32_t;
32
34 std::unique_ptr<gen_t[]> stamp;
35
37 size_t n{0};
38
41
45 GenerationStampSet() = default;
46
52 explicit GenerationStampSet(size_t n) { resize(n); }
53
59 void resize(size_t newN) {
60 n = newN;
61 stamp = std::make_unique<gen_t[]>(n);
62 std::fill_n(stamp.get(), n, 0);
63 cur = 1;
64 }
65
71 inline void mark(size_t idx) noexcept { stamp[idx] = cur; }
72
79 inline bool isMarked(size_t idx) const noexcept { return stamp[idx] == cur; }
80
86 inline void unmark(size_t idx) noexcept {
87 if (stamp[idx] == cur) {
88 stamp[idx] = 0;
89 }
90 }
91
95 void resetAll() {
96 if (++cur == 0) {
97 std::fill_n(stamp.get(), n, 0);
98 cur = 1;
99 }
100 }
101
105 void clearAll() {
106 std::fill_n(stamp.get(), n, 0);
107 cur = 1;
108 }
109
116};
117
118} // namespace mmcfilters
Owning result for one computed scalar attribute layout and buffer.
Efficient visited-set implementation based on generation stamps.
void clearAll()
Performs an O(N) physical clear of the whole stamp buffer.
void mark(size_t idx) noexcept
Marks idx in the current generation.
bool isMarked(size_t idx) const noexcept
Returns true when idx is marked in the current generation.
void resize(size_t newN)
Resizes the stamp buffer and physically clears all marks.
uint32_t gen_t
Integer type used for individual generation stamps.
void resetAll()
Performs an O(1) logical reset by advancing the generation counter.
std::unique_ptr< gen_t[]> stamp
Stamp buffer with one entry per logical index.
gen_t generation() const noexcept
Returns the current generation counter.
GenerationStampSet(size_t n)
Creates a stamp set with n logical entries.
void unmark(size_t idx) noexcept
Removes one mark from the current logical generation.
gen_t cur
Current generation; zero is reserved for physically cleared slots.
GenerationStampSet()=default
Constructs a default GenerationStampSet.
size_t n
Number of logical entries in stamp.