Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #867 from 9rnsr/fix13052
Browse files Browse the repository at this point in the history
Issue 13052 - TypeInfo.getHash should return same hash for different floating point zeros
  • Loading branch information
MartinNowak committed Nov 23, 2014
2 parents 4e8bb2c + 3721b43 commit 652014b
Show file tree
Hide file tree
Showing 18 changed files with 515 additions and 525 deletions.
23 changes: 12 additions & 11 deletions mak/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ MANIFEST=\
src\rt\tlsgc.d \
src\rt\trace.d \
\
src\rt\util\array.d \
src\rt\util\hash.d \
src\rt\util\random.d \
src\rt\util\string.d \
src\rt\util\typeinfo.d \
src\rt\util\utf.d \
src\rt\util\container\array.d \
src\rt\util\container\common.d \
src\rt\util\container\hashtab.d \
src\rt\util\container\treap.d \
\
src\rt\typeinfo\ti_AC.d \
src\rt\typeinfo\ti_Acdouble.d \
src\rt\typeinfo\ti_Acfloat.d \
Expand All @@ -233,8 +244,8 @@ MANIFEST=\
src\rt\typeinfo\ti_Along.d \
src\rt\typeinfo\ti_Areal.d \
src\rt\typeinfo\ti_Ashort.d \
src\rt\typeinfo\ti_C.d \
src\rt\typeinfo\ti_byte.d \
src\rt\typeinfo\ti_C.d \
src\rt\typeinfo\ti_cdouble.d \
src\rt\typeinfo\ti_cfloat.d \
src\rt\typeinfo\ti_char.d \
Expand All @@ -258,14 +269,4 @@ MANIFEST=\
src\rt\typeinfo\ti_void.d \
src\rt\typeinfo\ti_wchar.d \
\
src\rt\util\array.d \
src\rt\util\hash.d \
src\rt\util\random.d \
src\rt\util\string.d \
src\rt\util\utf.d \
src\rt\util\container\array.d \
src\rt\util\container\common.d \
src\rt\util\container\hashtab.d \
src\rt\util\container\treap.d \
\
src\etc\linux\memoryerror.d
5 changes: 3 additions & 2 deletions mak/SRCS
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ SRCS=\
src\core\stdc\math.d \
src\core\stdc\signal.d \
src\core\stdc\stdarg.d \
src\core\stdc\stddef.d \
src\core\stdc\stdint.d \
src\core\stdc\stdio.d \
src\core\stdc\stdlib.d \
src\core\stdc\stdint.d \
src\core\stdc\stddef.d \
src\core\stdc\string.d \
src\core\stdc\time.d \
src\core\stdc\wchar_.d \
Expand Down Expand Up @@ -128,6 +128,7 @@ SRCS=\
src\rt\util\hash.d \
src\rt\util\random.d \
src\rt\util\string.d \
src\rt\util\typeinfo.d \
src\rt\util\utf.d \
src\rt\util\container\array.d \
src\rt\util\container\common.d \
Expand Down
43 changes: 8 additions & 35 deletions src/rt/typeinfo/ti_Acdouble.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,35 @@
*/
module rt.typeinfo.ti_Acdouble;

private import rt.typeinfo.ti_cdouble;
private import rt.util.hash;
private import rt.util.typeinfo;

// cdouble[]

class TypeInfo_Ar : TypeInfo_Array
{
alias F = cdouble;

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return "cdouble[]"; }
override string toString() const { return (F[]).stringof; }

override size_t getHash(in void* p) @trusted const
{
cdouble[] s = *cast(cdouble[]*)p;
return rt.util.hash.hashOf(s.ptr, s.length * cdouble.sizeof);
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
cdouble[] s1 = *cast(cdouble[]*)p1;
cdouble[] s2 = *cast(cdouble[]*)p2;
size_t len = s1.length;

if (len != s2.length)
return false;
for (size_t u = 0; u < len; u++)
{
if (!TypeInfo_r._equals(s1[u], s2[u]))
return false;
}
return true;
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

override int compare(in void* p1, in void* p2) const
{
cdouble[] s1 = *cast(cdouble[]*)p1;
cdouble[] s2 = *cast(cdouble[]*)p2;
size_t len = s1.length;

if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_r._compare(s1[u], s2[u]);
if (c)
return c;
}
if (s1.length < s2.length)
return -1;
else if (s1.length > s2.length)
return 1;
return 0;
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(cdouble);
return cast(inout)typeid(F);
}
}
43 changes: 8 additions & 35 deletions src/rt/typeinfo/ti_Acfloat.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,35 @@
*/
module rt.typeinfo.ti_Acfloat;

