ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
DynamicCsr.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File DynamicCsr.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
41/*--------------------------------------------------------------------------*/
42/*----------------------------- DEFINITIONS --------------------------------*/
43/*--------------------------------------------------------------------------*/
44
45#ifndef __ADS_DynamicCsr
46 #define __ADS_DynamicCsr
47/* self-identification: #endif constant */
48
49/*--------------------------------------------------------------------------*/
50/*------------------------------ INCLUDES ----------------------------------*/
51/*--------------------------------------------------------------------------*/
52
53#include "ADS/Contract.h"
55
56#include <algorithm>
57#include <cstddef>
58#include <limits>
59#include <ranges>
60#include <span>
61#include <type_traits>
62#include <utility>
63#include <vector>
64
65/*--------------------------------------------------------------------------*/
66/*--------------------------- NAMESPACE ------------------------------------*/
67/*--------------------------------------------------------------------------*/
68
69namespace ADS
70{
71
72/*--------------------------------------------------------------------------*/
73/*---------------------------- CLASS DynamicCsr ----------------------------*/
74/*--------------------------------------------------------------------------*/
75
78template< class I = int , class V = double >
80{
81
82 static_assert( std::is_integral_v< I > );
83
84/*--------------------------------------------------------------------------*/
85 public:
86 using Index = I;
87 using Value = V;
88
90 DynamicCsr( void ) : f_beg( 1 , I( 0 ) ) { }
91
93 [[nodiscard]] std::size_t rows( void ) const { return( f_beg.size() - 1 ); }
94
96 [[nodiscard]] std::size_t nonzeros( void ) const { return( f_ind.size() ); }
97
99 [[nodiscard]] bool empty( void ) const { return( rows() == 0 ); }
100
102 void reserve( std::size_t r , std::size_t z );
103
105 void clear( void );
106
122 std::size_t append( std::span< const I > ind , std::span< const V > val );
123
145 std::size_t append( std::size_t r , const I * beg , const I * ind ,
146 const V * val );
147
171 template< std::ranges::contiguous_range R >
172 void remove( const R & E );
173
178 void remove( std::size_t first , std::size_t last );
179
182 [[nodiscard]] std::span< const I > indices( std::size_t i ) const;
183
186 [[nodiscard]] std::span< const V > values( std::size_t i ) const;
187
190 [[nodiscard]] std::span< V > values( std::size_t i );
191
194 [[nodiscard]] const I * beg( void ) const { return( f_beg.data() ); }
195
197 [[nodiscard]] const I * ind( void ) const { return( f_ind.data() ); }
198
200 [[nodiscard]] const V * val( void ) const { return( f_val.data() ); }
201
202/*--------------------------------------------------------------------------*/
203 private:
204 template< class U > // not zeroed when they grow
205 using Vector = std::vector< U , detail::DefaultInitAllocator< U > >;
206
208 [[nodiscard]] bool consistent( void ) const;
209
210 Vector< I > f_beg;
211 Vector< I > f_ind;
212 Vector< V > f_val;
213
214 }; // end( class DynamicCsr )
215
217template< class I = int , class V = double >
219
220/*--------------------------------------------------------------------------*/
221
222} // end( namespace ADS )
223
224/*--------------------------------------------------------------------------*/
225/*-------------------------- IMPLEMENTATION --------------------------------*/
226/*--------------------------------------------------------------------------*/
227
228#include "ADS/numeric/impl/DynamicCsr.tpp"
229
230/*--------------------------------------------------------------------------*/
231
232#endif /* DynamicCsr.h included */
233
234/*--------------------------------------------------------------------------*/
235/*-------------------------- End File DynamicCsr.h -------------------------*/
236/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The dense matrices by rows, beyond the book: DenseMatrix keeps the entries by rows in one contiguous...
a sparse matrix by rows, with indices of type I and values of type V, whose rows are appended and rem...
Definition DynamicCsr.h:80
void clear(void)
removes all the rows, keeping the memory
bool empty(void) const
true if the matrix has no row
Definition DynamicCsr.h:99
std::size_t append(std::size_t r, const I *beg, const I *ind, const V *val)
appends the rows of a compressed form: the row has the entries to of ind and val; the index of th...
DynamicCsr(void)
the matrix of no rows
Definition DynamicCsr.h:90
std::size_t nonzeros(void) const
the number of the entries
Definition DynamicCsr.h:96
std::span< const I > indices(std::size_t i) const
the minor indices of the row
std::size_t rows(void) const
the number of the rows
Definition DynamicCsr.h:93
void remove(std::size_t first, std::size_t last)
removes the rows from to , excluded, by one erase of their entries and a shift of the starts after ...
std::size_t append(std::span< const I > ind, std::span< const V > val)
appends the row of the entries ; its index
std::span< V > values(std::size_t i)
the values of the row , to change in place
const I * beg(void) const
Definition DynamicCsr.h:194
void reserve(std::size_t r, std::size_t z)
room for rows and entries
V Value
the type of the values
Definition DynamicCsr.h:87
std::span< const V > values(std::size_t i) const
the values of the row
void remove(const R &E)
removes the rows of (a contiguous range of integers, e.g., a std::vector), closing the gaps in one p...
const V * val(void) const
Definition DynamicCsr.h:200
const I * ind(void) const
Definition DynamicCsr.h:197
I Index
the type of the indices
Definition DynamicCsr.h:86
DynamicCsr< I, V > DynamicCsc
the same by columns
Definition DynamicCsr.h:218
Definition ADT.h:96