UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
xxhash.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7#include "CoreTypes.h"
8#include "HAL/UnrealMemory.h"
9#include "Memory/MemoryFwd.h"
10#include "Misc/ByteSwap.h"
12#include "String/BytesToHex.h"
13
15template <typename CharType> class TStringBuilderBase;
16
19{
26
28 [[nodiscard]] CORE_API static FXxHash64 HashBuffer(const void* Data, uint64 Size);
30
38 [[nodiscard]] CORE_API static FXxHash64 HashBufferChunked(const void* Data, uint64 Size, uint64 ChunkSize);
39
41 static inline FXxHash64 FromByteArray(const uint8 (&Bytes)[sizeof(uint64)])
42 {
46 }
47
49 inline void ToByteArray(uint8 (&Bytes)[sizeof(uint64)]) const
50 {
53 }
54
55 inline bool operator==(const FXxHash64& B) const
56 {
57 return Hash == B.Hash;
58 }
59
60 inline bool operator!=(const FXxHash64& B) const
61 {
62 return Hash != B.Hash;
63 }
64
65 inline bool operator<(const FXxHash64& B) const
66 {
67 return Hash < B.Hash;
68 }
69
70 inline bool IsZero() const
71 {
72 return Hash == 0;
73 }
74
75 friend inline uint32 GetTypeHash(const FXxHash64& InHash)
76 {
77 return uint32(InHash.Hash);
78 }
79
81 {
82 return Ar << InHash.Hash;
83 }
84
85 template <typename CharType>
87 {
88 uint8 Bytes[8];
89 InHash.ToByteArray(Bytes);
91 return Builder;
92 }
93};
94
97{
110
112 [[nodiscard]] CORE_API static FXxHash128 HashBuffer(const void* Data, uint64 Size);
114
122 [[nodiscard]] CORE_API static FXxHash128 HashBufferChunked(const void* Data, uint64 Size, uint64 ChunkSize);
123
125 static inline FXxHash128 FromByteArray(const uint8 (&Bytes)[sizeof(uint64[2])])
126 {
130 }
131
133 inline void ToByteArray(uint8 (&Bytes)[sizeof(uint64[2])]) const
134 {
137 }
138
139 inline bool operator==(const FXxHash128& B) const
140 {
141 return HashLow == B.HashLow && HashHigh == B.HashHigh;
142 }
143
144 inline bool operator!=(const FXxHash128& B) const
145 {
146 return HashLow != B.HashLow || HashHigh != B.HashHigh;
147 }
148
149 inline bool operator<(const FXxHash128& B) const
150 {
151 return HashHigh != B.HashHigh ? HashHigh < B.HashHigh : HashLow < B.HashLow;
152 }
153
154 inline bool IsZero() const
155 {
156 return HashHigh == 0 && HashLow == 0;
157 }
158
159 friend inline uint32 GetTypeHash(const FXxHash128& Hash)
160 {
161 return uint32(Hash.HashLow);
162 }
163
165 {
166 return Ar << Hash.HashLow << Hash.HashHigh;
167 }
168
169 template <typename CharType>
171 {
172 uint8 Bytes[16];
173 Hash.ToByteArray(Bytes);
175 return Builder;
176 }
177};
178
181{
182public:
183 inline FXxHash64Builder() { Reset(); }
184
187
188 CORE_API void Reset();
189
190 CORE_API void Update(FMemoryView View);
191 CORE_API void Update(const void* Data, uint64 Size);
193
195
196private:
197 alignas(64) char StateBytes[576];
198};
199
202{
203public:
204 inline FXxHash128Builder() { Reset(); }
205
208
209 CORE_API void Reset();
210
211 CORE_API void Update(FMemoryView View);
212 CORE_API void Update(const void* Data, uint64 Size);
214
216
217private:
218 alignas(64) char StateBytes[576];
219};
constexpr auto MakeArrayView(OtherRangeType &&Other)
Definition ArrayView.h:873
#define NETWORK_ORDER64(x)
Definition ByteSwap.h:147
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32 Size
Definition VulkanMemory.cpp:4034
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition CompositeBuffer.h:27
Definition xxhash.h:202
FXxHash128Builder(const FXxHash128Builder &)=delete
CORE_API void Reset()
Definition xxhash.cpp:134
CORE_API FXxHash128 Finalize() const
Definition xxhash.cpp:162
FXxHash128Builder()
Definition xxhash.h:204
FXxHash128Builder & operator=(const FXxHash128Builder &)=delete
Definition xxhash.h:181
CORE_API void Reset()
Definition xxhash.cpp:99
FXxHash64Builder()
Definition xxhash.h:183
FXxHash64Builder(const FXxHash64Builder &)=delete
CORE_API FXxHash64 Finalize() const
Definition xxhash.cpp:127
FXxHash64Builder & operator=(const FXxHash64Builder &)=delete
Definition StringBuilder.h:79
void BytesToHexLower(TConstArrayView< uint8 > Bytes, ANSICHAR *OutHex)
Definition BytesToHex.cpp:42
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160
Definition xxhash.h:97
static CORE_API FXxHash128 HashBufferChunked(FMemoryView View, uint64 ChunkSize)
Definition xxhash.cpp:82
void ToByteArray(uint8(&Bytes)[sizeof(uint64[2])]) const
Definition xxhash.h:133
bool operator!=(const FXxHash128 &B) const
Definition xxhash.h:144
static CORE_API FXxHash128 HashBuffer(FMemoryView View)
Definition xxhash.cpp:70
friend uint32 GetTypeHash(const FXxHash128 &Hash)
Definition xxhash.h:159
uint64 HashLow
Definition xxhash.h:103
friend FArchive & operator<<(FArchive &Ar, FXxHash128 &Hash)
Definition xxhash.h:164
bool operator==(const FXxHash128 &B) const
Definition xxhash.h:139
bool IsZero() const
Definition xxhash.h:154
friend TStringBuilderBase< CharType > & operator<<(TStringBuilderBase< CharType > &Builder, const FXxHash128 &Hash)
Definition xxhash.h:170
uint64 HashHigh
Definition xxhash.h:109
static FXxHash128 FromByteArray(const uint8(&Bytes)[sizeof(uint64[2])])
Definition xxhash.h:125
bool operator<(const FXxHash128 &B) const
Definition xxhash.h:149
Definition xxhash.h:19
friend FArchive & operator<<(FArchive &Ar, FXxHash64 &InHash)
Definition xxhash.h:80
bool IsZero() const
Definition xxhash.h:70
friend TStringBuilderBase< CharType > & operator<<(TStringBuilderBase< CharType > &Builder, const FXxHash64 &InHash)
Definition xxhash.h:86
bool operator==(const FXxHash64 &B) const
Definition xxhash.h:55
static CORE_API FXxHash64 HashBuffer(FMemoryView View)
Definition xxhash.cpp:43
static FXxHash64 FromByteArray(const uint8(&Bytes)[sizeof(uint64)])
Definition xxhash.h:41
bool operator<(const FXxHash64 &B) const
Definition xxhash.h:65
void ToByteArray(uint8(&Bytes)[sizeof(uint64)]) const
Definition xxhash.h:49
bool operator!=(const FXxHash64 &B) const
Definition xxhash.h:60
uint64 Hash
Definition xxhash.h:25
static CORE_API FXxHash64 HashBufferChunked(FMemoryView View, uint64 ChunkSize)
Definition xxhash.cpp:60
friend uint32 GetTypeHash(const FXxHash64 &InHash)
Definition xxhash.h:75