Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
crs_map.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2026 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Matteo Caldana <matteo.caldana@polimi.it>
22// Author: Pedro Peixoto <ppeixoto@usp.br>
23
24#ifndef VULPES_DATASTRUCTURE_CRS_MAP_HPP_
25#define VULPES_DATASTRUCTURE_CRS_MAP_HPP_
26
27#include <algorithm>
28#include <array>
29#include <cassert>
30#include <ostream>
31#include <utility>
32#include <variant>
33#include <vector>
34
35namespace vulpes {
36namespace datastructure {
37
38namespace internal {
44template <class T, bool Static, T Default = T{}>
46 explicit StaticSelector(T value_) : value(value_) {}
47 const T value;
48};
49
50template <class T, T Default>
51struct StaticSelector<T, true, Default> {
52 explicit StaticSelector(T /*unused*/) {}
53 static constexpr T value = Default;
54};
55} // namespace internal
56
68template <
69 typename DataType,
70 typename IndexType,
71 IndexType RowSize = IndexType(-1)>
72class CrsMap {
73 public:
81 template <bool Mutable>
82 class RowView {
83 public:
86 typename std::conditional_t<Mutable, DataType&, const DataType&>;
88 using pointer_t =
89 typename std::conditional_t<Mutable, DataType*, const DataType*>;
90
94
99 iterator begin() { return m_data; }
104 iterator end() { return m_data + size(); }
109 const_iterator begin() const { return m_data; }
114 const_iterator end() const { return m_data + size(); }
115
122 explicit RowView(pointer_t data, IndexType size)
123 : m_data(data), m_size(size) {}
124
131 const reference_t operator[](IndexType index) const {
132 return m_data[index];
133 }
134
141 reference_t operator[](IndexType index) { return m_data[index]; }
142
147 constexpr IndexType size() const {
148 if constexpr (RowSize == IndexType(-1)) {
149 return m_size.value;
150 } else {
151 return RowSize;
152 }
153 }
154
159 constexpr pointer_t const data() const { return m_data; }
160
161 private:
165 internal::StaticSelector<IndexType, RowSize != IndexType(-1), RowSize>
167 };
168
169 using ConstRowView = RowView<false>;
170 using MutableRowView = RowView<true>;
171
172 explicit CrsMap(const std::vector<std::vector<DataType>>& data) {
173 m_indices.reserve(data.size() + 1);
174 m_indices.push_back(0);
175 for (size_t i = 0; i < data.size(); ++i) {
176 m_indices.push_back(m_indices.back() + data[i].size());
177 for (const auto& e : data[i]) {
178 m_data.push_back(e);
179 }
180 }
181 }
182
189 explicit CrsMap(
190 const std::vector<DataType>& data, const std::vector<IndexType>& indices)
192
193 template <class Archive>
194 void serialize(Archive& ar, const unsigned int) {
195 ar & m_data;
196 ar & m_indices;
197 }
198
199 friend bool operator==(const CrsMap& lhs, const CrsMap& rhs) {
200 return (lhs.m_data == rhs.m_data) && (lhs.m_indices == rhs.m_indices);
201 }
202
222 explicit CrsMap(
223 std::vector<DataType>&& data, std::vector<IndexType>&& indices)
224 : m_data(std::move(data)), m_indices(std::move(indices)) {}
225
227 explicit CrsMap() = default;
228
235 MutableRowView getRow(IndexType row_idx) {
236 if constexpr (RowSize == IndexType(-1)) {
237 assert(row_idx < (IndexType)m_indices.size() - 1);
238 assert(
239 (m_indices[row_idx] <= (IndexType)m_data.size()) ||
240 (m_indices[row_idx] == 0 && m_data.size() == 0));
241 assert(m_indices[row_idx + 1] <= (IndexType)m_data.size());
242 return MutableRowView(
243 m_data.data() + m_indices[row_idx],
244 m_indices[row_idx + 1] - m_indices[row_idx]);
245 } else {
246 return MutableRowView(m_data.data() + row_idx * RowSize, RowSize);
247 }
248 }
249
256 ConstRowView getRow(IndexType row_idx) const {
257 if constexpr (RowSize == IndexType(-1)) {
258 assert(row_idx < (IndexType)m_indices.size() - 1);
259 assert(
260 (m_indices[row_idx] <= (IndexType)m_data.size()) ||
261 (m_indices[row_idx] == 0 && m_data.size() == 0));
262 assert(m_indices[row_idx + 1] <= (IndexType)m_data.size());
263 return ConstRowView(
264 m_data.data() + m_indices[row_idx],
265 m_indices[row_idx + 1] - m_indices[row_idx]);
266 } else {
267 return ConstRowView(m_data.data() + row_idx * RowSize, RowSize);
268 }
269 }
270
277 ConstRowView operator[](IndexType row_idx) const { return getRow(row_idx); }
284 MutableRowView operator[](IndexType row_idx) { return getRow(row_idx); }
285
298 const DataType& operator()(IndexType row_idx, IndexType col_idx) const {
299 if constexpr (RowSize == IndexType(-1)) {
300 return m_data[m_indices[row_idx] + col_idx];
301 } else {
302 return m_data[row_idx * RowSize + col_idx];
303 }
304 }
305
318 DataType& operator()(IndexType row_idx, IndexType col_idx) {
319 if constexpr (RowSize == IndexType(-1)) {
320 return m_data[m_indices[row_idx] + col_idx];
321 } else {
322 return m_data[row_idx * RowSize + col_idx];
323 }
324 }
325
331 IndexType size() const {
332 if constexpr (RowSize == IndexType(-1)) {
333 return m_indices.size() - 1;
334 } else {
335 return m_data.size() / RowSize;
336 }
337 }
338
346 auto slice(const std::vector<IndexType>& subindices) const {
347 std::decay_t<decltype(*this)> slice_map({}, {});
348 if constexpr (RowSize == IndexType(-1)) {
349 slice_map.m_indices.push_back(0);
350 for (std::size_t i = 0; i < subindices.size(); ++i) {
351 const auto idx = subindices[i];
352 assert(idx + 1 < static_cast<IndexType>(m_indices.size()));
353 const IndexType row_size = m_indices[idx + 1] - m_indices[idx];
354 slice_map.m_indices.push_back(row_size + slice_map.m_indices.back());
355 for (IndexType j = 0; j < row_size; ++j) {
356 slice_map.m_data.push_back(m_data[m_indices[idx] + j]);
357 }
358 }
359 } else {
360 slice_map.m_data.resize(RowSize * subindices.size());
361 for (std::size_t i = 0; i < subindices.size(); ++i) {
362 const auto idx = subindices[i];
363 for (IndexType j = 0; j < RowSize; ++j) {
364 slice_map.m_data[i * RowSize + j] = m_data[idx * RowSize + j];
365 }
366 }
367 }
368 return slice_map;
369 }
370
380 const std::vector<IndexType>& perm,
381 const std::vector<IndexType>& perm_inv) const {
382 assert(perm.size() == perm_inv.size());
383 assert(perm.size() == static_cast<std::size_t>(size()));
384 std::decay_t<decltype(*this)> slice_map({}, {});
385 if constexpr (RowSize == IndexType(-1)) {
386 slice_map.m_indices.push_back(0);
387 for (std::size_t i = 0; i < perm_inv.size(); ++i) {
388 const auto idx = perm_inv[i];
389 assert(static_cast<std::size_t>(idx + 1) < m_indices.size());
390 const IndexType row_size = m_indices[idx + 1] - m_indices[idx];
391 slice_map.m_indices.push_back(row_size + slice_map.m_indices.back());
392 for (IndexType j = 0; j < row_size; ++j) {
393 slice_map.m_data.push_back(perm[m_data[m_indices[idx] + j]]);
394 }
395 }
396 } else {
397 static_assert(RowSize * 0 && "NotImplemented");
398 }
399 return slice_map;
400 }
401
408 void remove(const DataType& value_to_remove) {
409 if (m_indices.size() < 1) {
410 return;
411 }
412 size_t curr = 0;
413 size_t row_start = 0;
414 for (size_t row = 0; row < m_indices.size() - 1; ++row) {
415 size_t row_end = m_indices[row + 1];
416 for (size_t i = row_start; i < row_end; ++i) {
417 if (m_data[i] != value_to_remove) {
418 m_data[curr++] = m_data[i];
419 }
420 }
421 m_indices[row + 1] = curr;
422 row_start = row_end;
423 }
424 m_data.resize(curr);
425 }
426
427 void pushBack(const std::vector<DataType>& row) {
428 m_data.reserve(m_data.size() + row.size());
429 for (const auto& e : row) {
430 m_data.push_back(e);
431 }
432 m_indices.push_back(m_data.size());
433 }
434
438 const auto& data() const { return m_data; }
442 const auto& indices() const { return m_indices; }
446 auto& data() { return m_data; }
450 auto& indices() { return m_indices; }
451
452 protected:
454 std::vector<DataType> m_data;
456 std::vector<IndexType> m_indices;
457};
458
483template <typename DataType, typename IndexType, IndexType RowSize>
484std::ostream& operator<<(
485 std::ostream& os, const CrsMap<DataType, IndexType, RowSize>& map) {
486 os << "CrsMap with " << map.size() << " rows:\n";
487 for (IndexType row_idx = 0; row_idx < map.size(); ++row_idx) {
488 os << "Row " << row_idx << ": ";
489 os << "[ ";
490 for (const auto& elem : map[row_idx]) {
491 os << elem << " ";
492 }
493 os << "]\n";
494 }
495 return os;
496}
497
509template <typename T, std::size_t N>
511 public:
512 using iterator = T*;
513 using const_iterator = const T*;
514
526 if (std::holds_alternative<StaticStorage>(m_storage)) {
527 return std::get<StaticStorage>(m_storage).data();
528 }
529 return std::get<DynamicStorage>(m_storage).data();
530 }
531
542 if (std::holds_alternative<StaticStorage>(m_storage)) {
543 return std::get<StaticStorage>(m_storage).data() + m_size;
544 }
545 return std::get<DynamicStorage>(m_storage).data() + m_size;
546 }
547
559 if (std::holds_alternative<StaticStorage>(m_storage)) {
560 return std::get<StaticStorage>(m_storage).data();
561 }
562 return std::get<DynamicStorage>(m_storage).data();
563 }
564
576 if (std::holds_alternative<StaticStorage>(m_storage)) {
577 return std::get<StaticStorage>(m_storage).data() + m_size;
578 }
579 return std::get<DynamicStorage>(m_storage).data() + m_size;
580 }
581
584
590 SmallVector(std::initializer_list<T> init_list) : m_size(init_list.size()) {
591 if (m_size <= N) {
592 std::copy(
593 init_list.begin(), init_list.end(),
594 std::get<StaticStorage>(m_storage).begin());
595 } else {
596 m_storage = DynamicStorage(init_list);
597 }
598 }
599
600 SmallVector(const T* begin, const T* end) {
601 if (end < begin) {
602 m_size = begin - end;
603 if (m_size <= N) {
604 std::copy(
605 std::make_reverse_iterator(begin), std::make_reverse_iterator(end),
606 std::get<StaticStorage>(m_storage).begin());
607 } else {
609 std::make_reverse_iterator(begin), std::make_reverse_iterator(end));
610 }
611 } else {
612 m_size = end - begin;
613 if (m_size <= N) {
614 std::copy(begin, end, std::get<StaticStorage>(m_storage).begin());
615 } else {
617 }
618 }
619 }
620
626 void push_back(const T& value) {
627 if (m_size < N) {
628 std::get<StaticStorage>(m_storage)[m_size] = value;
629 } else {
630 // Switch to dynamic storage if we haven't yet
631 if (std::holds_alternative<StaticStorage>(m_storage)) {
632 // Move elements from static storage to dynamic vector
633 std::vector<T> dynamic_storage;
634 dynamic_storage.reserve(m_size + 1);
635 for (std::size_t i = 0; i < m_size; ++i) {
636 dynamic_storage.push_back(std::get<StaticStorage>(m_storage)[i]);
637 }
638 m_storage = std::move(dynamic_storage);
639 }
640 std::get<DynamicStorage>(m_storage).push_back(value);
641 }
642 ++m_size;
643 }
644
655 template <typename... Args>
656 void emplace_back(Args&&... args) {
657 if (m_size < N) {
658 std::get<StaticStorage>(m_storage)[m_size] = T{args...};
659 } else {
660 // Switch to dynamic storage if we haven't yet
661 if (std::holds_alternative<StaticStorage>(m_storage)) {
662 // Move elements from static storage to dynamic vector
663 std::vector<T> dynamic_storage;
664 dynamic_storage.reserve(m_size + 1);
665 for (std::size_t i = 0; i < m_size; ++i) {
666 dynamic_storage.push_back(std::get<StaticStorage>(m_storage)[i]);
667 }
668 m_storage = std::move(dynamic_storage);
669 }
670 std::get<DynamicStorage>(m_storage).emplace_back(
671 std::forward<Args>(args)...);
672 }
673 ++m_size;
674 }
675
683 template <class InputIt>
684 void assign(InputIt first, InputIt last) {
685 m_size = std::distance(first, last);
686 if (m_size <= N) {
687 m_storage.template emplace<StaticStorage>();
688 std::copy(first, last, std::get<StaticStorage>(m_storage).begin());
689 } else {
690 m_storage.template emplace<DynamicStorage>(first, last);
691 }
692 }
693
700 T& operator[](std::size_t index) {
701 assert(index < m_size);
702 if (std::holds_alternative<StaticStorage>(m_storage)) {
703 return std::get<StaticStorage>(m_storage)[index];
704 }
705 return std::get<DynamicStorage>(m_storage)[index];
706 }
707
714 const T& operator[](std::size_t index) const {
715 assert(index < m_size);
716 if (std::holds_alternative<StaticStorage>(m_storage)) {
717 return std::get<StaticStorage>(m_storage)[index];
718 }
719 return std::get<DynamicStorage>(m_storage)[index];
720 }
721
727 constexpr std::size_t size() const { return m_size; }
728
729 private:
730 using StaticStorage = std::array<T, N>;
731 using DynamicStorage = std::vector<T>;
732
734 std::variant<StaticStorage, DynamicStorage> m_storage;
735 std::size_t m_size;
736};
737
757template <typename DataType, std::size_t N = 16>
759 public:
761
768 CrsMapUncompressed(std::initializer_list<SmallVector<DataType, N>> init_list)
769 : m_data(init_list) {}
770
775 constexpr auto begin() { return m_data.begin(); }
780 constexpr auto end() { return m_data.end(); }
785 constexpr auto begin() const { return m_data.begin(); }
790 constexpr auto end() const { return m_data.end(); }
795 constexpr const auto& back() const { return m_data.back(); }
800 constexpr auto& back() { return m_data.back(); }
801
807 constexpr void resize(std::size_t new_size) { m_data.resize(new_size); }
808
815 constexpr const SmallVector<DataType, N>& operator[](std::size_t idx) const {
816 return m_data[idx];
817 }
818
823 constexpr SmallVector<DataType, N>& operator[](std::size_t idx) {
824 return m_data[idx];
825 }
826
830 constexpr void push_back(const SmallVector<DataType, N>& value) {
831 m_data.push_back(value);
832 }
833
837 constexpr void push_back(SmallVector<DataType, N>&& value) {
838 m_data.push_back(std::move(value));
839 }
840
841 template <class... Args>
842 constexpr void emplace_back(Args&&... args) {
843 m_data.emplace_back(std::forward<Args>(args)...);
844 }
845
857 SmallVector<DataType, N>& getRow(std::size_t row_idx) {
858 if (row_idx >= static_cast<std::size_t>(m_data.size())) {
859 m_data.resize(row_idx + 1);
860 }
861 return m_data[row_idx];
862 }
863
875 template <typename IndexType>
877 std::vector<DataType> data;
878 std::vector<IndexType> indices = {0};
879 for (size_t i = 0; i < m_data.size(); ++i) {
880 indices.push_back(indices.back() + m_data[i].size());
881 for (const auto& e : m_data[i]) {
882 data.push_back(e);
883 }
884 }
885 return CrsMap(std::move(data), std::move(indices));
886 }
887
893 std::size_t size() const { return m_data.size(); }
894
895 protected:
903 std::vector<SmallVector<DataType, N>> m_data;
904};
905
906template <typename DataType>
907using CrsMapUncompressedVariant = std::variant<
920
934template <typename DataType>
937 if (static_size <= 4) {
939 } else if (static_size <= 8) {
941 } else if (static_size <= 16) {
943 } else if (static_size <= 32) {
945 } else if (static_size <= 64) {
947 } else if (static_size <= 128) {
949 } else if (static_size <= 256) {
951 } else if (static_size <= 512) {
953 } else if (static_size <= 1024) {
955 } else if (static_size <= 2048) {
957 } else if (static_size <= 4096) {
959 } else if (static_size <= 8192) {
961 } else {
963 }
964}
965
990template <typename DataType, std::size_t N>
991std::ostream& operator<<(
992 std::ostream& os, const CrsMapUncompressed<DataType, N>& map) {
993 os << "CrsMapUncompressed with " << map.size() << " rows:\n";
994 for (std::size_t row_idx = 0; row_idx < map.size(); ++row_idx) {
995 os << "Row " << row_idx << ": ";
996 os << "[ ";
997 for (const auto& elem : map[row_idx]) {
998 os << elem << " ";
999 }
1000 os << "]\n";
1001 }
1002 return os;
1003}
1004
1005} // namespace datastructure
1006} // namespace vulpes
1007
1008#endif // VULPES_DATASTRUCTURE_CRS_MAP_HPP_
A class that behaves like a vector of vectors, providing automatic row range checking.
Definition crs_map.hpp:758
constexpr const auto & back() const
Returns a constant reference to the last row of the map.
Definition crs_map.hpp:795
std::vector< SmallVector< IndexType, 16 > > m_data
Definition crs_map.hpp:903
constexpr void emplace_back(Args &&... args)
Definition crs_map.hpp:842
CrsMapUncompressed(std::initializer_list< SmallVector< DataType, N > > init_list)
Constructs a CrsMapUncompressed object with an initializer list of SmallVector objects.
Definition crs_map.hpp:768
constexpr void push_back(SmallVector< DataType, N > &&value)
Appends an rvalue SmallVector to the map.
Definition crs_map.hpp:837
CrsMap< DataType, IndexType > compress() const
Compresses the uncompressed CrsMap into a compressed format.
Definition crs_map.hpp:876
constexpr const SmallVector< DataType, N > & operator[](std::size_t idx) const
Accesses a SmallVector at the given index.
Definition crs_map.hpp:815
constexpr auto & back()
Returns a reference to the last row of the map.
Definition crs_map.hpp:800
constexpr void resize(std::size_t new_size)
Resizes the map to contain the specified number of SmallVector objects.
Definition crs_map.hpp:807
constexpr auto begin()
Returns an iterator to the beginning of the map.
Definition crs_map.hpp:775
constexpr SmallVector< DataType, N > & operator[](std::size_t idx)
Accesses a SmallVector at the given index.
Definition crs_map.hpp:823
constexpr auto begin() const
Returns a constant iterator to the beginning of the map.
Definition crs_map.hpp:785
constexpr auto end() const
Returns a constant iterator to the end of the map.
Definition crs_map.hpp:790
std::size_t size() const
Returns the number of rows in the matrix.
Definition crs_map.hpp:893
constexpr void push_back(const SmallVector< DataType, N > &value)
Appends a copy of a SmallVector to the map.
Definition crs_map.hpp:830
constexpr auto end()
Returns an iterator to the end of the map.
Definition crs_map.hpp:780
SmallVector< DataType, N > & getRow(std::size_t row_idx)
Access a row of the matrix as a mutable reference.
Definition crs_map.hpp:857
const_iterator begin() const
Get the beginning iterator of the row (const version).
Definition crs_map.hpp:109
typename std::conditional_t< Mutable, DataType &, const DataType & > reference_t
Alias for the reference type, depending on mutability.
Definition crs_map.hpp:85
const_iterator end() const
Get the ending iterator of the row (const version).
Definition crs_map.hpp:114
iterator begin()
Get the beginning iterator of the row.
Definition crs_map.hpp:99
typename std::conditional_t< Mutable, DataType *, const DataType * > pointer_t
Alias for the pointer type, depending on mutability.
Definition crs_map.hpp:88
pointer_t const m_data
Definition crs_map.hpp:163
constexpr pointer_t const data() const
Definition crs_map.hpp:159
reference_t operator[](IndexType index)
Access an element in the row by index.
Definition crs_map.hpp:141
pointer_t iterator
Iterator type for mutable/non-mutable rows.
Definition crs_map.hpp:92
const reference_t operator[](IndexType index) const
Access an element in the row by index.
Definition crs_map.hpp:131
iterator end()
Get the ending iterator of the row.
Definition crs_map.hpp:104
internal::StaticSelector< IndexType, RowSize !=IndexType(-1), RowSize > m_size
Definition crs_map.hpp:166
const pointer_t const_iterator
Definition crs_map.hpp:93
RowView(pointer_t data, IndexType size)
Constructor to create a view over a row.
Definition crs_map.hpp:122
constexpr IndexType size() const
Get the size of the row.
Definition crs_map.hpp:147
Definition crs_map.hpp:72
auto & indices()
Accessor to the indices buffer.
Definition crs_map.hpp:450
CrsMap(const std::vector< DataType > &data, const std::vector< IndexType > &indices)
Construct a CrsMap with the provided data and index arrays.
Definition crs_map.hpp:189
CrsMap()=default
Default constructor.
CrsMap(const std::vector< std::vector< DataType > > &data)
Definition crs_map.hpp:172
void serialize(Archive &ar, const unsigned int)
Definition crs_map.hpp:194
IndexType size() const
Get the number of rows in the CRS map.
Definition crs_map.hpp:331
const auto & indices() const
Definition crs_map.hpp:442
MutableRowView getRow(IndexType row_idx)
Get a mutable view over a row.
Definition crs_map.hpp:235
friend bool operator==(const CrsMap &lhs, const CrsMap &rhs)
Definition crs_map.hpp:199
void remove(const DataType &value_to_remove)
Remove in-place all entries with a certain value.
Definition crs_map.hpp:408
DataType & operator()(IndexType row_idx, IndexType col_idx)
Access an element in the CRS map by row and column index (mutable version).
Definition crs_map.hpp:318
const DataType & operator()(IndexType row_idx, IndexType col_idx) const
Access an element in the CRS map by row and column index (constant version).
Definition crs_map.hpp:298
CrsMap(std::vector< DataType > &&data, std::vector< IndexType > &&indices)
Constructor that initializes a CrsMap by moving the provided data and indices.
Definition crs_map.hpp:222
std::vector< MonoTypeLifted > m_data
Definition crs_map.hpp:454
auto & data()
Accessor to the data buffer.
Definition crs_map.hpp:446
ConstRowView getRow(IndexType row_idx) const
Get a constant view over a row.
Definition crs_map.hpp:256
RowView< false > ConstRowView
Definition crs_map.hpp:169
auto slice(const std::vector< IndexType > &subindices) const
Get a CrsMap with the rows of the passed indexes.
Definition crs_map.hpp:346
ConstRowView operator[](IndexType row_idx) const
Access a row using the subscript operator (constant version).
Definition crs_map.hpp:277
MutableRowView operator[](IndexType row_idx)
Access a row using the subscript operator (mutable version).
Definition crs_map.hpp:284
auto permute(const std::vector< IndexType > &perm, const std::vector< IndexType > &perm_inv) const
Get a CrsMap obtained by applying a permutation to this instance.
Definition crs_map.hpp:379
void pushBack(const std::vector< DataType > &row)
Definition crs_map.hpp:427
RowView< true > MutableRowView
Definition crs_map.hpp:170
std::vector< index_t > m_indices
Definition crs_map.hpp:456
const auto & data() const
Definition crs_map.hpp:438
Definition crs_map.hpp:510
SmallVector()
Default constructor.
Definition crs_map.hpp:583
const T * const_iterator
Iterator for constant access.
Definition crs_map.hpp:513
void assign(InputIt first, InputIt last)
Assign the values in range [first, last) to the container.
Definition crs_map.hpp:684
std::variant< StaticStorage, DynamicStorage > m_storage
Variant storing either static or dynamic memory.
Definition crs_map.hpp:734
T * iterator
Iterator for mutable access.
Definition crs_map.hpp:512
constexpr std::size_t size() const
Get the number of elements in the vector.
Definition crs_map.hpp:727
const_iterator end() const
Returns a const iterator pointing to the end of the storage.
Definition crs_map.hpp:575
iterator begin()
Returns an iterator pointing to the beginning of the storage.
Definition crs_map.hpp:525
iterator end()
Returns an iterator pointing to the end of the storage.
Definition crs_map.hpp:541
void emplace_back(Args &&... args)
Constructs an element in-place at the end of the vector.
Definition crs_map.hpp:656
const_iterator begin() const
Returns a const iterator pointing to the beginning of the storage.
Definition crs_map.hpp:558
const T & operator[](std::size_t index) const
Access an element by index (constant).
Definition crs_map.hpp:714
std::vector< T > DynamicStorage
Dynamic storage for larger sizes.
Definition crs_map.hpp:731
std::size_t m_size
Number of elements in the vector.
Definition crs_map.hpp:735
SmallVector(const T *begin, const T *end)
Definition crs_map.hpp:600
SmallVector(std::initializer_list< T > init_list)
Constructor to initialize the vector with an initializer list.
Definition crs_map.hpp:590
std::array< T, N > StaticStorage
Static array for small sizes.
Definition crs_map.hpp:730
T & operator[](std::size_t index)
Access an element by index (mutable).
Definition crs_map.hpp:700
void push_back(const T &value)
Add an element to the end of the vector.
Definition crs_map.hpp:626
Definition crs_map.hpp:38
Definition crs_map.hpp:36
std::ostream & operator<<(std::ostream &os, const CrsMap< DataType, IndexType, RowSize > &map)
Overloaded stream insertion operator for CrsMap objects.
Definition crs_map.hpp:484
CrsMapUncompressedVariant< DataType > getUncompressedCrsMapWithStaticStorageGreaterThan(std::size_t static_size)
Function that builds an UncompressedCrsMap with at least a certain static storage,...
Definition crs_map.hpp:936
std::variant< CrsMapUncompressed< DataType, 4 >, CrsMapUncompressed< DataType, 8 >, CrsMapUncompressed< DataType, 16 >, CrsMapUncompressed< DataType, 32 >, CrsMapUncompressed< DataType, 64 >, CrsMapUncompressed< DataType, 128 >, CrsMapUncompressed< DataType, 256 >, CrsMapUncompressed< DataType, 512 >, CrsMapUncompressed< DataType, 1024 >, CrsMapUncompressed< DataType, 2048 >, CrsMapUncompressed< DataType, 4096 >, CrsMapUncompressed< DataType, 8192 > > CrsMapUncompressedVariant
Definition crs_map.hpp:907
Definition cell_manager.hpp:38
const T value
Definition crs_map.hpp:47
StaticSelector(T value_)
Definition crs_map.hpp:46