import java.util.BitSet; public class BitGraph { private final int order; private final BitSet[] adjacency; public int order(){ return order; } public BitSet adjacency(int vertex){ return adjacency[vertex]; } public boolean areAdjacent(int v, int w){ return adjacency[v].get(w); } BitGraph(String graph6String){ order = graph6N(graph6String); adjacency = new BitSet[order]; for (int i = 0; i < order; i++) { adjacency[i] = new BitSet(order); } readGraph6(graph6String); } BitGraph(BitGraph other){ order = other.order; adjacency = new BitSet[order]; for (int i = 0; i < order; i++) { adjacency[i] = (BitSet) other.adjacency[i].clone(); } } private int graph6N(String graph6String){ if(graph6String.charAt(0) != 126){ return graph6String.charAt(0) - 63; } int nr = graph6String.charAt(1) - 63; nr <<= 6; nr |= graph6String.charAt(2) - 63; nr <<= 6; nr |= graph6String.charAt(3) - 63; return nr; } void readGraph6(String graph6String){ int i = order < 63 ? 1 : 4; int x = 0; int y = 1; for(; i < graph6String.length(); ++i) { char c = (char) (graph6String.charAt(i) - 63); for (int j = 5; j >= 0; j--) { if ((c & (1 << j)) > 0) { adjacency[x].set(y); adjacency[y].set(x); } if (x + 1 < y) { x++; } else { y++; x = 0; } } } } }