2015-08-19 08:04:59 -04:00
|
|
|
#ifndef DIST_TABLE_WRAPPER_H
|
|
|
|
#define DIST_TABLE_WRAPPER_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
#include <boost/assert.hpp>
|
2015-08-28 14:18:15 -04:00
|
|
|
#include <cstddef>
|
2015-08-19 08:04:59 -04:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
// This Wrapper provides an easier access to a distance table that is given as an linear vector
|
2015-08-19 08:04:59 -04:00
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
template <typename T> class DistTableWrapper
|
|
|
|
{
|
|
|
|
public:
|
2015-08-19 08:04:59 -04:00
|
|
|
using Iterator = typename std::vector<T>::iterator;
|
|
|
|
using ConstIterator = typename std::vector<T>::const_iterator;
|
|
|
|
|
|
|
|
DistTableWrapper(std::vector<T> table, std::size_t number_of_nodes)
|
2015-08-28 14:18:15 -04:00
|
|
|
: table_(std::move(table)), number_of_nodes_(number_of_nodes)
|
|
|
|
{
|
2015-08-19 08:04:59 -04:00
|
|
|
BOOST_ASSERT_MSG(table.size() == 0, "table is empty");
|
2015-08-28 14:18:15 -04:00
|
|
|
BOOST_ASSERT_MSG(number_of_nodes_ * number_of_nodes_ <= table_.size(),
|
|
|
|
"number_of_nodes_ is invalid");
|
2015-08-19 08:04:59 -04:00
|
|
|
};
|
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
std::size_t GetNumberOfNodes() const { return number_of_nodes_; }
|
2015-08-19 08:04:59 -04:00
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
std::size_t size() const { return table_.size(); }
|
2015-08-19 08:04:59 -04:00
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
EdgeWeight operator()(NodeID from, NodeID to) const
|
|
|
|
{
|
2015-08-19 08:04:59 -04:00
|
|
|
BOOST_ASSERT_MSG(from < number_of_nodes_, "from ID is out of bound");
|
|
|
|
BOOST_ASSERT_MSG(to < number_of_nodes_, "to ID is out of bound");
|
2015-08-20 09:32:28 -04:00
|
|
|
|
2015-08-19 08:04:59 -04:00
|
|
|
const auto index = from * number_of_nodes_ + to;
|
2015-08-20 09:32:28 -04:00
|
|
|
|
|
|
|
BOOST_ASSERT_MSG(index < table_.size(), "index is out of bound");
|
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
return table_[index];
|
2015-08-19 08:04:59 -04:00
|
|
|
}
|
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
ConstIterator begin() const { return std::begin(table_); }
|
2015-08-19 08:04:59 -04:00
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
Iterator begin() { return std::begin(table_); }
|
2015-08-19 08:04:59 -04:00
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
ConstIterator end() const { return std::end(table_); }
|
2015-08-19 08:04:59 -04:00
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
Iterator end() { return std::end(table_); }
|
2015-08-19 08:04:59 -04:00
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
NodeID GetIndexOfMaxValue() const
|
|
|
|
{
|
2015-08-19 08:04:59 -04:00
|
|
|
return std::distance(table_.begin(), std::max_element(table_.begin(), table_.end()));
|
|
|
|
}
|
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
std::vector<T> GetTable() const { return table_; }
|
2015-08-19 08:04:59 -04:00
|
|
|
|
2015-08-28 14:18:15 -04:00
|
|
|
private:
|
2015-08-19 08:04:59 -04:00
|
|
|
std::vector<T> table_;
|
|
|
|
const std::size_t number_of_nodes_;
|
|
|
|
};
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 08:04:59 -04:00
|
|
|
#endif // DIST_TABLE_WRAPPER_H
|