chore: use stylua for formatting (#1040)
* chore: stylua job and config * reformat with stylua
This commit is contained in:
@@ -7,12 +7,12 @@
|
||||
-- > matches on consecutive letters and starts of words. This allows matching
|
||||
-- > using acronyms or different parts of the path." - J Hawthorn
|
||||
|
||||
local has_path, Path = pcall(require, 'plenary.path')
|
||||
local has_path, Path = pcall(require, "plenary.path")
|
||||
if not has_path then
|
||||
Path = {
|
||||
path = {
|
||||
separator = '/'
|
||||
}
|
||||
separator = "/",
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
@@ -48,11 +48,11 @@ function fzy.has_match(needle, haystack)
|
||||
end
|
||||
|
||||
local function is_lower(c)
|
||||
return c:match("%l")
|
||||
return c:match "%l"
|
||||
end
|
||||
|
||||
local function is_upper(c)
|
||||
return c:match("%u")
|
||||
return c:match "%u"
|
||||
end
|
||||
|
||||
local function precompute_bonus(haystack)
|
||||
@@ -93,7 +93,7 @@ local function compute(needle, haystack, D, M)
|
||||
haystack_chars[i] = lower_haystack:sub(i, i)
|
||||
end
|
||||
|
||||
for i=1,n do
|
||||
for i = 1, n do
|
||||
D[i] = {}
|
||||
M[i] = {}
|
||||
|
||||
@@ -147,7 +147,7 @@ function fzy.positions(needle, haystack)
|
||||
return {}
|
||||
elseif n == m then
|
||||
local consecutive = {}
|
||||
for i=1,n do
|
||||
for i = 1, n do
|
||||
consecutive[i] = i
|
||||
end
|
||||
return consecutive
|
||||
@@ -160,11 +160,10 @@ function fzy.positions(needle, haystack)
|
||||
local positions = {}
|
||||
local match_required = false
|
||||
local j = m
|
||||
for i=n,1,-1 do
|
||||
for i = n, 1, -1 do
|
||||
while j >= 1 do
|
||||
if D[i][j] ~= SCORE_MIN and (match_required or D[i][j] == M[i][j]) then
|
||||
match_required = (i ~= 1) and (j ~= 1) and (
|
||||
M[i][j] == D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE)
|
||||
match_required = (i ~= 1) and (j ~= 1) and (M[i][j] == D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE)
|
||||
positions[i] = j
|
||||
j = j - 1
|
||||
break
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
local LinkedList = {}
|
||||
LinkedList.__index = LinkedList
|
||||
|
||||
@@ -27,7 +26,7 @@ end
|
||||
|
||||
local create_node = function(item)
|
||||
return {
|
||||
item = item
|
||||
item = item,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -122,7 +121,6 @@ function LinkedList:place_after(index, node, item)
|
||||
new_node.next.prev = new_node
|
||||
end
|
||||
|
||||
|
||||
if self.track_at then
|
||||
if index == self.track_at then
|
||||
self._tracked_node = new_node
|
||||
@@ -166,7 +164,6 @@ function LinkedList:place_before(index, node, item)
|
||||
new_node.next.prev = new_node
|
||||
end
|
||||
|
||||
|
||||
if self.track_at then
|
||||
if index == self.track_at - 1 then
|
||||
self._tracked_node = node
|
||||
@@ -176,7 +173,7 @@ function LinkedList:place_before(index, node, item)
|
||||
elseif final_size > self.track_at then
|
||||
self._tracked_node = self._tracked_node.prev
|
||||
else
|
||||
return
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@@ -184,7 +181,6 @@ function LinkedList:place_before(index, node, item)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Do you even do this in linked lists...?
|
||||
-- function LinkedList:remove(item)
|
||||
-- end
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
|
||||
local function min(a, b, c)
|
||||
local min_val = a
|
||||
|
||||
if b < min_val then min_val = b end
|
||||
if c < min_val then min_val = c end
|
||||
if b < min_val then
|
||||
min_val = b
|
||||
end
|
||||
if c < min_val then
|
||||
min_val = c
|
||||
end
|
||||
|
||||
return min_val
|
||||
|
||||
end
|
||||
|
||||
----------------------------------
|
||||
@@ -16,34 +18,35 @@ end
|
||||
-- @treturn number the levenshtein distance
|
||||
-- @within Metrics
|
||||
return function(s1, s2)
|
||||
if s1 == s2 then return 0 end
|
||||
if s1:len() == 0 then return s2:len() end
|
||||
if s2:len() == 0 then return s1:len() end
|
||||
if s1:len() < s2:len() then s1, s2 = s2, s1 end
|
||||
|
||||
local t = {}
|
||||
for i=1, #s1+1 do
|
||||
t[i] = {i-1}
|
||||
if s1 == s2 then
|
||||
return 0
|
||||
end
|
||||
if s1:len() == 0 then
|
||||
return s2:len()
|
||||
end
|
||||
if s2:len() == 0 then
|
||||
return s1:len()
|
||||
end
|
||||
if s1:len() < s2:len() then
|
||||
s1, s2 = s2, s1
|
||||
end
|
||||
|
||||
for i=1, #s2+1 do
|
||||
t[1][i] = i-1
|
||||
local t = {}
|
||||
for i = 1, #s1 + 1 do
|
||||
t[i] = { i - 1 }
|
||||
end
|
||||
|
||||
for i = 1, #s2 + 1 do
|
||||
t[1][i] = i - 1
|
||||
end
|
||||
|
||||
local cost
|
||||
for i=2, #s1+1 do
|
||||
|
||||
for j=2, #s2+1 do
|
||||
cost = (s1:sub(i-1,i-1) == s2:sub(j-1,j-1) and 0) or 1
|
||||
t[i][j] = min(
|
||||
t[i-1][j] + 1,
|
||||
t[i][j-1] + 1,
|
||||
t[i-1][j-1] + cost)
|
||||
for i = 2, #s1 + 1 do
|
||||
for j = 2, #s2 + 1 do
|
||||
cost = (s1:sub(i - 1, i - 1) == s2:sub(j - 1, j - 1) and 0) or 1
|
||||
t[i][j] = min(t[i - 1][j] + 1, t[i][j - 1] + 1, t[i - 1][j - 1] + cost)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return t[#s1+1][#s2+1]
|
||||
|
||||
return t[#s1 + 1][#s2 + 1]
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user