12 template <
typename, my_
size_t>
class ValueStoragePolicy =
StaticStorage,
13 template <
typename, my_
size_t>
class IndexStoragePolicy =
StaticStorage>
16 ValueStoragePolicy<T, NonZeroCount> values_;
17 IndexStoragePolicy<IndexType, NonZeroCount> indices_;
33 for (
my_size_t i = 0; i < NonZeroCount; ++i)
41 : values_(other.values_), indices_(other.indices_), current_size_(other.current_size_)
47 : values_(
move(other.values_)), indices_(
move(other.indices_)), current_size_(other.current_size_)
49 other.current_size_ = 0;
57 values_ = other.values_;
58 indices_ = other.indices_;
59 current_size_ = other.current_size_;
70 values_ =
move(other.values_);
71 indices_ =
move(other.indices_);
72 current_size_ = other.current_size_;
74 other.current_size_ = 0;
82 std::cout <<
"Sparse Representation (NonZeroCount = " << NonZeroCount <<
"):\n";
83 for (
my_size_t i = 0; i < current_size_; ++i)
85 std::cout <<
"Index: " << indices_[i] <<
", Value: " << values_[i] <<
"\n";
112 for (
my_size_t i = 0; i < current_size_; ++i)
114 if (indices_[i] == idx)
119 if (current_size_ < NonZeroCount)
121 indices_[current_size_] = idx;
122 values_[current_size_] = T{};
124 return values_[current_size_ - 1];
136 if (last_idx_ < current_size_ && indices_[last_idx_] == idx)
137 return values_[last_idx_];
139 for (
my_size_t i = 0; i < current_size_; ++i)
141 if (indices_[i] == idx)
static void error(const T &msg)
Definition error_handler.h:30
Definition sparse_access.h:15
FORCE_INLINE T & operator[](IndexType idx) noexcept
Definition sparse_access.h:109
FORCE_INLINE constexpr const T * data() const noexcept
Definition sparse_access.h:91
FORCE_INLINE constexpr T * data() noexcept
Definition sparse_access.h:90
FORCE_INLINE constexpr T * values_begin() noexcept
Definition sparse_access.h:92
FORCE_INLINE constexpr IndexType * indices_end() noexcept
Definition sparse_access.h:102
SparseAccess(SparseAccess &&other) noexcept
Definition sparse_access.h:46
FORCE_INLINE const T & operator[](IndexType idx) const noexcept
Definition sparse_access.h:133
SparseAccess(const SparseAccess &other)
Definition sparse_access.h:40
FORCE_INLINE constexpr const IndexType * indices_data() const noexcept
Definition sparse_access.h:99
FORCE_INLINE constexpr IndexType * indices_begin() noexcept
Definition sparse_access.h:100
SparseAccess(T initValue)
Definition sparse_access.h:31
SparseAccess & operator=(const SparseAccess &other)
Definition sparse_access.h:53
FORCE_INLINE constexpr const T * values_begin() const noexcept
Definition sparse_access.h:93
SparseAccess()
Definition sparse_access.h:26
FORCE_INLINE constexpr IndexType * indices_data() noexcept
Definition sparse_access.h:98
SparseAccess & operator=(SparseAccess &&other) noexcept
Definition sparse_access.h:66
void print() const
Definition sparse_access.h:80
FORCE_INLINE constexpr const IndexType * indices_begin() const noexcept
Definition sparse_access.h:101
FORCE_INLINE constexpr const T * values_end() const noexcept
Definition sparse_access.h:95
FORCE_INLINE constexpr const IndexType * indices_end() const noexcept
Definition sparse_access.h:103
FORCE_INLINE constexpr T * values_end() noexcept
Definition sparse_access.h:94
Definition static_storage.h:9
#define my_size_t
Size/index type used throughout the library.
Definition config.h:126
#define FORCE_INLINE
Hint the compiler to always inline a function.
Definition config.h:26
STL-free memory utilities.
void fill_n_optimized(T *ptr, my_size_t count, const T &value)
Fill a contiguous buffer with a given value.
Definition mem_utils.h:71
constexpr remove_reference_t< T > && move(T &&t) noexcept
Cast to rvalue reference (replacement for std::move).
Definition simple_type_traits.h:178