From 53d124455837e9afa2c78e41b88f0f973fdf83e7 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 21 Mar 2025 23:16:34 +0800 Subject: get parital single node --- tests/modules/graph/test.lua | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'tests/modules/graph/test.lua') diff --git a/tests/modules/graph/test.lua b/tests/modules/graph/test.lua index da6218f14..c9584a69a 100644 --- a/tests/modules/graph/test.lua +++ b/tests/modules/graph/test.lua @@ -42,16 +42,14 @@ function test_paritail_topo_sort(t) local function partiail_topo_sort(dag) dag:partial_topo_sort_reset() + local node, has_cycle local order_vertices = {} - local batch, has_cycle = dag:partial_topo_sort_next() - while #batch > 0 do - for _, v in ipairs(batch) do - table.insert(order_vertices, v) - end - batch, has_cycle = dag:partial_topo_sort_next() - if has_cycle then + while true do + node, has_cycle = dag:partial_topo_sort_next() + if node == nil or has_cycle then break end + table.insert(order_vertices, node) end return order_vertices, has_cycle -- cgit v1.3.1