private import rt.typeinfo.ti_cfloat;
private import rt.util.hash;
private import rt.util.typeinfo;

// cfloat[]

class TypeInfo_Aq : TypeInfo_Array
{
alias F = cfloat;

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return "cfloat[]"; }
override string toString() const { return (F[]).stringof; }

override size_t getHash(in void* p) @trusted const
{
cfloat[] s = *cast(cfloat[]*)p;
return rt.util.hash.hashOf(s.ptr, s.length * cfloat.sizeof);
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
cfloat[] s1 = *cast(cfloat[]*)p1;
cfloat[] s2 = *cast(cfloat[]*)p2;
size_t len = s1.length;

if (len != s2.length)
return false;
for (size_t u = 0; u < len; u++)
{
if (!TypeInfo_q._equals(s1[u], s2[u]))
return false;
}
return true;
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

override int compare(in void* p1, in void* p2) const
{
cfloat[] s1 = *cast(cfloat[]*)p1;
cfloat[] s2 = *cast(cfloat[]*)p2;
size_t len = s1.length;

if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_q._compare(s1[u], s2[u]);
if (c)
return c;
}
if (s1.length < s2.length)
return -1;
else if (s1.length > s2.length)
return 1;
return 0;
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(cfloat);
return cast(inout)typeid(F);
}
}
43 changes: 8 additions & 35 deletions src/rt/typeinfo/ti_Acreal.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,35 @@
*/
module rt.typeinfo.ti_Acreal;

private import rt.typeinfo.ti_creal;
private import rt.util.hash;
private import rt.util.typeinfo;

// creal[]

class TypeInfo_Ac : TypeInfo_Array
{
alias F = creal;

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return "creal[]"; }
override string toString() const { return (F[]).stringof; }

override size_t getHash(in void* p) @trusted const
{
creal[] s = *cast(creal[]*)p;
return rt.util.hash.hashOf(s.ptr, s.length * creal.sizeof);
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
creal[] s1 = *cast(creal[]*)p1;
creal[] s2 = *cast(creal[]*)p2;
size_t len = s1.length;

if (len != s2.length)
return 0;
for (size_t u = 0; u < len; u++)
{
if (!TypeInfo_c._equals(s1[u], s2[u]))
return false;
}
return true;
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

override int compare(in void* p1, in void* p2) const
{
creal[] s1 = *cast(creal[]*)p1;
creal[] s2 = *cast(creal[]*)p2;
size_t len = s1.length;

if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_c._compare(s1[u], s2[u]);
if (c)
return c;
}
if (s1.length < s2.length)
return -1;
else if (s1.length > s2.length)
return 1;
return 0;
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(creal);
return cast(inout)typeid(F);
}
}
49 changes: 12 additions & 37 deletions src/rt/typeinfo/ti_Adouble.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,49 @@
*/
module rt.typeinfo.ti_Adouble;

private import rt.typeinfo.ti_double;
private import rt.util.hash;
private import rt.util.typeinfo;

// double[]

class TypeInfo_Ad : TypeInfo_Array
{
alias F = double;

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return "double[]"; }
override string toString() const { return (F[]).stringof; }

override size_t getHash(in void* p) @trusted const
{
double[] s = *cast(double[]*)p;
return rt.util.hash.hashOf(s.ptr, s.length * double.sizeof);
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
double[] s1 = *cast(double[]*)p1;
double[] s2 = *cast(double[]*)p2;
size_t len = s1.length;

if (len != s2.length)
return 0;
for (size_t u = 0; u < len; u++)
{
if (!TypeInfo_d._equals(s1[u], s2[u]))
return false;
}
return true;
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

override int compare(in void* p1, in void* p2) const
{
double[] s1 = *cast(double[]*)p1;
double[] s2 = *cast(double[]*)p2;
size_t len = s1.length;

if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_d._compare(s1[u], s2[u]);
if (c)
return c;
}
if (s1.length < s2.length)
return -1;
else if (s1.length > s2.length)
return 1;
return 0;
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(double);
return cast(inout)typeid(F);
}
}

// idouble[]

class TypeInfo_Ap : TypeInfo_Ad
{
override string toString() const { return "idouble[]"; }
alias F = idouble;

override string toString() const { return (F[]).stringof; }

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(idouble);
return cast(inout)typeid(F);
}
}
Loading

0 comments on commit 652014b

Please sign in to comment.