summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-03-21 22:38:32 +0800
committerruki <[email protected]>2025-04-08 15:31:54 +0800
commit0662b04580e06e6d18b254e4005869569d8a8c50 (patch)
tree6f390204fb20d3c780fd360542cf93018c9862be
parentce5fb205bbebb83fe6842b00858210f9d4256148 (diff)
use list as queue
-rw-r--r--xmake/core/base/graph.lua13
1 files changed, 7 insertions, 6 deletions
diff --git a/xmake/core/base/graph.lua b/xmake/core/base/graph.lua
index 06324c0a0..681d390c3 100644
--- a/xmake/core/base/graph.lua
+++ b/xmake/core/base/graph.lua
@@ -19,7 +19,8 @@
--
-- load modules
-local table = require("base/table")
+local table = require("base/table")
+local list = require("base/list")
local object = require("base/object")
-- define module
@@ -180,10 +181,10 @@ function graph:_topological_sort_kahn()
end
-- queue of vertices with no incoming edges (no dependencies)
- local queue = {}
+ local queue = list.new()
for _, v in ipairs(self:vertices()) do
if in_degree[v] == 0 then
- table.insert(queue, v)
+ queue:insert(v)
end
end
@@ -191,9 +192,9 @@ function graph:_topological_sort_kahn()
local order_vertices = {}
-- process queue
- while #queue > 0 do
+ while not queue:empty() do
-- remove a vertex with no incoming edges
- local v = table.remove(queue, 1)
+ local v = queue:remove_first()
table.insert(order_vertices, v)
-- for each outgoing edge, remove it and update in-degrees
@@ -205,7 +206,7 @@ function graph:_topological_sort_kahn()
in_degree[w] = in_degree[w] - 1
-- if in-degree becomes zero, add to queue
if in_degree[w] == 0 then
- table.insert(queue, w)
+ queue:insert(w)
end
end
end