diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-05-27 12:49:05 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-05-11 12:23:48 +0200 |
commit | e6c0c282be59a5198932604d6c40de837b7cb548 (patch) | |
tree | 5b085ee69347fbd27bf0e9b14e7a42546afa5d40 /include/o3tl/hash_combine.hxx | |
parent | 57ed14b5c52c6a3504a7af8359dec436fcdf54f2 (diff) |
add o3tl version of hash_combine to not depend on boost for this
Change-Id: I081f8d116ef811baa8aa5de35a6cb51fa4de7d56
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114983
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include/o3tl/hash_combine.hxx')
-rw-r--r-- | include/o3tl/hash_combine.hxx | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/o3tl/hash_combine.hxx b/include/o3tl/hash_combine.hxx new file mode 100644 index 000000000000..17419b3e2c0f --- /dev/null +++ b/include/o3tl/hash_combine.hxx @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +namespace o3tl +{ +template <typename T, typename N, std::enable_if_t<(sizeof(N) == 4), bool> = false> +inline void hash_combine(N& nSeed, T const& nValue) +{ + static_assert(sizeof(nSeed) == 4); + nSeed ^= std::hash<T>{}(nValue) + 0x9E3779B9u + (nSeed << 6) + (nSeed >> 2); +} + +template <typename T, typename N, std::enable_if_t<(sizeof(N) == 8), bool> = false> +inline void hash_combine(N& nSeed, T const& nValue) +{ + static_assert(sizeof(nSeed) == 8); + nSeed ^= std::hash<T>{}(nValue) + 0x9E3779B97F4A7C15llu + (nSeed << 12) + (nSeed >> 4); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |