-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable_utils.lua
More file actions
79 lines (66 loc) · 1.2 KB
/
Copy pathtable_utils.lua
File metadata and controls
79 lines (66 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
inspect = require("inspect")
local M = {}
M.contains = function(tbl, file_name)
for _, v in ipairs(tbl) do
if v == file_name then
return true
end
end
return false
end
function _keys(t)
local keys = {}
local j = 1
for k, _ in pairs(t) do
keys[j] = k
j = j + 1
end
j = 1
return function()
local k = keys[j]
j = j + 1
return k
end
end
function _max(t)
local max = nil
local key_max = nil
for key in _keys(t) do
local item = t[key]
if max == nil or item["total_out"] > max["total_out"] then
max = item
key_max = key
end
end
return key_max, max
end
function _min(t)
local min = nil
local key_min = nil
for key in _keys(t) do
local item = t[key]
if min == nil or item["total_out"] <= min["total_out"] then
min = item
key_min = key
end
end
return key_min, min
end
function _remove(tbl, key)
local t = {}
for k, value in pairs(tbl) do
if k ~= key then
t[k] = value
end
end
return t
end
M.iter_deps_tbl = function(app_tbl)
local app_tbl_ = app_tbl
return function()
local k, k_value = _min(app_tbl_)
app_tbl_ = _remove(app_tbl_, k)
return k, k_value
end
end
return M