UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LevenshteinDistance.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "CoreTypes.h"
7#include "Templates/Invoke.h"
8
9namespace Algo
10{
22 template <typename RangeAType, typename RangeBType>
24 {
25 const int32 LenA = GetNum(RangeA);
26 const int32 LenB = GetNum(RangeB);
27 //Early return for empty string
28 if (LenA == 0)
29 {
30 return LenB;
31 }
32 else if (LenB == 0)
33 {
34 return LenA;
35 }
36
37 auto DataA = GetData(RangeA);
38 auto DataB = GetData(RangeB);
39
41 //Initialize data
43 for (int32 IndexB = 0; IndexB <= LenB; ++IndexB)
44 {
45 OperationCount[IndexB] = IndexB;
46 }
47 //find the operation count
48 for (int32 IndexA = 0; IndexA < LenA; ++IndexA)
49 {
50 int32 LastCount = IndexA + 1;
51 for (int32 IndexB = 0; IndexB < LenB; ++IndexB)
52 {
54 if (DataA[IndexA] != DataB[IndexB])
55 {
57 }
58 OperationCount[IndexB] = LastCount;
60 }
62 }
63 return OperationCount[LenB];
64 }
65
66} //End namespace Algo
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
auto GetNum(const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Length())
Definition StringConv.h:808
auto GetData(const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Get())
Definition StringConv.h:802
Definition Array.h:670
UE_FORCEINLINE_HINT SizeType AddUninitialized()
Definition Array.h:1664
Definition ParallelSort.h:13
int32 LevenshteinDistance(const RangeAType &RangeA, const RangeBType &RangeB)
Definition LevenshteinDistance.h:23
static constexpr UE_FORCEINLINE_HINT T Min3(const T A, const T B, const T C)
Definition UnrealMathUtility.h:558