hashtable - Check Uniqueness of a Java Object, within some epsilon -
i'm trying prune 3d mesh checking vertices uniqueness. because each vertex has sort of error associated it, 2 "similar" verts same. e.g.
<1.9999999, 1, 3> same vertex <2.000001, 1, 3>
i have millions of vertices need check, going put of objects hash table , query see if unique. overriding isequal easy: take abs of difference between 2 coordinates , divide magnitude of one. example:
if (math.abs((x2-x2)/x1) < 0.0000001) return true;
but how come hashcode return same 2 equal, not equal vertices?
i thought quantizing space, i.e. taking floor decimal place entire set. but, in example above round <1.999, 1, 3> , <2.000, 1, 3> example.
but how come hashcode return same 2 equal, not equal vertices?
in short, that's not possible.
if hashcode(x) == hashcode(x + eps)
x
, it's true hashcode(x + eps) == hashcode(x + 2*eps)
, on.
the way satisfy int hashcode() { return constant; }
, of limited use...
as corollary, equals()
method flawed too. contract equals()
requires transitive, i.e. if a.equals(b)
, b.equals(c)
, a.equals(c)
, any a
, b
, c
. not case definition.
this going lead sorts of subtle hell, many of standard java collections, etc. rely on this.
Comments
Post a Comment