TTK
Loading...
Searching...
No Matches
VisitedMask.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <DataTypes.h>
9
10#include <algorithm>
11#include <vector>
12
13namespace ttk {
14
27 struct VisitedMask {
28 std::vector<bool> &isVisited_;
29 std::vector<SimplexId> &visitedIds_;
30
31 VisitedMask(std::vector<bool> &isVisited,
32 std::vector<SimplexId> &visitedIds)
33 : isVisited_{isVisited}, visitedIds_{visitedIds} {
34 }
35
37 // use RAII to clean & reset referenced vectors
38 for(const auto id : this->visitedIds_) {
39 this->isVisited_[id] = false;
40 }
41 // set size to 0 but keep allocated memory
42 this->visitedIds_.clear();
43 }
44
45 inline void insert(const SimplexId id) {
46 this->isVisited_[id] = true;
47 this->visitedIds_.emplace_back(id);
48 }
49
50 inline bool remove(const SimplexId id) {
51 if(!this->isVisited_[id]) {
52 return false;
53 }
54 const auto it
55 = std::find(this->visitedIds_.begin(), this->visitedIds_.end(), id);
56 if(it != this->visitedIds_.end()) {
57 this->visitedIds_.erase(it);
58 }
59 this->isVisited_[id] = false;
60 return true;
61 }
62 };
63
64} // namespace ttk
The Topology ToolKit.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22
Auto-cleaning re-usable graph propagations data structure.
Definition VisitedMask.h:27
VisitedMask(std::vector< bool > &isVisited, std::vector< SimplexId > &visitedIds)
Definition VisitedMask.h:31
std::vector< bool > & isVisited_
Definition VisitedMask.h:28
void insert(const SimplexId id)
Definition VisitedMask.h:45
std::vector< SimplexId > & visitedIds_
Definition VisitedMask.h:29
bool remove(const SimplexId id)
Definition VisitedMask.h:50