Class GraphColoring<N,E>
- java.lang.Object
-
- com.google.javascript.jscomp.graph.GraphColoring<N,E>
-
- Type Parameters:
N
- Value type that the graph node stores.E
- Value type that the graph edge stores.
- Direct Known Subclasses:
GraphColoring.GreedyGraphColoring
public abstract class GraphColoring<N,E> extends java.lang.Object
Annotates the graph with a color in a way that no connected node will have the same color. Nodes of the same color can then be partitioned together and be represented by a super node. This class will merely annotate the nodes with a color usingAnnotatable.setAnnotation(Annotation)
and provide a node to super node mapping withgetPartitionSuperNode(Object)
. The given graph itself will not be modified.This algorithm is NOT deterministic by default. Passes that requires deterministic output should provide a
Comparator
in the constructor as a tie-breaker. This tie-break will be used when deciding which node should be colored first when multiple nodes have the same degree.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GraphColoring.Color
The color of a nodestatic class
GraphColoring.GreedyGraphColoring<N,E>
Greedily assign nodes with high degree unique colors.
-
Field Summary
Fields Modifier and Type Field Description protected N[]
colorToNodeMap
protected AdjacencyGraph<N,E>
graph
-
Constructor Summary
Constructors Constructor Description GraphColoring(AdjacencyGraph<N,E> graph)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
color()
Annotates the graph withGraphColoring.Color
objects usingAnnotatable.setAnnotation(Annotation)
.AdjacencyGraph<N,E>
getGraph()
N
getPartitionSuperNode(N node)
Using the coloring as partitions, finds the node that represents that partition as the super node.
-
-
-
Field Detail
-
colorToNodeMap
protected N[] colorToNodeMap
-
graph
protected final AdjacencyGraph<N,E> graph
-
-
Constructor Detail
-
GraphColoring
public GraphColoring(AdjacencyGraph<N,E> graph)
-
-
Method Detail
-
color
public abstract int color()
Annotates the graph withGraphColoring.Color
objects usingAnnotatable.setAnnotation(Annotation)
.- Returns:
- The number of unique colors need.
-
getPartitionSuperNode
public N getPartitionSuperNode(N node)
Using the coloring as partitions, finds the node that represents that partition as the super node. The first to retrieve its partition will become the super node.
-
getGraph
public AdjacencyGraph<N,E> getGraph()
-
-