Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
HashBuilder.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Crc.h"
7#include "Concepts/GetTypeHashable.h"
8#include "Containers/UnrealString.h"
9
10/**
11 * Class for computing a hash of multiple types, going through GetTypeHash when the type implements it, and
12 * fallbacks to CRC32 when the type doesn't.
13 *
14 * Note: this hash builder should be used for transient hashes, as some types implements run-dependent hash
15 * computations, such as GetTypeHash(FName).
16 */
18{
19public:
20 explicit FHashBuilder(uint32 InHash = 0)
21 : Hash(~InHash)
22 {}
23
24 void AppendRaw(const void* Data, int64 Num)
25 {
26 Hash = FCrc::MemCrc32(Data, static_cast<int32>(Num), Hash); // TODO: Update MemCrc32 to take an int64 Length?
27 }
28
29 template <typename T>
30 typename TEnableIf<TIsPODType<T>::Value, FHashBuilder&>::Type AppendRaw(const T& InData)
31 {
32 AppendRaw(&InData, sizeof(T), Hash);
33 return *this;
34 }
35
36 template <typename T>
38 {
39 return AppendRaw(InData);
40 }
41
42 template <typename T>
44 {
46 return *this;
47 }
48
49 template <typename T>
50 FHashBuilder& Append(const TArray<T>& InArray)
51 {
52 for (auto& Value: InArray)
53 {
55 }
56 return *this;
57 }
58
59 template <typename T>
60 FHashBuilder& Append(const TSet<T>& InArray)
61 {
62 for (auto& Value: InArray)
63 {
65 }
66 return *this;
67 }
68
69 template <typename T>
70 FHashBuilder& operator<<(const T& InData)
71 {
72 return Append(InData);
73 }
74
75 uint32 GetHash() const
76 {
77 return ~Hash;
78 }
79
80private:
81 uint32 Hash;
82};
uint32 GetHash() const
Definition HashBuilder.h:75
FHashBuilder & Append(const TArray< T > &InArray)
Definition HashBuilder.h:50
TEnableIf< TIsPODType< T >::Value, FHashBuilder & >::Type AppendRaw(const T &InData)
Definition HashBuilder.h:30
void AppendRaw(const void *Data, int64 Num)
Definition HashBuilder.h:24
TEnableIf<!TModels< CGetTypeHashable, T >::Value, FHashBuilder & >::Type Append(const T &InData)
Definition HashBuilder.h:37
FHashBuilder(uint32 InHash=0)
Definition HashBuilder.h:20