private String encodePath(List<IAtom> apath, List<IBond> bpath, StringBuilder buffer) { buffer.setLength(0); IAtom prev = apath.get(0); buffer.append(getAtomSymbol(prev)); for (int i = 1; i < apath.size(); i++) { final IAtom next = apath.get(i); final IBond bond = bpath.get(i-1); buffer.append(getBondSymbol(bond)); buffer.append(getAtomSymbol(next)); } return buffer.toString(); }
/** * Compares atom symbols lexicographical * @param a atom a * @param b atom b * @return comparison <0 a is less than b, >0 a is more than b */ private int compare(IAtom a, IAtom b) { final int elemA = getElem(a); final int elemB = getElem(b); if (elemA == elemB) return 0; return getAtomSymbol(a).compareTo(getAtomSymbol(b)); }
private int encodeUniquePath(IAtomContainer container, Map<IAtom, List<IBond>> cache, List<IAtom> path, StringBuilder buffer) { if (path.size() == 1) return getAtomSymbol(path.get(0)).hashCode(); String forward = encodePath(container, cache, path, buffer); Collections.reverse(path); String reverse = encodePath(container, cache, path, buffer); Collections.reverse(path); final int x; if (reverse.compareTo(forward) < 0) x = forward.hashCode(); else x = reverse.hashCode(); return x; }
private int hashPath(List<IAtom> apath, List<IBond> bpath) { int hash = 0; hash = appendHash(hash, getAtomSymbol(apath.get(0))); for (int i = 1; i < apath.size(); i++) { final IAtom next = apath.get(i); final IBond bond = bpath.get(i-1); hash = appendHash(hash, getBondSymbol(bond)); hash = appendHash(hash, getAtomSymbol(next)); } return hash; }
private int hashRevPath(List<IAtom> apath, List<IBond> bpath) { int hash = 0; int last = apath.size() - 1; hash = appendHash(hash, getAtomSymbol(apath.get(last))); for (int i = last-1; i >= 0; i--) { final IAtom next = apath.get(i); final IBond bond = bpath.get(i); hash = appendHash(hash, getBondSymbol(bond)); hash = appendHash(hash, getAtomSymbol(next)); } return hash; }
private String encodePath(IAtomContainer mol, Map<IAtom, List<IBond>> cache, List<IAtom> path, StringBuilder buffer) { buffer.setLength(0); IAtom prev = path.get(0); buffer.append(getAtomSymbol(prev)); for (int i = 1; i < path.size(); i++) { final IAtom next = path.get(i); List<IBond> bonds = cache.get(prev); if (bonds == null) { bonds = mol.getConnectedBondsList(prev); cache.put(prev, bonds); } IBond bond = findBond(bonds, next, prev); if (bond == null) throw new IllegalStateException("FATAL - Atoms in patch were connected?"); buffer.append(getBondSymbol(bond)); buffer.append(getAtomSymbol(next)); prev = next; } return buffer.toString(); }
private int encodeUniquePath(List<IAtom> apath, List<IBond> bpath, StringBuilder buffer) { if (bpath.size() == 0) return getAtomSymbol(apath.get(0)).hashCode(); final int x; if (compare(apath, bpath) >= 0) { x = hashPath(apath, bpath); } else { x = hashRevPath(apath, bpath); } return x; }