Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tales of MajEyal
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tome
Tales of MajEyal
Commits
1b87dcc6
Commit
1b87dcc6
authored
4 years ago
by
DarkGod
Browse files
Options
Downloads
Patches
Plain Diff
plop
parent
eb21586e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
game/engines/default/engine/utils.lua
+45
-0
45 additions, 0 deletions
game/engines/default/engine/utils.lua
with
45 additions
and
0 deletions
game/engines/default/engine/utils.lua
+
45
−
0
View file @
1b87dcc6
...
...
@@ -1277,6 +1277,51 @@ function string.split(str, char, keep_separator)
return
lpeg
.
match
(
p
,
str
)
end
-- Returns the Levenshtein distance between the two given strings
function
string
.
levenshtein
(
str1
,
str2
)
local
len1
=
string.len
(
str1
)
local
len2
=
string.len
(
str2
)
local
matrix
=
{}
local
cost
=
0
-- quick cut-offs to save time
if
(
len1
==
0
)
then
return
len2
elseif
(
len2
==
0
)
then
return
len1
elseif
(
str1
==
str2
)
then
return
0
end
-- initialise the base matrix values
for
i
=
0
,
len1
,
1
do
matrix
[
i
]
=
{}
matrix
[
i
][
0
]
=
i
end
for
j
=
0
,
len2
,
1
do
matrix
[
0
][
j
]
=
j
end
-- actual Levenshtein algorithm
for
i
=
1
,
len1
,
1
do
for
j
=
1
,
len2
,
1
do
if
(
str1
:
byte
(
i
)
==
str2
:
byte
(
j
))
then
cost
=
0
else
cost
=
1
end
matrix
[
i
][
j
]
=
math.min
(
matrix
[
i
-
1
][
j
]
+
1
,
matrix
[
i
][
j
-
1
]
+
1
,
matrix
[
i
-
1
][
j
-
1
]
+
cost
)
end
end
-- return the last value - this is the Levenshtein distance
return
matrix
[
len1
][
len2
]
end
function
string
.
levenshtein_p
(
str1
,
str2
)
return
string
.
levenshtein
(
str1
,
str2
)
/
#
str1
end
local
hex_to_dec
=
{
[
"0"
]
=
0
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment