class Functions {

    public static Graph canonicalize(final Graph g,
                                     final long[] labels) {

        Integer[] is = new Integer[g.order()];

        for (int i = 0; i < is.length; i++)
            is[i] = i;

        // TODO: replace with radix sort (i.e. using a custom comparator)
        Arrays.sort(is, new Comparator<Integer>() {
            @Override public int compare(Integer i, Integer j) {
                if (labels[i] > labels[j])
                    return +1;
                else if (labels[i] < labels[j])
                    return -1;
                return 0;
            }
        });

        int[] p = new int[g.order()];
        for (int i = 0; i < is.length; i++)
            p[is[i]] = i;
        return g.permute(p);
    }

    private  Functions();

}