diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/digest/lower_case | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/digest/lower_case')
-rw-r--r-- | library/cpp/digest/lower_case/hash_ops.cpp | 44 | ||||
-rw-r--r-- | library/cpp/digest/lower_case/hash_ops.h | 24 | ||||
-rw-r--r-- | library/cpp/digest/lower_case/hash_ops_ut.cpp | 56 | ||||
-rw-r--r-- | library/cpp/digest/lower_case/lchash.cpp | 2 | ||||
-rw-r--r-- | library/cpp/digest/lower_case/lchash.h | 28 | ||||
-rw-r--r-- | library/cpp/digest/lower_case/lchash_ut.cpp | 32 | ||||
-rw-r--r-- | library/cpp/digest/lower_case/lciter.cpp | 2 | ||||
-rw-r--r-- | library/cpp/digest/lower_case/lciter.h | 68 | ||||
-rw-r--r-- | library/cpp/digest/lower_case/ut/ya.make | 16 | ||||
-rw-r--r-- | library/cpp/digest/lower_case/ya.make | 26 |
10 files changed, 149 insertions, 149 deletions
diff --git a/library/cpp/digest/lower_case/hash_ops.cpp b/library/cpp/digest/lower_case/hash_ops.cpp index 3f1746d830..cbc25394a8 100644 --- a/library/cpp/digest/lower_case/hash_ops.cpp +++ b/library/cpp/digest/lower_case/hash_ops.cpp @@ -1,23 +1,23 @@ -#include "lchash.h" -#include "lciter.h" -#include "hash_ops.h" - -#include <util/generic/algorithm.h> - -size_t TCIOps::operator()(const TStringBuf& s) const noexcept { - return FnvCaseLess(s, (size_t)0xBEE); -} - -size_t TCIOps::operator()(const char* s) const noexcept { - return operator()(TStringBuf(s)); -} - -bool TCIOps::operator()(const TStringBuf& f, const TStringBuf& s) const noexcept { - using TIter = TLowerCaseIterator<const char>; - +#include "lchash.h" +#include "lciter.h" +#include "hash_ops.h" + +#include <util/generic/algorithm.h> + +size_t TCIOps::operator()(const TStringBuf& s) const noexcept { + return FnvCaseLess(s, (size_t)0xBEE); +} + +size_t TCIOps::operator()(const char* s) const noexcept { + return operator()(TStringBuf(s)); +} + +bool TCIOps::operator()(const TStringBuf& f, const TStringBuf& s) const noexcept { + using TIter = TLowerCaseIterator<const char>; + return (f.size() == s.size()) && Equal(TIter(f.begin()), TIter(f.end()), TIter(s.begin())); -} - -bool TCIOps::operator()(const char* f, const char* s) const noexcept { - return operator()(TStringBuf(f), TStringBuf(s)); -} +} + +bool TCIOps::operator()(const char* f, const char* s) const noexcept { + return operator()(TStringBuf(f), TStringBuf(s)); +} diff --git a/library/cpp/digest/lower_case/hash_ops.h b/library/cpp/digest/lower_case/hash_ops.h index 83ebf7aca4..54267c1ee4 100644 --- a/library/cpp/digest/lower_case/hash_ops.h +++ b/library/cpp/digest/lower_case/hash_ops.h @@ -1,13 +1,13 @@ -#pragma once - -#include <util/generic/strbuf.h> - +#pragma once + +#include <util/generic/strbuf.h> + // can be used for caseless hashes like: THashMap<TStringBuf, T, TCIOps, TCIOps> - -struct TCIOps { - size_t operator()(const char* s) const noexcept; - size_t operator()(const TStringBuf& s) const noexcept; - - bool operator()(const char* f, const char* s) const noexcept; - bool operator()(const TStringBuf& f, const TStringBuf& s) const noexcept; -}; + +struct TCIOps { + size_t operator()(const char* s) const noexcept; + size_t operator()(const TStringBuf& s) const noexcept; + + bool operator()(const char* f, const char* s) const noexcept; + bool operator()(const TStringBuf& f, const TStringBuf& s) const noexcept; +}; diff --git a/library/cpp/digest/lower_case/hash_ops_ut.cpp b/library/cpp/digest/lower_case/hash_ops_ut.cpp index a7ab0b86ea..47f154ffb2 100644 --- a/library/cpp/digest/lower_case/hash_ops_ut.cpp +++ b/library/cpp/digest/lower_case/hash_ops_ut.cpp @@ -1,36 +1,36 @@ -#include "hash_ops.h" - +#include "hash_ops.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TestCIHash) { Y_UNIT_TEST(TestYHash1) { THashMap<TStringBuf, int, TCIOps, TCIOps> h; - - h["Ab"] = 1; - h["aB"] = 2; - - UNIT_ASSERT_VALUES_EQUAL(h.size(), 1); - UNIT_ASSERT_VALUES_EQUAL(h["ab"], 2); - } - + + h["Ab"] = 1; + h["aB"] = 2; + + UNIT_ASSERT_VALUES_EQUAL(h.size(), 1); + UNIT_ASSERT_VALUES_EQUAL(h["ab"], 2); + } + Y_UNIT_TEST(TestYHash2) { THashMap<const char*, int, TCIOps, TCIOps> h; - - h["Ab"] = 1; - h["aB"] = 2; - - UNIT_ASSERT_VALUES_EQUAL(h.size(), 1); - UNIT_ASSERT_VALUES_EQUAL(h["ab"], 2); - - h["Bc"] = 2; - h["bC"] = 3; - - UNIT_ASSERT_VALUES_EQUAL(h.size(), 2); - UNIT_ASSERT_VALUES_EQUAL(h["bc"], 3); - } - + + h["Ab"] = 1; + h["aB"] = 2; + + UNIT_ASSERT_VALUES_EQUAL(h.size(), 1); + UNIT_ASSERT_VALUES_EQUAL(h["ab"], 2); + + h["Bc"] = 2; + h["bC"] = 3; + + UNIT_ASSERT_VALUES_EQUAL(h.size(), 2); + UNIT_ASSERT_VALUES_EQUAL(h["bc"], 3); + } + Y_UNIT_TEST(Test1) { UNIT_ASSERT_VALUES_EQUAL(TCIOps()("aBc3"), TCIOps()(TStringBuf("AbC3"))); - UNIT_ASSERT(TCIOps()("aBc4", "AbC4")); - } -} + UNIT_ASSERT(TCIOps()("aBc4", "AbC4")); + } +} diff --git a/library/cpp/digest/lower_case/lchash.cpp b/library/cpp/digest/lower_case/lchash.cpp index 92b4245533..51a7ff5799 100644 --- a/library/cpp/digest/lower_case/lchash.cpp +++ b/library/cpp/digest/lower_case/lchash.cpp @@ -1 +1 @@ -#include "lchash.h" +#include "lchash.h" diff --git a/library/cpp/digest/lower_case/lchash.h b/library/cpp/digest/lower_case/lchash.h index 6a287d9479..007d723e21 100644 --- a/library/cpp/digest/lower_case/lchash.h +++ b/library/cpp/digest/lower_case/lchash.h @@ -1,18 +1,18 @@ -#pragma once - -#include "lciter.h" - -#include <util/digest/fnv.h> -#include <util/generic/strbuf.h> - -template <class T> +#pragma once + +#include "lciter.h" + +#include <util/digest/fnv.h> +#include <util/generic/strbuf.h> + +template <class T> static inline T FnvCaseLess(const char* b, size_t l, T t = 0) noexcept { using TIter = TLowerCaseIterator<const char>; - - return FnvHash(TIter(b), TIter(b + l), t); -} - -template <class T> + + return FnvHash(TIter(b), TIter(b + l), t); +} + +template <class T> static inline T FnvCaseLess(const TStringBuf& s, T t = 0) noexcept { return FnvCaseLess(s.data(), s.size(), t); -} +} diff --git a/library/cpp/digest/lower_case/lchash_ut.cpp b/library/cpp/digest/lower_case/lchash_ut.cpp index 5711fe7cd7..9b40f38667 100644 --- a/library/cpp/digest/lower_case/lchash_ut.cpp +++ b/library/cpp/digest/lower_case/lchash_ut.cpp @@ -1,21 +1,21 @@ -#include "lchash.h" - +#include "lchash.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TWebDaemonHash) { Y_UNIT_TEST(Stability) { - UNIT_ASSERT_VALUES_EQUAL(FnvCaseLess<ui64>("blah"), ULL(5923727754379976229)); - UNIT_ASSERT_VALUES_EQUAL(FnvCaseLess<ui64>("blahminor"), ULL(8755704309003440816)); - } - + UNIT_ASSERT_VALUES_EQUAL(FnvCaseLess<ui64>("blah"), ULL(5923727754379976229)); + UNIT_ASSERT_VALUES_EQUAL(FnvCaseLess<ui64>("blahminor"), ULL(8755704309003440816)); + } + Y_UNIT_TEST(CaseLess) { - UNIT_ASSERT_VALUES_EQUAL(FnvCaseLess<ui64>("blah"), FnvCaseLess<ui64>("bLah")); - UNIT_ASSERT_VALUES_EQUAL(FnvCaseLess<ui64>("blah"), FnvCaseLess<ui64>("blAh")); - UNIT_ASSERT_VALUES_EQUAL(FnvCaseLess<ui64>("blah"), FnvCaseLess<ui64>("BLAH")); - } - + UNIT_ASSERT_VALUES_EQUAL(FnvCaseLess<ui64>("blah"), FnvCaseLess<ui64>("bLah")); + UNIT_ASSERT_VALUES_EQUAL(FnvCaseLess<ui64>("blah"), FnvCaseLess<ui64>("blAh")); + UNIT_ASSERT_VALUES_EQUAL(FnvCaseLess<ui64>("blah"), FnvCaseLess<ui64>("BLAH")); + } + Y_UNIT_TEST(Robustness) { - UNIT_ASSERT(FnvCaseLess<ui64>("x-real-ip") != FnvCaseLess<ui64>("x-req-id")); - UNIT_ASSERT(FnvCaseLess<ui64>("x-real-ip") != FnvCaseLess<ui64>("x-start-time")); - } -} + UNIT_ASSERT(FnvCaseLess<ui64>("x-real-ip") != FnvCaseLess<ui64>("x-req-id")); + UNIT_ASSERT(FnvCaseLess<ui64>("x-real-ip") != FnvCaseLess<ui64>("x-start-time")); + } +} diff --git a/library/cpp/digest/lower_case/lciter.cpp b/library/cpp/digest/lower_case/lciter.cpp index 38d23eb2dd..d204536e8d 100644 --- a/library/cpp/digest/lower_case/lciter.cpp +++ b/library/cpp/digest/lower_case/lciter.cpp @@ -1 +1 @@ -#include "lciter.h" +#include "lciter.h" diff --git a/library/cpp/digest/lower_case/lciter.h b/library/cpp/digest/lower_case/lciter.h index 9538e57932..87f47c7a82 100644 --- a/library/cpp/digest/lower_case/lciter.h +++ b/library/cpp/digest/lower_case/lciter.h @@ -1,42 +1,42 @@ -#pragma once - -#include <util/generic/typetraits.h> -#include <util/string/ascii.h> - +#pragma once + +#include <util/generic/typetraits.h> +#include <util/string/ascii.h> + #include <iterator> - -template <class T> + +template <class T> struct TLowerCaseIterator: public std::iterator<std::input_iterator_tag, T> { using TNonConst = std::remove_const_t<T>; - - inline TLowerCaseIterator(T* c) - : C(c) - { - } - + + inline TLowerCaseIterator(T* c) + : C(c) + { + } + inline TLowerCaseIterator& operator++() noexcept { - ++C; - - return *this; - } - + ++C; + + return *this; + } + inline TLowerCaseIterator operator++(int) noexcept { - return C++; - } - + return C++; + } + inline TNonConst operator*() const noexcept { - return AsciiToLower(*C); - } - - T* C; -}; - -template <class T> + return AsciiToLower(*C); + } + + T* C; +}; + +template <class T> inline bool operator==(const TLowerCaseIterator<T>& l, const TLowerCaseIterator<T>& r) noexcept { - return l.C == r.C; -} - -template <class T> + return l.C == r.C; +} + +template <class T> inline bool operator!=(const TLowerCaseIterator<T>& l, const TLowerCaseIterator<T>& r) noexcept { - return !(l == r); -} + return !(l == r); +} diff --git a/library/cpp/digest/lower_case/ut/ya.make b/library/cpp/digest/lower_case/ut/ya.make index f083257b3d..adfb14818d 100644 --- a/library/cpp/digest/lower_case/ut/ya.make +++ b/library/cpp/digest/lower_case/ut/ya.make @@ -1,13 +1,13 @@ UNITTEST_FOR(library/cpp/digest/lower_case) - + OWNER( pg g:util ) - -SRCS( - lchash_ut.cpp - hash_ops_ut.cpp -) - -END() + +SRCS( + lchash_ut.cpp + hash_ops_ut.cpp +) + +END() diff --git a/library/cpp/digest/lower_case/ya.make b/library/cpp/digest/lower_case/ya.make index 62cc16556a..bb6dee8ea9 100644 --- a/library/cpp/digest/lower_case/ya.make +++ b/library/cpp/digest/lower_case/ya.make @@ -1,14 +1,14 @@ -LIBRARY() - -OWNER( - pg +LIBRARY() + +OWNER( + pg g:util -) - -SRCS( - lciter.cpp - lchash.cpp - hash_ops.cpp -) - -END() +) + +SRCS( + lciter.cpp + lchash.cpp + hash_ops.cpp +) + +END() |