tatami
C++ API for different matrix representations
Loading...
Searching...
No Matches
FixedOracle.hpp
Go to the documentation of this file.
1#ifndef TATAMI_FIXED_ORACLE_HPP
2#define TATAMI_FIXED_ORACLE_HPP
3
4#include "../base/Oracle.hpp"
5
6#include <vector>
7#include <cstddef>
8
9#include "sanisizer/sanisizer.hpp"
10
17namespace tatami {
18
25template<typename Index_, typename Pointer_ = const Index_*>
26class FixedViewOracle final : public Oracle<Index_> {
27public:
33 FixedViewOracle(Pointer_ ptr, const PredictionIndex number) : my_reference(ptr), my_length(number) {
34 sanisizer::can_cast<std::size_t>(number); // make sure that array is addressable by all [0, number).
35 }
36
38 return my_length;
39 }
40
41 Index_ get(PredictionIndex i) const {
42 return my_reference[i];
43 }
44
45private:
46 Pointer_ my_reference;
47 PredictionIndex my_length;
48};
49
57template<typename Index_, class Container_ = std::vector<Index_> >
58class FixedVectorOracle final : public Oracle<Index_> {
59public:
63 FixedVectorOracle(Container_ sequence) : my_sequence(std::move(sequence)) {
64 sanisizer::can_cast<PredictionIndex>(my_sequence.size()); // make sure that total() will return a sensible value.
65 }
66
68 return my_sequence.size();
69 }
70
71 Index_ get(PredictionIndex i) const {
72 return my_sequence[i];
73 }
74
75private:
76 Container_ my_sequence;
77};
78
79}
80
81#endif
Oracle for data access.
Predict future accesses from a vector containing a fixed sequence.
Definition FixedOracle.hpp:58
PredictionIndex total() const
Definition FixedOracle.hpp:67
Index_ get(PredictionIndex i) const
Definition FixedOracle.hpp:71
FixedVectorOracle(Container_ sequence)
Definition FixedOracle.hpp:63
Predict future accesses from a view on a fixed sequence.
Definition FixedOracle.hpp:26
Index_ get(PredictionIndex i) const
Definition FixedOracle.hpp:41
PredictionIndex total() const
Definition FixedOracle.hpp:37
FixedViewOracle(Pointer_ ptr, const PredictionIndex number)
Definition FixedOracle.hpp:33
Predict future access requests on the target dimension.
Definition Oracle.hpp:29
Flexible representations for matrix data.
Definition Extractor.hpp:15
std::size_t PredictionIndex
Definition Oracle.hpp:18