aboutsummaryrefslogtreecommitdiffstats
path: root/util/digest/numeric.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/digest/numeric.h
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/digest/numeric.h')
-rw-r--r--util/digest/numeric.h132
1 files changed, 66 insertions, 66 deletions
diff --git a/util/digest/numeric.h b/util/digest/numeric.h
index e20bd908e4..87b8b648d6 100644
--- a/util/digest/numeric.h
+++ b/util/digest/numeric.h
@@ -1,86 +1,86 @@
#pragma once
-
+
#include <util/generic/typelist.h>
#include <util/system/defaults.h>
-
-/*
+
+/*
* original url (now dead): http://www.cris.com/~Ttwang/tech/inthash.htm
* copy: https://gist.github.com/badboy/6267743
- */
-
+ */
+
static constexpr ui8 IntHashImpl(ui8 key8) noexcept {
- size_t key = key8;
-
- key += ~(key << 15);
- key ^= (key >> 10);
- key += (key << 3);
- key ^= (key >> 6);
- key += ~(key << 11);
- key ^= (key >> 16);
-
+ size_t key = key8;
+
+ key += ~(key << 15);
+ key ^= (key >> 10);
+ key += (key << 3);
+ key ^= (key >> 6);
+ key += ~(key << 11);
+ key ^= (key >> 16);
+
return static_cast<ui8>(key);
-}
-
+}
+
static constexpr ui16 IntHashImpl(ui16 key16) noexcept {
- size_t key = key16;
-
- key += ~(key << 15);
- key ^= (key >> 10);
- key += (key << 3);
- key ^= (key >> 6);
- key += ~(key << 11);
- key ^= (key >> 16);
-
+ size_t key = key16;
+
+ key += ~(key << 15);
+ key ^= (key >> 10);
+ key += (key << 3);
+ key ^= (key >> 6);
+ key += ~(key << 11);
+ key ^= (key >> 16);
+
return static_cast<ui16>(key);
-}
-
+}
+
static constexpr ui32 IntHashImpl(ui32 key) noexcept {
- key += ~(key << 15);
- key ^= (key >> 10);
- key += (key << 3);
- key ^= (key >> 6);
- key += ~(key << 11);
- key ^= (key >> 16);
-
- return key;
-}
-
+ key += ~(key << 15);
+ key ^= (key >> 10);
+ key += (key << 3);
+ key ^= (key >> 6);
+ key += ~(key << 11);
+ key ^= (key >> 16);
+
+ return key;
+}
+
static constexpr ui64 IntHashImpl(ui64 key) noexcept {
- key += ~(key << 32);
- key ^= (key >> 22);
- key += ~(key << 13);
- key ^= (key >> 8);
- key += (key << 3);
- key ^= (key >> 15);
- key += ~(key << 27);
- key ^= (key >> 31);
-
+ key += ~(key << 32);
+ key ^= (key >> 22);
+ key += ~(key << 13);
+ key ^= (key >> 8);
+ key += (key << 3);
+ key ^= (key >> 15);
+ key += ~(key << 27);
+ key ^= (key >> 31);
+
return key;
-}
-
-template <class T>
+}
+
+template <class T>
static constexpr T IntHash(T t) noexcept {
using TCvt = TFixedWidthUnsignedInt<T>;
-
- return IntHashImpl((TCvt)(t));
-}
-
-/*
- * can handle floats && pointers
- */
-template <class T>
+
+ return IntHashImpl((TCvt)(t));
+}
+
+/*
+ * can handle floats && pointers
+ */
+template <class T>
static constexpr size_t NumericHash(T t) noexcept {
using TCvt = TFixedWidthUnsignedInt<T>;
-
- union Y_HIDDEN {
+
+ union Y_HIDDEN {
T t;
- TCvt cvt;
+ TCvt cvt;
} u{t};
-
+
return (size_t)IntHash(u.cvt);
-}
-
-template <class T>
+}
+
+template <class T>
static constexpr T CombineHashes(T l, T r) noexcept {
- return IntHash(l) ^ r;
-}
+ return IntHash(l) ^ r;
+}