I have graph traversal algorithm that needs to keep track of the
N "best" node visit. Every time a visit a new node I get its
goodness along with a ref to it. I then want to compare it to
every currently best node in this list and replace it with the
worst one if its better than the worst. How do I most easily do
this with regards to minimizing GC-usage.
For N = 3 I mean something like this:
(A,1) => [(A,1)]
(B,2) => [(A,1), (B,2)]
(C,3) => [(A,1), (B,2), (C,3)]
(X,0) => [(X,0), (A,1), (B,2)]
(Y,1) => [(X,0), (Y,1), (A,1)]
...
(A,1) means we just visited node with goodness (distance) 1