4 ms·
What is DAG ordering of structs?
by actionfromafar 9mo ago
What is DAG ordering of structs?
- michalsustr 9mo agoEach struct and its referenced fields can be thought of as a graph which can be sorted. Ideally, it is a DAG, but sometimes you can have recursive structures so it can be a cyclic graph. By DAG-ordering a I meant a topological sorting such that you do it by layers of the graph. https://en.wikipedia.org/wiki/Topological_sorting https://en.wikipedia.org/wiki/Topological_sorting https://en.wikipedia.org/wiki/Directed_acyclic_graph https://en.wikipedia.org/wiki/Directed_acyclic_graph
- tablatom 9mo agoDAG is directed acyclic graph. A bit like a tree where branches are allowed to merge but there are no cycles.
- actionfromafar 9mo agoYes, but I was wondering how organize your code in a DAG.
- yorwba 9mo agoIdentifiers correspond to nodes and a mention of an identifier in the definition of another corresponds to a directed edge. The resulting graph won't necessarily be acyclic, but you can still use it to inform the order in which you present definitions, e.g. newspaper style starts with the most high-level function and puts the low-level details at the end: https://pypi.org/project/flake8-newspaper-style/ https://pypi.org/project/flake8-newspaper-style/
- michalsustr 9mo agoYes exactly! Good idea to extend it to functions as well