2 * TypeInfo support code.
4 * Copyright: Copyright Digital Mars 2004 - 2009.
5 * License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6 * Authors: Walter Bright
9 /* Copyright Digital Mars 2004 - 2009.
10 * Distributed under the Boost Software License, Version 1.0.
11 * (See accompanying file LICENSE or copy at
12 * http://www.boost.org/LICENSE_1_0.txt)
14 module rt.typeinfo.ti_Aint;
16 private import core.stdc.string;
17 private import rt.util.hash;
19 extern (C) void[] _adSort(void[] a, TypeInfo ti);
23 class TypeInfo_Ai : TypeInfo_Array
25 override bool opEquals(Object o) { return TypeInfo.opEquals(o); }
27 override string toString() const { return "int[]"; }
29 override size_t getHash(in void* p) @trusted const
31 const s = *cast(const int[]*)p;
32 return rt.util.hash.hashOf(s, 0);
35 override bool equals(in void* p1, in void* p2) const
37 int[] s1 = *cast(int[]*)p1;
38 int[] s2 = *cast(int[]*)p2;
40 return s1.length == s2.length &&
41 memcmp(cast(void *)s1, cast(void *)s2, s1.length * int.sizeof) == 0;
44 override int compare(in void* p1, in void* p2) const
46 int[] s1 = *cast(int[]*)p1;
47 int[] s2 = *cast(int[]*)p2;
48 size_t len = s1.length;
52 for (size_t u = 0; u < len; u++)
56 else if (s1[u] > s2[u])
59 if (s1.length < s2.length)
61 else if (s1.length > s2.length)
66 override @property inout(TypeInfo) next() inout
68 return cast(inout)typeid(int);
74 int[][] a = [[5,3,8,7], [2,5,3,8,7]];
75 _adSort(*cast(void[]*)&a, typeid(a[0]));
76 assert(a == [[2,5,3,8,7], [5,3,8,7]]);
78 a = [[5,3,8,7], [5,3,8]];
79 _adSort(*cast(void[]*)&a, typeid(a[0]));
80 assert(a == [[5,3,8], [5,3,8,7]]);
85 // Issue 13073: original code uses int subtraction which is susceptible to
86 // integer overflow, causing the following case to fail.
87 int[] a = [int.max, int.max];
88 int[] b = [int.min, int.min];
95 class TypeInfo_Ak : TypeInfo_Ai
97 override string toString() const { return "uint[]"; }
99 override int compare(in void* p1, in void* p2) const
101 uint[] s1 = *cast(uint[]*)p1;
102 uint[] s2 = *cast(uint[]*)p2;
103 size_t len = s1.length;
107 for (size_t u = 0; u < len; u++)
111 else if (s1[u] > s2[u])
114 if (s1.length < s2.length)
116 else if (s1.length > s2.length)
121 override @property inout(TypeInfo) next() inout
123 return cast(inout)typeid(uint);
129 // Original test case from issue 13073
130 uint x = 0x22_DF_FF_FF;
131 uint y = 0xA2_DF_FF_FF;
132 assert(!(x < y && y < x));
135 assert(!(a < b && b < a)); // Original failing case
138 assert(!(a1 < b1 && b1 < a1)); // Original failing case
143 class TypeInfo_Aw : TypeInfo_Ak
145 override string toString() const { return "dchar[]"; }
147 override @property inout(TypeInfo) next() inout
149 return cast(inout)typeid(dchar);