Skip to content

Commit

Permalink
Corrected canonical label sorting in the SmilesGenerator. This canoni…
Browse files Browse the repository at this point in the history
…cal labels are long and thus when the difference between two values is taken the result may be larger then the largest possible integer. This in rare cases cause the value to overflow and thus make the comparator non-transitive.

Change-Id: Ibaba56bb5e559bbf250459689e6b0cc5b286fa03
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Dec 12, 2012
1 parent d7a55d3 commit 704280a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/org/openscience/cdk/smiles/SmilesGenerator.java
Expand Up @@ -655,8 +655,15 @@ private List getCanNeigh(final IAtom a, final IAtomContainer container)
{
public int compare(IAtom o1, IAtom o2)
{
return (int) ((Long) ( o1).getProperty("CanonicalLable") - (Long) (o2).getProperty("CanonicalLable"));
return label(o1).compareTo(label(o2));
}

private Long label(IAtom atom){
// cast can be removed in master
Long label = (Long) atom.getProperty(InvPair.CANONICAL_LABEL);
return label != null ? label : Long.MIN_VALUE;
}

});
}
return v;
Expand Down

0 comments on commit 704280a

Please sign in to comment.