lasd/librerie/exercise5/matrix/csr/matrixcsr.hpp

114 lines
3.6 KiB
C++
Raw Normal View History

#ifndef MATRIXCSR_HPP
#define MATRIXCSR_HPP
/* ************************************************************************** */
#include "../matrix.hpp"
2021-05-28 12:43:27 +02:00
#include "../../list/list.hpp"
#include "../../vector/vector.hpp"
namespace lasd {
template <typename Data>
2021-05-31 11:26:27 +02:00
class MatrixCSR : virtual public List<std::pair<Data,ulong>>,
2021-05-28 12:43:27 +02:00
virtual public Matrix<Data>{ // Must extend Matrix<Data>
2021-05-28 12:43:27 +02:00
protected:
2021-05-28 12:43:27 +02:00
using Matrix<Data>::rows;
using Matrix<Data>::columns;
using List<std::pair<Data,ulong>>::size;
2021-05-31 11:26:27 +02:00
Vector<struct List<std::pair<Data,ulong>>::Node**> R;
2021-05-28 12:43:27 +02:00
using List<std::pair<Data,ulong>>::head;
2021-05-31 11:26:27 +02:00
using typename List<std::pair<Data,ulong>>::Node;
2021-05-28 12:43:27 +02:00
/*
Node
| pair
| | Data (actual element - first)
| | ulong (column index - second)
| next
*/
public:
// Default constructor
2021-05-28 12:43:27 +02:00
MatrixCSR();
/* ************************************************************************ */
// Specific constructors
2021-05-31 11:26:27 +02:00
MatrixCSR(const ulong, const ulong); // A matrix of some specified dimension
/* ************************************************************************ */
// Copy constructor
2021-05-28 12:43:27 +02:00
MatrixCSR(const MatrixCSR&);
// Move constructor
2021-05-28 12:43:27 +02:00
MatrixCSR(MatrixCSR&&) noexcept;
/* ************************************************************************ */
// Destructor
2021-05-28 12:43:27 +02:00
virtual ~MatrixCSR();
/* ************************************************************************ */
// Copy assignment
2021-05-28 12:43:27 +02:00
MatrixCSR& operator=(const MatrixCSR&);
// Move assignment
2021-05-28 12:43:27 +02:00
MatrixCSR& operator=(MatrixCSR&&) noexcept;
/* ************************************************************************ */
// Comparison operators
2021-05-28 12:43:27 +02:00
bool operator==(const MatrixCSR&) const noexcept;
bool operator!=(const MatrixCSR&) const noexcept;
/* ************************************************************************ */
// Specific member functions (inherited from Matrix)
2021-05-28 12:43:27 +02:00
void RowResize(const ulong&) override; // Override Matrix member
void ColumnResize(const ulong&) override; // Override Matrix member
2021-05-31 11:26:27 +02:00
bool ExistsCell(const ulong&, const ulong&) const noexcept override; // Override Matrix member (should not throw exceptions)
2021-05-28 12:43:27 +02:00
Data& operator()(const ulong&, const ulong&) override; // Override Matrix member (mutable access to the element; throw out_of_range when out of range)
const Data& operator()(const ulong&, const ulong&) const override; // Override Matrix member (immutable access to the element; throw out_of_range when out of range and length_error when not present)
/* ************************************************************************ */
// Specific member functions (inherited from Container)
2021-05-28 12:43:27 +02:00
void Clear() override; // Override Container member
/* ************************************************************************ */
// Specific member functions (inherited from MappableContainer)
2021-05-28 12:43:27 +02:00
virtual void MapPreOrder(const typename MappableContainer<Data>::MapFunctor, void*) override; // Override MappableContainer member
virtual void MapPostOrder(const typename MappableContainer<Data>::MapFunctor, void*) override; // Override MappableContainer member
/* ************************************************************************ */
// Specific member functions (inherited from FoldableContainer)
2021-05-28 12:43:27 +02:00
virtual void FoldPreOrder(const typename FoldableContainer<Data>::FoldFunctor, const void*, void*) const override; // Override FoldableContainer member
virtual void FoldPostOrder(const typename FoldableContainer<Data>::FoldFunctor, const void*, void*) const override; // Override FoldableContainer member
};
/* ************************************************************************** */
}
#include "matrixcsr.cpp"
#endif