Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
HashAlgorithm.cc
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/* HashAlgorithm.cc (C) 2000-2025 */
9/* */
10/* Interface of a hashing algorithm. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/IHashAlgorithm.h"
15#include "arcane/utils/FatalErrorException.h"
16#include "arcane/utils/NotImplementedException.h"
17#include "arcane/utils/Array.h"
18#include "arcane/utils/Ref.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29void HashAlgorithmValue::
30setSize(Int32 size)
31{
32 ARCANE_FATAL_IF((size < 0), "Invalid negative size '{0}'", size);
33 ARCANE_FATAL_IF((size > MAX_SIZE), "Invalid size '{0}' max value is '{1}'", size, MAX_SIZE);
34 m_size = size;
35}
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
41name() const
42{
43 ARCANE_THROW(NotImplementedException, "name() method");
44}
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
50hashSize() const
51{
52 ARCANE_THROW(NotImplementedException, "hashSize() method");
53}
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
60{
61 computeHash(input.smallView(), output);
62}
63
64/*---------------------------------------------------------------------------*/
65/*---------------------------------------------------------------------------*/
66
69{
70 const Byte* x = reinterpret_cast<const Byte*>(input.data());
71 computeHash64(Span<const Byte>(x, input.size()), output);
72}
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
79{
80 UniqueArray<Byte> legacy_bytes;
81 computeHash64(input, legacy_bytes);
82 Int32 n = legacy_bytes.size();
83 value.setSize(n);
84 SmallSpan<std::byte> value_as_bytes(value.bytes());
85 for (Int32 i = 0; i < n; ++i)
86 value_as_bytes[i] = static_cast<std::byte>(legacy_bytes[i]);
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101} // namespace Arcane
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL_IF(const,...)
Macro throwing a FatalErrorException if cond is true.
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
Integer size() const
Number of elements in the vector.
Hash algorithm return value.
virtual String name() const
Name of the algorithm.
virtual void computeHash(Span< const std::byte > input, HashAlgorithmValue &value)
Calculates the hash value for the array input.
virtual void computeHash64(Span< const Byte > input, ByteArray &output)
Calculates the hash value for the array input.
virtual Int32 hashSize() const
Size (in bytes) of the hash key.
virtual Ref< IHashAlgorithmContext > createContext()
Creates a context to calculate the hash value incrementally.
Reference to an instance.
View of an array of elements of type T.
Definition Span.h:805
constexpr view_type smallView()
Constant view of this view.
Definition Span.h:392
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
Definition Span.h:539
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
Definition Span.h:327
View of an array of elements of type T.
Definition Span.h:635
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Byte > ByteArray
Dynamic one-dimensional array of characters.
Definition UtilsTypes.h:121
unsigned char Byte
Type of a byte.
Definition BaseTypes.h:43
std::int32_t Int32
Signed integer type of 32 bits.