All Downloads are FREE. Search and download functionalities are using the official Maven repository.

signature.CanonicalLabellingVisitor Maven / Gradle / Ivy

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