forked from jasder/antlr
Use LinkedHashMap for deterministic behavior in Graph class
This commit is contained in:
parent
3565c36db6
commit
0942edbedd
|
@ -32,7 +32,7 @@ package org.antlr.v4.misc;
|
|||
import org.antlr.v4.runtime.misc.OrderedHashSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -59,7 +59,7 @@ public class Graph<T> {
|
|||
}
|
||||
|
||||
/** Map from node payload to node containing it */
|
||||
protected Map<T,Node<T>> nodes = new HashMap<T,Node<T>>();
|
||||
protected Map<T,Node<T>> nodes = new LinkedHashMap<T,Node<T>>();
|
||||
|
||||
public void addEdge(T a, T b) {
|
||||
//System.out.println("add edge "+a+" to "+b);
|
||||
|
|
|
@ -53,7 +53,7 @@ public class TestTopologicalSort extends BaseTest {
|
|||
g.addEdge("F", "H");
|
||||
g.addEdge("E", "F");
|
||||
|
||||
String expecting = "[H, F, E, D, G, A, B, C]";
|
||||
String expecting = "[H, F, G, E, D, A, B, C]";
|
||||
List<String> nodes = g.sort();
|
||||
String result = nodes.toString();
|
||||
assertEquals(expecting, result);
|
||||
|
@ -95,7 +95,7 @@ public class TestTopologicalSort extends BaseTest {
|
|||
g.addEdge("Def.g4", "Java.tokens"); // walkers feed off generated tokens
|
||||
g.addEdge("Ref.g4", "Java.tokens");
|
||||
|
||||
String expecting = "[MyJava.tokens, Java.g4, Java.tokens, Ref.g4, Def.g4]";
|
||||
String expecting = "[MyJava.tokens, Java.g4, Java.tokens, Def.g4, Ref.g4]";
|
||||
List<String> nodes = g.sort();
|
||||
String result = nodes.toString();
|
||||
assertEquals(expecting, result);
|
||||
|
@ -109,7 +109,7 @@ public class TestTopologicalSort extends BaseTest {
|
|||
g.addEdge("Def.g4", "JavaLexer.tokens");
|
||||
g.addEdge("Ref.g4", "JavaLexer.tokens");
|
||||
|
||||
String expecting = "[JavaLexer.g4, JavaLexer.tokens, JavaParser.g4, Ref.g4, Def.g4]";
|
||||
String expecting = "[JavaLexer.g4, JavaLexer.tokens, JavaParser.g4, Def.g4, Ref.g4]";
|
||||
List<String> nodes = g.sort();
|
||||
String result = nodes.toString();
|
||||
assertEquals(expecting, result);
|
||||
|
|
Loading…
Reference in New Issue