Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
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{
11 /**
12 * LevenshteinDistance return the number of edit operation we need to transform RangeA to RangeB.
13 * Operation type are Add/Remove/substitution of range element. Base on Levenshtein algorithm.
14 *
15 * Range[A/B]Type: Support [] operator and the range element must be able to be compare with == operator
16 * Support GetNum() functionality
17 *
18 * @param RangeA The first range of element
19 * @param RangeB The second range of element
20 * @return The number of operation to transform RangeA to RangeB
21 */
22 template <typename RangeAType, typename RangeBType>
23 int32 LevenshteinDistance(const RangeAType& RangeA, const RangeBType& RangeB)
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 {
46 }
47 //find the operation count
48 for (int32 IndexA = 0; IndexA < LenA; ++IndexA)
49 {
51 for (int32 IndexB = 0; IndexB < LenB; ++IndexB)
52 {
54 if (DataA[IndexA] != DataB[IndexB])
55 {
57 }
60 }
62 }
63 return OperationCount[LenB];
64 }
65
66} //End namespace Algo
Definition Heapify.h:12
int32 LevenshteinDistance(const RangeAType &RangeA, const RangeBType &RangeB)