mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-23 17:01:49 +01:00
Implement SpanEqual
and SpanHash
We desire the ability to hash and check equality of data across spans to use associative containers such as `std::unordered_map` with spans. The implemented functions provide an easy way to do that.
This commit is contained in:
parent
df5d1256c2
commit
0baa90d641
@ -155,4 +155,26 @@ namespace skyline {
|
|||||||
span(Container &) -> span<typename Container::value_type>;
|
span(Container &) -> span<typename Container::value_type>;
|
||||||
template<typename Container>
|
template<typename Container>
|
||||||
span(const Container &) -> span<const typename Container::value_type>;
|
span(const Container &) -> span<const typename Container::value_type>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return If the contents of the two spans are byte-for-byte equal
|
||||||
|
*/
|
||||||
|
template<typename T, size_t Extent = std::dynamic_extent>
|
||||||
|
struct SpanEqual {
|
||||||
|
constexpr bool operator()(const span<T, Extent> &lhs, const span<T, Extent> &rhs) const {
|
||||||
|
if (lhs.size_bytes() != rhs.size_bytes())
|
||||||
|
return false;
|
||||||
|
return std::equal(lhs.begin(), lhs.end(), rhs.begin());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return A hash of the contents of the span
|
||||||
|
*/
|
||||||
|
template<typename T, size_t Extent = std::dynamic_extent>
|
||||||
|
struct SpanHash {
|
||||||
|
constexpr size_t operator()(const skyline::span<T, Extent> &x) const {
|
||||||
|
return XXH64(x.data(), x.size_bytes(), 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user