Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
HashFunction.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* HashFunction.cc (C) 2000-2023 */
9/* */
10/* Fonction de hachage. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/HashFunction.h"
15#include "arcane/utils/String.h"
16
17#include <cstdint>
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28//-----------------------------------------------------------------------------
29// MurmurHash2, 64-bit versions, by Austin Appleby
30
31namespace
32{
33 uint64_t _MurmurHash64A(const void* key, uint64_t len, unsigned int seed)
34 {
35 const uint64_t m = 0xc6a4a7935bd1e995;
36 const int r = 47;
37
38 uint64_t h = seed ^ (len * m);
39
40 const uint64_t* data = (const uint64_t*)key;
41 const uint64_t* end = data + (len / 8);
42
43 while (data != end) {
44 uint64_t k = *data++;
45
46 k *= m;
47 k ^= k >> r;
48 k *= m;
49
50 h ^= k;
51 h *= m;
52 }
53
54 const unsigned char* data2 = (const unsigned char*)data;
55
56 switch (len & 7) {
57 case 7:
58 h ^= uint64_t(data2[6]) << 48;
59 [[fallthrough]];
60 case 6:
61 h ^= uint64_t(data2[5]) << 40;
62 [[fallthrough]];
63 case 5:
64 h ^= uint64_t(data2[4]) << 32;
65 [[fallthrough]];
66 case 4:
67 h ^= uint64_t(data2[3]) << 24;
68 [[fallthrough]];
69 case 3:
70 h ^= uint64_t(data2[2]) << 16;
71 [[fallthrough]];
72 case 2:
73 h ^= uint64_t(data2[1]) << 8;
74 [[fallthrough]];
75 case 1:
76 h ^= uint64_t(data2[0]);
77 h *= m;
78 };
79
80 h ^= h >> r;
81 h *= m;
82 h ^= h >> r;
83
84 return h;
85 }
86} // namespace
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
91Int64 IntegerHashFunctionT<StringView>::
92hashfunc(StringView str)
93{
94 Span<const Byte> bytes(str.bytes());
95 return _MurmurHash64A(bytes.data(), bytes.size(), 0x424);
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101} // namespace Arcane
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Integer len(const char *s)
Retourne la longueur de la chaîne s.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-