summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-03-22 00:43:40 +0800
committerruki <[email protected]>2025-04-08 15:31:55 +0800
commit4a8219cda19cf320330ab7488f53158624c8c393 (patch)
tree7348edfb0b0ea27e3b22dfff89df00f8f8a6798d
parent63ed1854ea964fbbe7bc9dbdd8e2c34068dff7de (diff)
update comments
-rw-r--r--tests/modules/graph/test.lua10
-rw-r--r--xmake/core/base/graph.lua19
2 files changed, 25 insertions, 4 deletions
diff --git a/tests/modules/graph/test.lua b/tests/modules/graph/test.lua
index 1fb0bcb43..c242962db 100644
--- a/tests/modules/graph/test.lua
+++ b/tests/modules/graph/test.lua
@@ -46,12 +46,14 @@ function test_paritail_topo_sort(t)
local order_vertices = {}
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)
if node then
+ table.insert(order_vertices, node)
dag:partial_topo_sort_remove(node)
+ else
+ if has_cycle then
+ raise("has cycle!")
+ end
+ break
end
end
diff --git a/xmake/core/base/graph.lua b/xmake/core/base/graph.lua
index 090d41ade..4be7a2b77 100644
--- a/xmake/core/base/graph.lua
+++ b/xmake/core/base/graph.lua
@@ -142,6 +142,25 @@ end
-- @return array of nodes with zero in-degree, empty when complete
-- @return has_cycle indicates if a cycle was detected
--
+-- @code
+-- dag:partial_topo_sort_reset()
+--
+-- local node, has_cycle
+-- local order_vertices = {}
+-- while true do
+-- node, has_cycle = dag:partial_topo_sort_next()
+-- if node then
+-- table.insert(order_vertices, node)
+-- dag:partial_topo_sort_remove(node)
+-- else
+-- if has_cycle then
+-- -- find cycle
+-- end
+-- break
+-- end
+-- end
+-- @endcode
+--
-- e.g.
--
-- add_edge(a, b) -- a depend on b