-
-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Topological sort according to TAOCP by Donald Knuth, Volume 1 page 265. #7457
Topological sort according to TAOCP by Donald Knuth, Volume 1 page 265. #7457
Conversation
Hi Massimo. |
Another observation: |
… found in the original text. Add a test case that shows how to iteratively remove cycle to refine the input relations to be acyclic.
Hi @dionisiydk , I added it to the root Yes, you're right, the implementation is long and the critique browser complains as you said. I think that many parts can be encapsulated/promoted to be a message of its own; before going further, I would like to ask you an advice about that. |
…em acyclic, in order to collect the set of edges removed in the process.
Maybe I misunderstood PR but it looks like algorithm needs a collection of associations as an input. And it is what I consider as a special kind of collection while existing collection methods are really general and can be applied to any collection of any objects. Also you did not explain why it should be in the core collection library? |
After a talk with @pavel-krivanek and Richard Uttner, I fully understand your comments and realised that BTW, are the auxiliary messages Thanks. |
I doubt about #ignoreBlock: because you can do the same with #in: . Also I find the name is very unclear. |
Ok, IMHO
provided that
What's a better name for it? |
I see the difference. Thanks for details. |
Maybe this can be a topologicalSortOnCycleDo: aBlock
^(TopologicalSortAlgorithm over: self onCycleDo: aBlock) value And refactor a bit the internals of the algorithm in this class instead of adding several private methods to the Collection hiearchy? |
I like the idea of Gabriel, I would name it TopologicalSorter In awesome there is
in SortedCollection So I will close the issue but I encourage you to turn it in TopologicalSorter and we can host it in http://www.github.com/Pharo-containers/
|
Hi, many thanks to all of you for the advices. I've moved the code in https://github.com/massimo-nocentini/Containers-LinkedStoragePool and an short documentation can be found at https://massimo-nocentini.github.io/Booklet-DSst/linked-allocation/linked-allocation.html#topological-sorting Whenever I've time I'll refactor it as suggested. All the best,
|
Thanks this is great and I will your doc. It looks super nice. S |
Implementation that combines sequential and linked allocations to obtain
O(m + n)
complexity, wherem
is the number of input relations andn
is the number of unique objects that are being related. Neither priority heaps nor recursive message sends (as in DFS-based solutions) are used, just anArray
of sizen
,m
ValueLink
objects and aDictionary
of size proportional to the number of sources (nodes with no incoming edges) are allocated.The proposed message return an
Array
object with the objects in topological order if the given associations form a DAG, otherwise it detect a cycle and invoke a given block with a collection of associations forming that cycle.It depends on two auxiliary messages
#ignoreBlock:
and#anyAssociation
that are commented and tested as well.The example from Knuth:
Assumption
the naturals used in the input relations have to cover the interval
[1, n]
, no holes allowed. For the sake of clarity,