Program Listing for File DynamicCsr.h
↰ Return to documentation for file (ADS/numeric/DynamicCsr.h)
/*--------------------------------------------------------------------------*/
/*---------------------------- File DynamicCsr.h ---------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/
#ifndef __ADS_DynamicCsr
#define __ADS_DynamicCsr
/* self-identification: #endif constant */
/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/Contract.h"
#include "ADS/numeric/DenseMatrix.h"
#include <algorithm>
#include <cstddef>
#include <limits>
#include <ranges>
#include <span>
#include <type_traits>
#include <utility>
#include <vector>
/*--------------------------------------------------------------------------*/
/*--------------------------- NAMESPACE ------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace ADS {
/*--------------------------------------------------------------------------*/
/*---------------------------- CLASS DynamicCsr ----------------------------*/
/*--------------------------------------------------------------------------*/
template< class I = int , class V = double >
class DynamicCsr {
static_assert( std::is_integral_v< I > );
/*--------------------------------------------------------------------------*/
public:
using Index = I;
using Value = V;
DynamicCsr( void ) : f_beg( 1 , I( 0 ) ) {}
[[nodiscard]] std::size_t rows( void ) const {
return( f_beg.size() - 1 );
}
[[nodiscard]] std::size_t nonzeros( void ) const { return( f_ind.size() ); }
[[nodiscard]] bool empty( void ) const { return( rows() == 0 ); }
void reserve( std::size_t r , std::size_t z );
void clear( void );
std::size_t append( std::span< const I > ind , std::span< const V > val );
std::size_t append( std::size_t r , const I * beg , const I * ind ,
const V * val );
template< std::ranges::contiguous_range R >
void remove( const R & E );
void remove( std::size_t first , std::size_t last );
[[nodiscard]] std::span< const I > indices( std::size_t i ) const;
[[nodiscard]] std::span< const V > values( std::size_t i ) const;
[[nodiscard]] std::span< V > values( std::size_t i );
[[nodiscard]] const I * beg( void ) const { return( f_beg.data() ); }
[[nodiscard]] const I * ind( void ) const { return( f_ind.data() ); }
[[nodiscard]] const V * val( void ) const { return( f_val.data() ); }
/*--------------------------------------------------------------------------*/
private:
template< class U > // not zeroed when they grow
using Vector = std::vector< U , detail::DefaultInitAllocator< U > >;
[[nodiscard]] bool consistent( void ) const;
Vector< I > f_beg;
Vector< I > f_ind;
Vector< V > f_val;
}; // end( class DynamicCsr )
template< class I = int , class V = double >
using DynamicCsc = DynamicCsr< I , V >;
/*--------------------------------------------------------------------------*/
} // end( namespace ADS )
/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/numeric/impl/DynamicCsr.tpp"
/*--------------------------------------------------------------------------*/
#endif /* DynamicCsr.h included */
/*--------------------------------------------------------------------------*/
/*-------------------------- End File DynamicCsr.h -------------------------*/
/*--------------------------------------------------------------------------*/