diff options
author | breakneck <breakneck@yandex-team.ru> | 2022-02-10 16:47:58 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:58 +0300 |
commit | e2021f9a0e54d13b7c48796318b13b66dc625e74 (patch) | |
tree | 5aed1691033eaf399ab80a10a137238922035fa8 /util/digest | |
parent | 83602b1b564b92a80a1526d113fa2846661dd10e (diff) | |
download | ydb-e2021f9a0e54d13b7c48796318b13b66dc625e74.tar.gz |
Restoring authorship annotation for <breakneck@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/digest')
-rw-r--r-- | util/digest/murmur.h | 22 | ||||
-rw-r--r-- | util/digest/murmur_ut.cpp | 28 | ||||
-rw-r--r-- | util/digest/sequence.h | 90 | ||||
-rw-r--r-- | util/digest/sequence_ut.cpp | 84 | ||||
-rw-r--r-- | util/digest/ut/ya.make | 2 |
5 files changed, 113 insertions, 113 deletions
diff --git a/util/digest/murmur.h b/util/digest/murmur.h index 6b519b430a..0c3c8d3dbb 100644 --- a/util/digest/murmur.h +++ b/util/digest/murmur.h @@ -1,7 +1,7 @@ #pragma once #include <util/system/defaults.h> -#include <util/generic/array_ref.h> +#include <util/generic/array_ref.h> /* * murmur2 from http://murmurhash.googlepages.com/ @@ -41,15 +41,15 @@ static inline T MurmurHash(const void* buf, size_t len) noexcept { //non-inline version size_t MurmurHashSizeT(const char* buf, size_t len) noexcept; - -template <typename TOut = size_t> -struct TMurmurHash { + +template <typename TOut = size_t> +struct TMurmurHash { TOut operator()(const void* buf, size_t len) const noexcept { - return MurmurHash<TOut>(buf, len); - } - - template <typename ElementType> + return MurmurHash<TOut>(buf, len); + } + + template <typename ElementType> TOut operator()(const TArrayRef<ElementType>& data) const noexcept { - return operator()(data.data(), data.size() * sizeof(ElementType)); - } -}; + return operator()(data.data(), data.size() * sizeof(ElementType)); + } +}; diff --git a/util/digest/murmur_ut.cpp b/util/digest/murmur_ut.cpp index 29287668bc..4f763ba366 100644 --- a/util/digest/murmur_ut.cpp +++ b/util/digest/murmur_ut.cpp @@ -9,7 +9,7 @@ class TMurmurHashTest: public TTestBase { UNIT_TEST(TestUnalignedHash32) UNIT_TEST(TestHash64) UNIT_TEST(TestUnalignedHash64) - UNIT_TEST(TestWrapperBiggerTypes) + UNIT_TEST(TestWrapperBiggerTypes) UNIT_TEST_SUITE_END(); private: @@ -21,7 +21,7 @@ private: } Test<ui32>(buf, 256, 2373126550UL); - TestWrapper<ui8, ui32>({buf, buf + 256}, 2373126550UL); + TestWrapper<ui8, ui32>({buf, buf + 256}, 2373126550UL); Test<ui32>(buf, 255, 3301607533UL); Test<ui32>(buf, 254, 2547410121UL); Test<ui32>(buf, 253, 80030810UL); @@ -46,7 +46,7 @@ private: } Test<ui64>(buf, 256, ULL(12604435678857905857)); - TestWrapper<ui8, ui64>({buf, buf + 256}, ULL(12604435678857905857)); + TestWrapper<ui8, ui64>({buf, buf + 256}, ULL(12604435678857905857)); Test<ui64>(buf, 255, ULL(1708835094528446095)); Test<ui64>(buf, 254, ULL(5077937678736514994)); Test<ui64>(buf, 253, ULL(11553864555081396353)); @@ -63,23 +63,23 @@ private: Test<ui64>(unalignedBuf, 256, ULL(12604435678857905857)); } - inline void TestWrapperBiggerTypes() { - ui32 buf[] = {24, 42}; - TestWrapper<ui32, ui32>({buf, buf + 2}, MurmurHash<ui32>(buf, sizeof(ui32) * 2)); - TestWrapper<ui32, ui64>({buf, buf + 2}, MurmurHash<ui64>(buf, sizeof(ui32) * 2)); - } - + inline void TestWrapperBiggerTypes() { + ui32 buf[] = {24, 42}; + TestWrapper<ui32, ui32>({buf, buf + 2}, MurmurHash<ui32>(buf, sizeof(ui32) * 2)); + TestWrapper<ui32, ui64>({buf, buf + 2}, MurmurHash<ui64>(buf, sizeof(ui32) * 2)); + } + private: template <class T> inline void Test(const void* data, size_t len, T expected) { UNIT_ASSERT_STRINGS_EQUAL(ToString(MurmurHash<T>(data, len)), ToString(expected)); } - - template <class E, class T> + + template <class E, class T> inline void TestWrapper(const TArrayRef<E>& array, T expected) { - auto val = TMurmurHash<T>()(array); - UNIT_ASSERT_EQUAL(val, expected); - } + auto val = TMurmurHash<T>()(array); + UNIT_ASSERT_EQUAL(val, expected); + } }; UNIT_TEST_SUITE_REGISTRATION(TMurmurHashTest); diff --git a/util/digest/sequence.h b/util/digest/sequence.h index 712331007b..a8a1bce688 100644 --- a/util/digest/sequence.h +++ b/util/digest/sequence.h @@ -1,48 +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, +#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, + +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> + +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); - } -}; + return TBase<ElementType>()(data); + } +}; diff --git a/util/digest/sequence_ut.cpp b/util/digest/sequence_ut.cpp index 87d6102ee5..f49ebc9638 100644 --- a/util/digest/sequence_ut.cpp +++ b/util/digest/sequence_ut.cpp @@ -1,62 +1,62 @@ -#include "sequence.h" - +#include "sequence.h" + #include <library/cpp/testing/unittest/registar.h> #include <util/generic/map.h> -#include <util/generic/vector.h> - -class TRangeHashTest: public TTestBase { - UNIT_TEST_SUITE(TRangeHashTest); - UNIT_TEST(TestStrokaInt) - UNIT_TEST(TestIntVector) - UNIT_TEST(TestOneElement) +#include <util/generic/vector.h> + +class TRangeHashTest: public TTestBase { + UNIT_TEST_SUITE(TRangeHashTest); + UNIT_TEST(TestStrokaInt) + UNIT_TEST(TestIntVector) + UNIT_TEST(TestOneElement) UNIT_TEST(TestMap); - UNIT_TEST(TestCollectionIndependancy); - UNIT_TEST_SUITE_END(); - -private: - inline void TestStrokaInt() { + UNIT_TEST(TestCollectionIndependancy); + UNIT_TEST_SUITE_END(); + +private: + inline void TestStrokaInt() { const size_t canonicalHash = static_cast<size_t>(ULL(12727184940294366172)); UNIT_ASSERT_EQUAL(canonicalHash, TRangeHash<>()(TString("12345"))); - } - - inline void TestIntVector() { + } + + inline void TestIntVector() { const size_t canonicalHash = static_cast<size_t>(ULL(1351128487744230578)); TVector<int> testVec = {1, 2, 4, 3}; - UNIT_ASSERT_EQUAL(canonicalHash, TRangeHash<>()(testVec)); - } - - inline void TestOneElement() { - const int testVal = 42; + UNIT_ASSERT_EQUAL(canonicalHash, TRangeHash<>()(testVec)); + } + + inline void TestOneElement() { + const int testVal = 42; TVector<int> testVec = {testVal}; - UNIT_ASSERT_UNEQUAL(THash<int>()(testVal), TRangeHash<>()(testVec)); - } - + UNIT_ASSERT_UNEQUAL(THash<int>()(testVal), TRangeHash<>()(testVec)); + } + inline void TestMap() { const size_t canonicalHash = static_cast<size_t>(ULL(4415387926488545605)); TMap<TString, int> testMap{{"foo", 123}, {"bar", 456}}; UNIT_ASSERT_EQUAL(canonicalHash, TRangeHash<>()(testMap)); } - inline void TestCollectionIndependancy() { + inline void TestCollectionIndependancy() { TVector<char> testVec = {'a', 'b', 'c'}; TString testStroka = "abc"; - UNIT_ASSERT_EQUAL(TRangeHash<>()(testVec), TRangeHash<>()(testStroka)); - } -}; - + UNIT_ASSERT_EQUAL(TRangeHash<>()(testVec), TRangeHash<>()(testStroka)); + } +}; + class TSequenceHashTest: public TTestBase { - UNIT_TEST_SUITE(TSequenceHashTest); - UNIT_TEST(TestSimpleBuffer) - UNIT_TEST_SUITE_END(); + UNIT_TEST_SUITE(TSequenceHashTest); + UNIT_TEST(TestSimpleBuffer) + UNIT_TEST_SUITE_END(); -private: - inline void TestSimpleBuffer() { - int arr[] = {1, 2, 3}; +private: + inline void TestSimpleBuffer() { + int arr[] = {1, 2, 3}; const size_t canonicalHash = static_cast<size_t>(ULL(3903918011533391876)); - TContiguousHash<TSimpleRangeHash> hasher; + TContiguousHash<TSimpleRangeHash> hasher; UNIT_ASSERT_EQUAL(canonicalHash, hasher(TArrayRef<int>(arr, arr + 3))); - } -}; - -UNIT_TEST_SUITE_REGISTRATION(TRangeHashTest); -UNIT_TEST_SUITE_REGISTRATION(TSequenceHashTest); + } +}; + +UNIT_TEST_SUITE_REGISTRATION(TRangeHashTest); +UNIT_TEST_SUITE_REGISTRATION(TSequenceHashTest); diff --git a/util/digest/ut/ya.make b/util/digest/ut/ya.make index 245b2cf6d2..25d2f50ba3 100644 --- a/util/digest/ut/ya.make +++ b/util/digest/ut/ya.make @@ -7,7 +7,7 @@ SRCS( digest/fnv_ut.cpp digest/murmur_ut.cpp digest/multi_ut.cpp - digest/sequence_ut.cpp + digest/sequence_ut.cpp ) INCLUDE(${ARCADIA_ROOT}/util/tests/ya_util_tests.inc) |