Add generation counted storage

This commit is contained in:
Patrick Niklaus 2017-04-04 11:33:34 +00:00 committed by Patrick Niklaus
parent 721f319909
commit 9b614c6057

View File

@ -16,6 +16,40 @@ namespace osrm
namespace util
{
template <typename NodeID, typename Key> class GenerationArrayStorage
{
using GenerationCounter = std::uint16_t;
public:
explicit GenerationArrayStorage(std::size_t size) : positions(size, 0), generation(0), generations(size, 0) {}
Key &operator[](NodeID node) {
generation[node] = generation;
return positions[node];
}
Key peek_index(const NodeID node) const {
if (generations[node] < generation)
{
return std::numeric_limits<Key>::max();
}
return positions[node];
}
void Clear() {
generation++;
if (generation == std::numeric_limits<GenerationCounter>::max())
{
std::fill(generations.begin(), generations.end(), 0);
std::fill(positions.begin(), positions.end(), 0);
}
}
private:
GenerationCounter generation;
std::vector<GenerationCounter> generations;
std::vector<Key> positions;
};
template <typename NodeID, typename Key> class ArrayStorage
{
public: