Skip to content

Commit 1b3dae8

Browse files
johnmayegonw
authored andcommitted
Replace usage of Guava's BiMap
1 parent 9bbae7a commit 1b3dae8

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

base/core/src/main/java/org/openscience/cdk/graph/InitialCycles.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
*/
2424
package org.openscience.cdk.graph;
2525

26-
import com.google.common.collect.BiMap;
27-
import com.google.common.collect.HashBiMap;
2826
import com.google.common.collect.Multimap;
2927
import com.google.common.collect.TreeMultimap;
3028

3129
import java.util.BitSet;
3230
import java.util.Collection;
31+
import java.util.HashMap;
32+
import java.util.Map;
3333
import java.util.Objects;
3434

3535
import static java.util.Arrays.copyOf;
@@ -57,7 +57,8 @@ final class InitialCycles {
5757
private final Multimap<Integer, Cycle> cycles = TreeMultimap.create();
5858

5959
/** Index of edges in the graph */
60-
private final BiMap<Edge, Integer> edges;
60+
private final Map<Edge, Integer> edgeToIndex;
61+
private final Edge[] edges;
6162

6263
/**
6364
* Initial array size for 'ordering()'. This method sorts vertices by degree
@@ -123,16 +124,19 @@ private InitialCycles(final int[][] graph, final int limit, boolean biconnected)
123124
// - edge representation: binary vector indicates whether an edge
124125
// is present or
125126
// - path representation: sequential list vertices forming the cycle
126-
edges = HashBiMap.create(graph.length);
127+
edgeToIndex = new HashMap<>(2*graph.length);
127128
int n = graph.length;
128129
for (int v = 0; v < n; v++) {
129130
for (int w : graph[v]) {
130131
if (w > v) {
131132
Edge edge = new Edge(v, w);
132-
edges.put(edge, edges.size());
133+
edgeToIndex.put(edge, edgeToIndex.size());
133134
}
134135
}
135136
}
137+
edges = new Edge[edgeToIndex.size()];
138+
for (Map.Entry<Edge,Integer> e : edgeToIndex.entrySet())
139+
edges[e.getValue()] = e.getKey();
136140

137141
// compute the initial set of cycles
138142
compute();
@@ -192,7 +196,7 @@ int numberOfCycles() {
192196
* @return number of edges
193197
*/
194198
int numberOfEdges() {
195-
return edges.size();
199+
return edgeToIndex.size();
196200
}
197201

198202
/**
@@ -202,7 +206,7 @@ int numberOfEdges() {
202206
* @return the edge at the given index
203207
*/
204208
Edge edge(int i) {
205-
return edges.inverse().get(i);
209+
return edges[i];
206210
}
207211

208212
/**
@@ -214,7 +218,7 @@ Edge edge(int i) {
214218
* @return the index of the edge
215219
*/
216220
int indexOfEdge(final int u, final int v) {
217-
return edges.get(new Edge(u, v));
221+
return edgeToIndex.get(new Edge(u, v));
218222
}
219223

220224
/**
@@ -226,7 +230,7 @@ int indexOfEdge(final int u, final int v) {
226230
* @see #indexOfEdge(int, int)
227231
*/
228232
BitSet toEdgeVector(final int[] path) {
229-
final BitSet incidence = new BitSet(edges.size());
233+
final BitSet incidence = new BitSet(edgeToIndex.size());
230234
int len = path.length - 1;
231235
for (int i = 0; i < len; i++) {
232236
incidence.set(indexOfEdge(path[i], path[i + 1]));

tool/pcore/src/main/java/org/openscience/cdk/pharmacophore/PharmacophoreMatcher.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,9 @@
1818
*/
1919
package org.openscience.cdk.pharmacophore;
2020

21-
import java.util.ArrayList;
22-
import java.util.HashMap;
23-
import java.util.HashSet;
24-
import java.util.LinkedHashSet;
25-
import java.util.List;
26-
import java.util.Map;
27-
import java.util.Objects;
28-
import java.util.Set;
29-
30-
import javax.vecmath.Point3d;
31-
32-
import com.google.common.collect.HashBiMap;
3321
import org.openscience.cdk.AtomRef;
34-
import org.openscience.cdk.CDKConstants;
35-
import org.openscience.cdk.aromaticity.Aromaticity;
36-
import org.openscience.cdk.aromaticity.ElectronDonation;
3722
import org.openscience.cdk.exception.CDKException;
3823
import org.openscience.cdk.geometry.GeometryUtil;
39-
import org.openscience.cdk.graph.Cycles;
4024
import org.openscience.cdk.interfaces.IAtom;
4125
import org.openscience.cdk.interfaces.IAtomContainer;
4226
import org.openscience.cdk.interfaces.IBond;
@@ -48,6 +32,16 @@
4832
import org.openscience.cdk.tools.ILoggingTool;
4933
import org.openscience.cdk.tools.LoggingToolFactory;
5034

35+
import javax.vecmath.Point3d;
36+
import java.util.ArrayList;
37+
import java.util.HashMap;
38+
import java.util.HashSet;
39+
import java.util.LinkedHashSet;
40+
import java.util.List;
41+
import java.util.Map;
42+
import java.util.Objects;
43+
import java.util.Set;
44+
5145
/**
5246
* Identifies atoms whose 3D arrangement matches a specified pharmacophore query.
5347
*
@@ -280,7 +274,10 @@ public List<HashMap<IBond, IBond>> getTargetQueryBondMappings() {
280274
// query -> target so need to inverse the mapping
281275
// XXX: re-subsearching the query
282276
for (Map<IBond,IBond> map : mappings.toBondMap()) {
283-
bondMap.add(new HashMap<>(HashBiMap.create(map).inverse()));
277+
HashMap<IBond, IBond> inv = new HashMap<>();
278+
for (Map.Entry<IBond, IBond> e : map.entrySet())
279+
inv.put(e.getValue(), e.getKey());
280+
bondMap.add(inv);
284281
}
285282

286283
return bondMap;

0 commit comments

Comments
 (0)