Adapts XORFastHashStorage to XORFastHash compile time limits
This commit is contained in:
parent
a6e7954128
commit
312b414d8f
@ -11,7 +11,8 @@ namespace osrm
|
|||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename NodeID, typename Key> class XORFastHashStorage
|
template <typename NodeID, typename Key, std::size_t MaxNumElements = (1u << 16u)>
|
||||||
|
class XORFastHashStorage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct HashCell
|
struct HashCell
|
||||||
@ -26,22 +27,18 @@ template <typename NodeID, typename Key> class XORFastHashStorage
|
|||||||
}
|
}
|
||||||
|
|
||||||
HashCell(const HashCell &other) : time(other.key), id(other.id), key(other.time) {}
|
HashCell(const HashCell &other) : time(other.key), id(other.id), key(other.time) {}
|
||||||
|
|
||||||
operator Key() const { return key; }
|
operator Key() const { return key; }
|
||||||
|
|
||||||
void operator=(const Key key_to_insert) { key = key_to_insert; }
|
void operator=(const Key key_to_insert) { key = key_to_insert; }
|
||||||
};
|
};
|
||||||
|
|
||||||
XORFastHashStorage() = delete;
|
explicit XORFastHashStorage(size_t) : positions(MaxNumElements), current_timestamp{0u} {}
|
||||||
|
|
||||||
explicit XORFastHashStorage(size_t) : positions(1u << 16u), current_timestamp(0) {}
|
|
||||||
|
|
||||||
HashCell &operator[](const NodeID node)
|
HashCell &operator[](const NodeID node)
|
||||||
{
|
{
|
||||||
std::uint16_t position = fast_hasher(node);
|
std::uint16_t position = fast_hasher(node);
|
||||||
while ((positions[position].time == current_timestamp) && (positions[position].id != node))
|
while ((positions[position].time == current_timestamp) && (positions[position].id != node))
|
||||||
{
|
{
|
||||||
++position %= (1u << 16u);
|
++position %= MaxNumElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
positions[position].time = current_timestamp;
|
positions[position].time = current_timestamp;
|
||||||
@ -58,7 +55,7 @@ template <typename NodeID, typename Key> class XORFastHashStorage
|
|||||||
std::uint16_t position = fast_hasher(node);
|
std::uint16_t position = fast_hasher(node);
|
||||||
while ((positions[position].time == current_timestamp) && (positions[position].id != node))
|
while ((positions[position].time == current_timestamp) && (positions[position].id != node))
|
||||||
{
|
{
|
||||||
++position %= (1u << 16u);
|
++position %= MaxNumElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_ASSERT(position < positions.size());
|
BOOST_ASSERT(position < positions.size());
|
||||||
@ -72,13 +69,13 @@ template <typename NodeID, typename Key> class XORFastHashStorage
|
|||||||
if (std::numeric_limits<unsigned>::max() == current_timestamp)
|
if (std::numeric_limits<unsigned>::max() == current_timestamp)
|
||||||
{
|
{
|
||||||
positions.clear();
|
positions.clear();
|
||||||
positions.resize(1u << 16u);
|
positions.resize(MaxNumElements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<HashCell> positions;
|
std::vector<HashCell> positions;
|
||||||
XORFastHash<> fast_hasher;
|
XORFastHash<MaxNumElements> fast_hasher;
|
||||||
unsigned current_timestamp;
|
unsigned current_timestamp;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user