28#include <initializer_list>
30#include <unordered_map>
44 using iterator = std::unordered_map<index_type, T>::iterator;
46 using value_type = std::unordered_map<index_type, T>::value_type;
49 m_free_indices.insert(0);
50 m_free_indices.insert(1);
59 for (
auto const &
e : l) {
60 m_container[
e.first] =
e.second;
62 if (
auto it = m_free_indices.find(
e.first);
it != m_free_indices.end()) {
63 m_free_indices.erase(
it);
68 for (
index_type index{}; m_free_indices.size() < 2ul; ++index) {
69 if (
not m_container.contains(index)) {
70 m_free_indices.insert(index);
83 auto const ind = get_index();
90 auto const ind = get_index();
91 m_container[ind] = std::move(c);
105 assert(m_container.contains(i));
107 m_container.erase(i);
108 m_free_indices.insert(i);
163 std::size_t
size()
const {
return m_container.size(); }
167 std::unordered_map<index_type, T> m_container;
169 std::set<index_type> m_free_indices;
186 assert(!m_free_indices.empty());
187 auto const index = *m_free_indices.begin();
189 m_free_indices.erase(index);
193 if (m_free_indices.size() == 1ul) {
194 m_free_indices.insert(*(--m_free_indices.end()) +
index_type{1});
Container for objects that are identified by a numeric id.
std::unordered_map< index_type, T >::iterator iterator
std::unordered_map< index_type, T >::const_iterator const_iterator
const_iterator find(int id) const
find object by id.
const T & operator[](index_type i) const
Get element from container.
std::unordered_map< index_type, T >::value_type value_type
iterator find(int id)
find object by id.
const_iterator begin() const
Get a const iterator to beginning of the container.
void remove(index_type i)
Remove element from container.
iterator end()
Get an iterator to end of the container.
index_type add(T const &c)
Copy c into the container.
const_iterator end() const
Get a const iterator to end of the container.
index_type add(T &&c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
iterator begin()
Get iterator to beginning of the container.
NumeratedContainer(std::initializer_list< value_type > l)
Construct from list of key-value pairs.
T & operator[](index_type i)
Get element from container.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.