@@ -230,7 +230,7 @@ private String encodePath(List<IAtom> apath, List<IBond> bpath, StringBuilder bu
230
230
return buffer .toString ();
231
231
}
232
232
233
- private int appendHash (int hash , String str ) {
233
+ private static int appendHash (int hash , String str ) {
234
234
int len = str .length ();
235
235
for (int i = 0 ; i < len ; i ++)
236
236
hash = 31 * hash + str .charAt (0 );
@@ -262,7 +262,7 @@ private int hashRevPath(List<IAtom> apath, List<IBond> bpath) {
262
262
return hash ;
263
263
}
264
264
265
- private static final class State {
265
+ private final class State {
266
266
private int numPaths = 0 ;
267
267
private Random rand = new Random ();
268
268
private BitSet fp ;
@@ -326,18 +326,31 @@ void addHash(int x) {
326
326
* @return true - do encode/false - skip encoding
327
327
*/
328
328
public boolean isOrderedPath () {
329
- return apath .size () == 1 ||
330
- System .identityHashCode (apath .get (0 )) <
329
+ return System .identityHashCode (apath .get (0 )) <
331
330
System .identityHashCode (apath .get (apath .size ()-1 ));
332
331
}
332
+
333
+ public void storePath () {
334
+ if (bpath .size () == 0 ) {
335
+ addHash (getAtomSymbol (apath .get (0 )).hashCode ());
336
+ } else {
337
+ if (!isOrderedPath ())
338
+ return ;
339
+ final int x ;
340
+ if (compare (apath , bpath ) >= 0 ) {
341
+ addHash (hashPath (apath , bpath ));
342
+ } else {
343
+ addHash (hashRevPath (apath , bpath ));
344
+ }
345
+ }
346
+ }
333
347
}
334
348
335
349
private void traversePaths (State state , IAtom beg , IBond prev ) throws CDKException {
336
350
if (!hashPseudoAtoms && isPseudo (beg ))
337
351
return ;
338
352
state .push (beg , prev );
339
- if (state .isOrderedPath ())
340
- state .addHash (encodeUniquePath (state .apath , state .bpath , state .buffer ));
353
+ state .storePath ();
341
354
if (state .numPaths > pathLimit )
342
355
throw new CDKException ("Too many paths! Structure is likely a cage, reduce path length or increase path limit" );
343
356
if (state .apath .size () < state .maxDepth ) {
@@ -433,7 +446,7 @@ private int encodeUniquePath(IAtomContainer container,
433
446
* @param b atom b
434
447
* @return comparison <0 a is less than b, >0 a is more than b
435
448
*/
436
- private int compare (IAtom a , IAtom b ) {
449
+ private static int compare (IAtom a , IAtom b ) {
437
450
final int elemA = getElem (a );
438
451
final int elemB = getElem (b );
439
452
if (elemA == elemB )
@@ -478,26 +491,14 @@ private int compare(List<IAtom> apath, List<IBond> bpath) {
478
491
return 0 ;
479
492
}
480
493
481
- private int encodeUniquePath (List <IAtom > apath , List <IBond > bpath , StringBuilder buffer ) {
482
- if (bpath .size () == 0 )
483
- return getAtomSymbol (apath .get (0 )).hashCode ();
484
- final int x ;
485
- if (compare (apath , bpath ) >= 0 ) {
486
- x = hashPath (apath , bpath );
487
- } else {
488
- x = hashRevPath (apath , bpath );
489
- }
490
- return x ;
491
- }
492
-
493
494
private static int getElem (IAtom atom ) {
494
495
Integer elem = atom .getAtomicNumber ();
495
496
if (elem == null )
496
497
elem = 0 ;
497
498
return elem ;
498
499
}
499
500
500
- private String getAtomSymbol (IAtom atom ) {
501
+ private static String getAtomSymbol (IAtom atom ) {
501
502
// XXX: backwards compatibility
502
503
// This is completely random, I believe the intention is because
503
504
// paths were reversed with string manipulation to de-duplicate
0 commit comments