AllEquivalentCyclicSet extends EquivalentSetFinder { @Override Set<Integer> find(long[] invariants, IAtomContainer container, int[][] graph) { int n = invariants.length; RingSearch ringSearch = new RingSearch(container, graph); Map<Long, Set<Integer>> equivalent = new TreeMap<Long, Set<Integer>>(); for (int i = 0; i < invariants.length; i++) { Long invariant = invariants[i]; Set<Integer> set = equivalent.get(invariant); if (set == null) { if (ringSearch.cyclic(i)) { set = new HashSet<Integer>(n / 2); set.add(i); equivalent.put(invariant, set); } } else { set.add(i); } } Set<Integer> set = new TreeSet<Integer>(); for (Map.Entry<Long, Set<Integer>> e : equivalent.entrySet()) { Set<Integer> vertices = e.getValue(); if (vertices.size() > 1) { set.addAll(vertices); } } return set; }    }
@Test public void testFind() throws Exception { IAtomContainer dummy = mock(IAtomContainer.class); int[][] g = new int[][]{{1, 5, 6}, {0, 2}, {1, 3}, {2, 4, 7}, {3, 5}, {0, 4}, {0}, {3}}; long[] values = new long[]{1, 0, 0, 1, 0, 0, 2, 2}; EquivalentSetFinder finder = new AllEquivalentCyclicSet(); Set<Integer> set = finder.find(values, dummy, g); assertThat(set.size(), is(6)); assertTrue(set.contains(0)); assertTrue(set.contains(1)); assertTrue(set.contains(2)); assertTrue(set.contains(3)); assertTrue(set.contains(4)); assertTrue(set.contains(5)); }
@Test public void testFind_Distinct() throws Exception { IAtomContainer dummy = mock(IAtomContainer.class); int[][] g = new int[][]{{1, 5, 6}, {0, 2}, {1, 3}, {2, 4, 7}, {3, 5}, {0, 4}, {0}, {3}}; long[] values = new long[]{10, 11, 12, 13, 14, 15, 16, 17}; EquivalentSetFinder finder = new AllEquivalentCyclicSet(); Set<Integer> set = finder.find(values, dummy, g); assertThat(set.size(), is(0)); }