mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
Improving the hash function
Using Szudzik's pairing function (more efficient than the previous approach or Cantor's)
This commit is contained in:
parent
fbae8cd6c1
commit
48c126cf9c
@ -262,11 +262,13 @@ namespace std {
|
||||
template <>
|
||||
struct hash<xlnt::cell_reference>
|
||||
{
|
||||
size_t operator()(const xlnt::cell_reference &x) const
|
||||
size_t operator()(const xlnt::cell_reference &x) const // using Szudzik's pairing function
|
||||
{
|
||||
static_assert(std::is_same<decltype(x.row()), std::uint32_t>::value, "this hash function expects both row and column to be 32-bit numbers");
|
||||
static_assert(std::is_same<decltype(x.column_index()), std::uint32_t>::value, "this hash function expects both row and column to be 32-bit numbers");
|
||||
return hash<std::uint64_t>{}(x.row() | static_cast<std::uint64_t>(x.column_index()) << 32);
|
||||
if (x.column_index() >= x.row()) {
|
||||
return hash<size_t>{}(x.column_index() * x.column_index() + x.column_index() + x.row());
|
||||
} else {
|
||||
return hash<size_t>{}(x.column_index() + x.row() * x.row());
|
||||
};
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
Loading…
x
Reference in New Issue
Block a user