summaryrefslogtreecommitdiffstats
path: root/util/digest/sequence.h
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/digest/sequence.h
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/digest/sequence.h')
-rw-r--r--util/digest/sequence.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/util/digest/sequence.h b/util/digest/sequence.h
new file mode 100644
index 00000000000..712331007b8
--- /dev/null
+++ b/util/digest/sequence.h
@@ -0,0 +1,48 @@
+#pragma once
+
+#include "numeric.h"
+#include <util/generic/hash.h>
+#include <util/generic/array_ref.h>
+
+template <typename ElementHash = void>
+class TRangeHash {
+private:
+ template <typename ElementType>
+ using TBase = std::conditional_t<
+ !std::is_void<ElementHash>::value,
+ ElementHash,
+ THash<ElementType>>;
+
+public:
+ template <typename Range>
+ size_t operator()(const Range& range) const {
+ size_t accumulated = 0;
+ for (const auto& element : range) {
+ accumulated = CombineHashes(accumulated, TBase<typename Range::value_type>()(element));
+ }
+ return accumulated;
+ }
+};
+
+using TSimpleRangeHash = TRangeHash<>;
+
+template <typename RegionHash = void>
+class TContiguousHash {
+private:
+ template <typename ElementType>
+ using TBase = std::conditional_t<
+ !std::is_void<RegionHash>::value,
+ RegionHash,
+ TRangeHash<ElementType>>;
+
+public:
+ template <typename ContainerType>
+ auto operator()(const ContainerType& container) const {
+ return operator()(MakeArrayRef(container));
+ }
+
+ template <typename ElementType>
+ auto operator()(const TArrayRef<ElementType>& data) const {
+ return TBase<ElementType>()(data);
+ }
+};