Dear list,
I need to get the all pair shortest path in a C array, to pass it to a
java program.
However johnson all pair shortest path[1] requires a BasicMatrix[2] as
output, so a simple array won't do.
At the moment I used few classes (see Matrix and MatrixR[3]) as
wrapper around a std::vector and it works fine, but I was wondering if
I am missing a simpler solution. Is there?
Yours faithfully,
Paolo
[1]http://www.boost.org/doc/libs/release/libs/graph/doc/johnson_all_pairs_short...
[2]http://www.boost.org/doc/libs/release/libs/graph/doc/BasicMatrix.html
[3]
struct Matrix {
Matrix(std::vector& storage, size_t rows, size_t columns)
: m_(storage),
columns_(columns)
{
m_.clear();
m_.resize(rows * columns_, int64_t{0});
}
int64_t& get(size_t row, size_t column) {
return m_[row * columns_ + column];
}
std::vector& m_;
size_t columns_;
};
struct MatrixR;
struct MatrixRR {
MatrixRR(MatrixR const& m, size_t column)
: m_(m),
column_(column)
{}
int64_t& operator[] (size_t row) const;
MatrixR const& m_;
size_t column_;
};
struct MatrixR {
MatrixR(Matrix& m)
: m_(m)
{}
MatrixRR operator[] (size_t column) const {
return MatrixRR(*this, column);
}
Matrix& m_;
};
int64_t &
MatrixRR ::
operator[] (size_t row) const {
return m_.m_.get(row, column_);
}