MorphologicalAttributeFilters
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
42 GenerationStampSet() = default;
43
47 explicit GenerationStampSet(size_t n) { resize(n); }
48
52 void resize(size_t newN) {
53 n = newN;
54 stamp = std::make_unique<gen_t[]>(n);
55 std::fill_n(stamp.get(), n, 0);
56 cur = 1;
57 }
58
62 inline void mark(size_t idx) noexcept {
63 stamp[idx] = cur;
64 }
65
69 inline bool isMarked(size_t idx) const noexcept {
70 return stamp[idx] == cur;
71 }
72
74 inline void unmark(size_t idx) noexcept {
75 if (stamp[idx] == cur) {
76 stamp[idx] = 0;
77 }
78 }
79
81 void resetAll() {
82 if (++cur == 0) {
83 std::fill_n(stamp.get(), n, 0);
84 cur = 1;
85 }
86 }
87
89 void clearAll() {
90 std::fill_n(stamp.get(), n, 0);
91 cur = 1;
92 }
93
96};
97
98} // 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.
size_t n
Number of logical entries in stamp.