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

84 lines
2.7 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"
2021-06-02 10:02:21 +02:00
#include <iostream>
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-06-04 22:16:34 +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
*/
2021-06-04 22:16:34 +02:00
public:
2021-05-28 12:43:27 +02:00
MatrixCSR();
2021-05-31 11:26:27 +02:00
MatrixCSR(const ulong, const ulong); // A matrix of some specified dimension
2021-05-28 12:43:27 +02:00
MatrixCSR(const MatrixCSR&);
MatrixCSR(MatrixCSR&&) noexcept;
2021-05-28 12:43:27 +02:00
virtual ~MatrixCSR();
2021-06-02 21:03:10 +02:00
MatrixCSR& operator=(const MatrixCSR<Data>&);
MatrixCSR& operator=(MatrixCSR<Data>&&) noexcept;
2021-05-28 12:43:27 +02:00
bool operator==(const MatrixCSR&) const noexcept;
bool operator!=(const MatrixCSR&) const noexcept;
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-06-02 10:02:21 +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)
2021-05-28 12:43:27 +02:00
void Clear() override; // Override Container member
/* ************************************************************************ */
// Specific member functions (inherited from MappableContainer)
2021-06-04 22:16:34 +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
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
2021-06-02 10:02:21 +02:00
void debug();
};
/* ************************************************************************** */
}
#include "matrixcsr.cpp"
#endif