TDoubleArrayList equality differs from List in important corner cases

Issue #10 new
Rob Eden created an issue

One would hope that TDoubleArrayList would be a drop-in replacement for List, however the corner cases for equals() differ. For instance,

new TDoubleArrayList(new double[]{Double.NaN}).equals(new TDoubleArrayList(new double[]{Double.NaN})) returns false, whereas the List returns true.

The reason is that List calls pair-wise equals on each element, & Double defines equals() as being slightly different than == (it does == on the toLongBits of the raw value). It would be nice if TDoubleArrayList followed the same thing.

Original SF issue

Comments from original bug:

Vitali

here's a patch that covers T#ArrayList & T#LinkedList for double & float. Presumably sets & hashes need to be updated too, but it's unclear how/where that would occur. It looks like maybe T#HashSet already uses Double/Float#equals via TObjectHash? (See lists.patch)

Rob Eden

Seems like a reasonable fix.

Vitali

do maps & sets using double/float need to be updated to? I couldn't quite tell from the template.

Rob Eden

Yeah, they would. We haven't handled NaN for keys due to this same issue. So, the same simple fix in equals() could be done for values. For keys the change would need to be done in a number of places (insertKey, for example).

Vitali

here's the patch for the entire set of collections (hopefully I got all the spots for the maps & sets). this supersedes the previous patch that only had lists (See full.patch)

Comments (3)

  1. Log in to comment