14 changed files with 136 additions and 75 deletions
@ -0,0 +1,39 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "../stl_alias.hpp" |
||||
|
|
||||
|
struct flat_index_group { |
||||
|
stl_vector_mp<uint32_t> index_group{}; /// a list of indices in the group
|
||||
|
stl_vector_mp<uint32_t> start_indices{}; /// a list of start indices for each group in the flat index group
|
||||
|
|
||||
|
inline size_t size() const { return start_indices.size() - 1; } |
||||
|
|
||||
|
// f(group_index, element_index_in_group, elemenet)
|
||||
|
template <typename F> |
||||
|
inline void foreach (F&& f) const |
||||
|
{ |
||||
|
for (uint32_t group_idx = 0; group_idx < size(); ++group_idx) { |
||||
|
for (uint32_t elem_idx = 0; elem_idx < start_indices[group_idx + 1] - start_indices[group_idx]; ++elem_idx) { |
||||
|
f(group_idx, elem_idx, index_group[start_indices[group_idx] + elem_idx]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// f(group_index, group_start_index, group_end_index)
|
||||
|
template <typename F> |
||||
|
inline void group_foreach(F&& f) const |
||||
|
{ |
||||
|
for (uint32_t group_idx = 0; group_idx < size(); ++group_idx) { |
||||
|
f(group_idx, start_indices[group_idx], start_indices[group_idx + 1]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// f(element_index_in_group, element)
|
||||
|
template <typename F> |
||||
|
inline void loop_on_group(uint32_t group_idx, F&& f) const |
||||
|
{ |
||||
|
for (uint32_t elem_idx = 0; elem_idx < start_indices[group_idx + 1] - start_indices[group_idx]; ++elem_idx) { |
||||
|
f(elem_idx, index_group[start_indices[group_idx] + elem_idx]); |
||||
|
} |
||||
|
} |
||||
|
}; |
Loading…
Reference in new issue