diff --git a/app/src/main/cpp/skyline/common/span.h b/app/src/main/cpp/skyline/common/span.h index 2904adf7..131a1a37 100644 --- a/app/src/main/cpp/skyline/common/span.h +++ b/app/src/main/cpp/skyline/common/span.h @@ -82,7 +82,7 @@ namespace skyline { /** * @return If a supplied span is located entirely inside this span and is effectively a subspan */ - constexpr bool contains(const span& other) const { + constexpr bool contains(const span &other) const { return this->begin() <= other.begin() && this->end() >= other.end(); } @@ -95,7 +95,7 @@ namespace skyline { /** Comparision operators for equality and binary searches **/ - constexpr bool operator==(const span& other) const { + constexpr bool operator==(const span &other) const { return this->data() == other.data() && this->size() == other.size(); } @@ -103,7 +103,7 @@ namespace skyline { return this->data() < other.data(); } - constexpr bool operator<(T* pointer) const { + constexpr bool operator<(T *pointer) const { return this->data() < pointer; } @@ -155,4 +155,26 @@ namespace skyline { span(Container &) -> span; template span(const Container &) -> span; + + /** + * @return If the contents of the two spans are byte-for-byte equal + */ + template + struct SpanEqual { + constexpr bool operator()(const span &lhs, const span &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 + struct SpanHash { + constexpr size_t operator()(const skyline::span &x) const { + return XXH64(x.data(), x.size_bytes(), 0); + } + }; }