Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
HashSuite.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* HashSuite.h (C) 2000-2025 */
9/* */
10/* Hash function for a sequence of values. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_HASHSUITE_H
13#define ARCANE_UTILS_HASHSUITE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/HashFunction.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28/*!
29 * \internal
30 * \brief Class allowing for iterative hash calculation.
31 * \warning The order in which values are provided via the add() method is important.
32 */
34{
35 public:
36
37 /*!
38 * \brief Method allowing a value to be added to the hash calculation.
39 * \warning The order in which values are provided via the method
40 * add() is important.
41 * \param value The value to add.
42 */
43 template <class T>
44 void add(T value)
45 {
46 const UInt64 next_hash = static_cast<UInt64>(IntegerHashFunctionT<T>::hashfunc(value));
47 m_hash ^= next_hash + 0x9e3779b9 + (m_hash << 6) + (m_hash >> 2);
48 }
49
50 /*!
51 * \brief Method allowing retrieval of the hash calculated from
52 * all values passed to the add() method.
53 * \return The hash.
54 */
55 Int64 hash() const
56 {
57 return static_cast<Int64>(m_hash);
58 }
59
60 private:
61
62 UInt64 m_hash{ 0 };
63};
64
65/*---------------------------------------------------------------------------*/
66/*---------------------------------------------------------------------------*/
67
68} // End namespace Arcane
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
73#endif
void add(T value)
Method allowing a value to be added to the hash calculation.
Definition HashSuite.h:44
Int64 hash() const
Method allowing retrieval of the hash calculated from all values passed to the add() method.
Definition HashSuite.h:55
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::uint64_t UInt64
Unsigned integer type of 64 bits.
std::int64_t Int64
Signed integer type of 64 bits.