diff options
author | David Neto <dneto@google.com> | 2019-02-20 17:18:28 -0500 |
---|---|---|
committer | David Neto <dneto@google.com> | 2019-02-21 19:52:57 -0500 |
commit | 83d14e6912c72138f77617d225a2f4a8786a9d82 (patch) | |
tree | 9ff24faf1e0271a77fbb0019edf793cfc0518a93 /util/mix.h | |
parent | 03e00e139ba1ef1ac728bb9b78181cf74a6b93be (diff) | |
parent | 79ef3b2d31f06493f687ef9e947d9632bad54b9b (diff) | |
download | regex-re2-83d14e6912c72138f77617d225a2f4a8786a9d82.tar.gz |
Merge remote-tracking branch 'aosp/upstream-master' into up-shaderc2
Refresh with content from github.com/google/re2
commit 79ef3b2d31f06493f687ef9e947d9632bad54b9b
date 2019-02-13
Change-Id: I4139f29d632e41722992309e96aca4f29c799c87
Diffstat (limited to 'util/mix.h')
-rw-r--r-- | util/mix.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/util/mix.h b/util/mix.h new file mode 100644 index 0000000..d85c172 --- /dev/null +++ b/util/mix.h @@ -0,0 +1,41 @@ +// Copyright 2016 The RE2 Authors. All Rights Reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#ifndef UTIL_MIX_H_ +#define UTIL_MIX_H_ + +#include <stddef.h> +#include <limits> + +namespace re2 { + +// Silence "truncation of constant value" warning for kMul in 32-bit mode. +// Since this is a header file, push and then pop to limit the scope. +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4309) +#endif + +class HashMix { + public: + HashMix() : hash_(1) {} + explicit HashMix(size_t val) : hash_(val + 83) {} + void Mix(size_t val) { + static const size_t kMul = static_cast<size_t>(0xdc3eb94af8ab4c93ULL); + hash_ *= kMul; + hash_ = ((hash_ << 19) | + (hash_ >> (std::numeric_limits<size_t>::digits - 19))) + val; + } + size_t get() const { return hash_; } + private: + size_t hash_; +}; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +} // namespace re2 + +#endif // UTIL_MIX_H_ |