signature.CanonicalLabellingVisitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signatures Show documentation
Show all versions of signatures Show documentation
A graph signature library
The newest version!
package signature;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import signature.DAG.Node;
public class CanonicalLabellingVisitor implements DAGVisitor {
private int[] labelling;
private int currentLabel;
private Comparator comparator;
public CanonicalLabellingVisitor(
int vertexCount, Comparator comparator) {
labelling = new int[vertexCount];
Arrays.fill(labelling, -1);
currentLabel = 0;
}
public void visit(Node node) {
// only label if this vertex has not yet been labeled
if (this.labelling[node.vertexIndex] == -1) {
this.labelling[node.vertexIndex] = this.currentLabel;
this.currentLabel++;
}
if (comparator != null) {
Collections.sort(node.children, comparator);
}
for (Node child : node.children) {
child.accept(this);
}
}
public int[] getLabelling() {
return this.labelling;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy