Blender V5.3
BLI_unique_hash.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include "BLI_vector.hh"
12
13namespace blender {
14
19struct UniqueHash {
22
23 uint64_t hash() const
24 {
25 return v1;
26 }
27 friend bool operator==(const UniqueHash &a, const UniqueHash &b) = default;
28};
29
40 template<typename T> void add(const T &value)
41 {
42 static_assert(std::is_trivially_copyable_v<T>);
43 data.extend(reinterpret_cast<const std::byte *>(&value), sizeof(T));
44 }
45};
46
47template<typename T> void hash_unique_default(const T &value, UniqueHashBytes &hash);
48
49template<typename T>
50inline void hash_unique_default(const T &value, UniqueHashBytes &hash)
51 requires(std::is_integral_v<T> || std::is_enum_v<T> || std::is_pointer_v<T>)
52{
53 hash.add(value);
54}
55
56template<typename T>
57inline void hash_unique_default(const T &value, UniqueHashBytes &hash)
58 requires(std::is_floating_point_v<T>)
59{
60 if (value == 0) {
61 hash.add(T(0));
62 }
63 else {
64 hash.add(value);
65 }
66}
67
68template<typename T>
69inline void hash_unique_default(const T &value, UniqueHashBytes &hash)
70 requires requires { value.hash_unique(hash); }
71{
72 value.hash_unique(hash);
73}
74
75} // namespace blender
#define T
BMesh Iterators.
unsigned __int64 uint64_t
Definition BKE_text.h:91
void hash_unique_default(const T &value, UniqueHashBytes &hash)
#define hash
Definition noise_c.cc:156
Vector< std::byte, 256 > data
void add(const T &value)
uint64_t hash() const
friend bool operator==(const UniqueHash &a, const UniqueHash &b)=default