Make XORFastHash's number of hashable elements compile time constant

Still constraint by the usage of uint32_t and subsequent splitting into
two uint16_t we use for indexing into the tables.
This commit is contained in:
Daniel J. Hofmann 2016-01-21 19:17:02 +01:00
parent 1417d43430
commit a6e7954128
3 changed files with 8 additions and 6 deletions

View File

@ -1096,7 +1096,7 @@ class GraphContractor
// self-loops are added.
std::vector<EdgeWeight> node_weights;
std::vector<bool> is_core_node;
util::XORFastHash fast_hash;
util::XORFastHash<> fast_hash;
};
}
}

View File

@ -35,10 +35,12 @@ namespace util
10: ret
*/
class XORFastHash
{ // 65k entries
std::array<std::uint16_t, (1u << 16u)> table1;
std::array<std::uint16_t, (1u << 16u)> table2;
template <std::size_t MaxNumElements = (1u << 16u)> class XORFastHash
{
static_assert(MaxNumElements <= (1u << 16u), "only 65536 elements indexable with uint16_t");
std::array<std::uint16_t, MaxNumElements> table1;
std::array<std::uint16_t, MaxNumElements> table2;
public:
XORFastHash()

View File

@ -78,7 +78,7 @@ template <typename NodeID, typename Key> class XORFastHashStorage
private:
std::vector<HashCell> positions;
XORFastHash fast_hasher;
XORFastHash<> fast_hasher;
unsigned current_timestamp;
};
}