Wildmeshing Toolkit
Loading...
Searching...
No Matches
indexed_collector.hpp
1#pragma once
2
3#include <vector>
4
5namespace wmtk::threading {
6
12template <typename T>
14{
15 std::vector<T> m_slots;
16 std::vector<char> m_filled;
17
18public:
23 explicit indexed_collector(std::size_t n)
24 : m_slots(n)
25 , m_filled(n, 0)
26 {}
27
35 void set(std::size_t i, const T& v)
36 {
37 m_slots[i] = v;
38 m_filled[i] = 1;
39 }
40
47 std::vector<T> compact() const
48 {
49 std::vector<T> out;
50 out.reserve(m_slots.size());
51 for (std::size_t i = 0; i < m_slots.size(); ++i) {
52 if (m_filled[i]) {
53 out.push_back(m_slots[i]);
54 }
55 }
56 return out;
57 }
58};
59
60} // namespace wmtk::threading
Definition indexed_collector.hpp:14
indexed_collector(std::size_t n)
Construct an indexed_collector with n slots.
Definition indexed_collector.hpp:23
std::vector< T > compact() const
Get a compacted vector of all filled slots. This function is not thread-safe and should only be calle...
Definition indexed_collector.hpp:47
void set(std::size_t i, const T &v)
Set the value at index i to v. This function can be called concurrently as long as callers pass disti...
Definition indexed_collector.hpp:35