UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
BuildPatchHash.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
5#include "Core/RingBuffer.h"
6
7/*=============================================================================
8 BuildPatchHash.h: Declares and implements template classes for use with the
9 Build and Patching hash functionality.
10=============================================================================*/
11
17#define ROTLEFT_64B( Value, Shifts ) Value = ( ( ( Value ) << ( ( Shifts ) % 64 ) ) | ( ( Value ) >> ( ( 64 - ( ( Shifts ) % 64 ) ) % 64 ) ) )
18
23{
24 // The lookup hash table
25 static uint64 HashTable[ 256 ];
26
30 static void Init();
31};
32
37{
38 // A typedef for our data ring buffer
40
41public:
45 FRollingHash(uint32 WindowSize);
46
51 void ConsumeByte( const uint8& NewByte );
52
58 void ConsumeBytes( const uint8* NewBytes, const uint32& NumBytes );
59
64 void RollForward( const uint8& NewByte );
65
69 void Clear();
70
75 const uint64 GetWindowHash() const;
76
81 const HashRingBuffer& GetWindowData() const;
82
87 const uint32 GetNumDataNeeded() const;
88
92 const uint32 GetWindowSize() const;
93
100 static uint64 GetHashForDataSet( const uint8* DataSet, uint32 WindowSize );
101
102private:
103 FRollingHash();
104 // The data size that we roll over.
105 const uint32 WindowSize = 0;
106 // The current hash value
107 uint64 HashState = 0;
108 // The number of bytes we have consumed so far, used in hash function and to check validity of calls
109 uint32 NumBytesConsumed = 0;
110 // Store the data to make access and rolling easier
111 HashRingBuffer WindowData = 0;
112};
113
117static bool CheckRollingHashAlgorithm()
118{
119 bool bCheckOk = true;
120 // Sanity Check the RollingHash code!!
121 FString IndivWords[6];
122 IndivWords[0] = "123456"; IndivWords[1] = "7890-="; IndivWords[2] = "qwerty"; IndivWords[3] = "uiop[]"; IndivWords[4] = "asdfgh"; IndivWords[5] = "jkl;'#";
123 FString DataToRollOver = FString::Printf( TEXT( "%s%s%s%s%s%s" ), *IndivWords[0], *IndivWords[1], *IndivWords[2], *IndivWords[3], *IndivWords[4], *IndivWords[5] );
125 for (uint32 idx = 0; idx < 6; ++idx )
126 {
127 uint8 Converted[6];
128 for (uint32 iChar = 0; iChar < 6; ++iChar )
131 }
132
133 FRollingHash RollingHash(6);
134 uint32 StrIdx = 0;
135 for (uint32 k=0; k<6; ++k)
136 RollingHash.ConsumeByte( DataToRollOver[ StrIdx++ ] );
137 bCheckOk = bCheckOk && IndivHashes[0] == RollingHash.GetWindowHash();
138 for (uint32 k=0; k<6; ++k)
139 RollingHash.RollForward( DataToRollOver[ StrIdx++ ] );
140 bCheckOk = bCheckOk && IndivHashes[1] == RollingHash.GetWindowHash();
141 for (uint32 k=0; k<6; ++k)
142 RollingHash.RollForward( DataToRollOver[ StrIdx++ ] );
143 bCheckOk = bCheckOk && IndivHashes[2] == RollingHash.GetWindowHash();
144 for (uint32 k=0; k<6; ++k)
145 RollingHash.RollForward( DataToRollOver[ StrIdx++ ] );
146 bCheckOk = bCheckOk && IndivHashes[3] == RollingHash.GetWindowHash();
147 for (uint32 k=0; k<6; ++k)
148 RollingHash.RollForward( DataToRollOver[ StrIdx++ ] );
149 bCheckOk = bCheckOk && IndivHashes[4] == RollingHash.GetWindowHash();
150 for (uint32 k=0; k<6; ++k)
151 RollingHash.RollForward( DataToRollOver[ StrIdx++ ] );
152 bCheckOk = bCheckOk && IndivHashes[5] == RollingHash.GetWindowHash();
153
154 return bCheckOk;
155}
#define TEXT(x)
Definition Platform.h:1272
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
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition BuildPatchHash.h:37
void ConsumeBytes(const uint8 *NewBytes, const uint32 &NumBytes)
Definition BuildPatchHash.cpp:64
const HashRingBuffer & GetWindowData() const
Definition BuildPatchHash.cpp:49
const uint64 GetWindowHash() const
Definition BuildPatchHash.cpp:42
void RollForward(const uint8 &NewByte)
Definition BuildPatchHash.cpp:72
void ConsumeByte(const uint8 &NewByte)
Definition BuildPatchHash.cpp:108
const uint32 GetWindowSize() const
Definition BuildPatchHash.cpp:54
static uint64 GetHashForDataSet(const uint8 *DataSet, uint32 WindowSize)
Definition BuildPatchHash.cpp:87
const uint32 GetNumDataNeeded() const
Definition BuildPatchHash.cpp:59
void Clear()
Definition BuildPatchHash.cpp:35
Definition BuildPatchHash.h:23
static uint64 HashTable[256]
Definition BuildPatchHash.h:12
static void Init()
Definition BuildPatchHash.cpp:14