Add generation counted storage
This commit is contained in:
parent
721f319909
commit
9b614c6057
@ -16,6 +16,40 @@ namespace osrm
|
|||||||
namespace util
|
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
|
template <typename NodeID, typename Key> class ArrayStorage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user