Skip to content

Commit f2673bf

Browse files
committed
Add docstring for topological_sort
1 parent eaf4446 commit f2673bf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/code.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,21 @@ end
696696

697697
@inline newsym(::Type{T}) where T = Sym{T}(gensym("cse"))
698698

699+
"""
700+
$(SIGNATURES)
701+
702+
Perform a topological sort on a symbolic expression represented as a Directed Acyclic
703+
Graph (DAG).
704+
705+
This function takes a symbolic expression `graph` (potentially containing shared common
706+
sub-expressions) and returns an array of `Assignment` objects. Each `Assignment`
707+
represents a node in the sorted order, assigning a fresh symbol to its corresponding
708+
expression. The order ensures that all dependencies of a node appear before the node itself
709+
in the array.
710+
711+
Hash consing is assumed, meaning that structurally identical expressions are represented by
712+
the same object in memory. This allows for efficient equality checks using `IdDict`.
713+
"""
699714
function topological_sort(graph)
700715
sorted_nodes = Assignment[]
701716
visited = IdDict()

0 commit comments

Comments
 (0)