Closed sidazhang closed 6 years ago
https://github.com/montagejs/collections/issues/27 is probably relevant
I would very much like to solve this problem and have stable operations. This is a matter of cracking open the Algorithms book and translating the right pseudocode. If anyone has a moment to do this, many people would be grateful.
My apologies, I didn't realise that there has already been an issue on this particular problem.
Is there any plan to add support for incomparable values?
There seems to be not well maintained module that does this. Any chance to merge it in?
The topological sort implementation might be insightful.
There are two answers to your question.
Topo sort sounds like the right algorithm for your particular situation though. Topo sort is usually implemented with a depth first traversal of the graph, which if well-written can tolerate cycles.
If I were to try to make a pull request to add support for incomparable values. Where would you recommend me to start with (collections is a pretty big library, so would be good if you could point me to a good starting point where I can focus my time on)
@sidazhang Everything you need should be in sorted-array.js
. The problem is probably in the binary search algorithms. Knowing how Object.compare
and Object.equals
will help and is in shim-object.js
, but you won’t be surprised. Don’t forget to use npm test
to verify work, but also, fixing tests may be the right solution.
I am trying to sort values that are sometimes incomparable with each other. The data that I am sorting resembles a tree where
Below is my example code:
This is the test output (with my annotation):