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
9
namespace
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
40
TArray
<
int32
>
OperationCount
;
41
//Initialize data
42
OperationCount
.
AddUninitialized
(
LenB
+ 1);
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
{
53
int32
NewCount
=
OperationCount
[
IndexB
];
54
if
(
DataA
[
IndexA
] !=
DataB
[
IndexB
])
55
{
56
NewCount
=
FMath
::
Min3
(
NewCount
,
LastCount
,
OperationCount
[
IndexB
+1]) + 1;
57
}
58
OperationCount
[
IndexB
] =
LastCount
;
59
LastCount
=
NewCount
;
60
}
61
OperationCount
[
LenB
] =
LastCount
;
62
}
63
return
OperationCount
[
LenB
];
64
}
65
66
}
//End namespace Algo
Algo
Definition
Heapify.h:12
Algo::LevenshteinDistance
int32 LevenshteinDistance(const RangeAType &RangeA, const RangeBType &RangeB)
Definition
LevenshteinDistance.h:23
Downloads
ArkServerAPI_NEW
ASA
AsaApi
AsaApi
Core
Public
API
UE
Algo
LevenshteinDistance.h
Generated by
1.10.0