6 #ifndef TURI_SYMMETRIC_ARRAY_H_ 7 #define TURI_SYMMETRIC_ARRAY_H_ 10 #include <core/storage/serialization/serialization_includes.hpp> 11 #include <core/logging/assertions.hpp> 30 , data(n*(n+1) / 2, default_value)
34 size_t size()
const {
return n; }
37 size_t rows()
const {
return n; }
40 size_t cols()
const {
return n; }
44 return data[_index(i,j)];
49 return data[_index(i,j)];
67 inline size_t _index(
size_t r,
size_t c)
const {
87 size_t idx = r*(r + 1) / 2 + c;
89 DASSERT_LT(idx, data.size());
T & operator()(size_t i, size_t j)
Access item (i, j) – same as (j, i) – by reference.
The serialization input archive object which, provided with a reference to an istream, will read from the istream, providing deserialization capabilities.
symmetric_2d_array(size_t _n, const T &default_value=T())
Init the 2d n x n symmetric array with default_value.
void save(turi::oarchive &oarc) const
save to disk
size_t size() const
Return the size of either the rows or the columns. (aka n)
size_t rows() const
Return the number of rows. (aka n)
void load(turi::iarchive &iarc)
load from disk
The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities.
size_t cols() const
Return the number of columns. (aka n)
const T & operator()(size_t i, size_t j) const
Access item (i, j) – same as (j, i) – by const reference.