1 
2 module rt.compiler.ldc.typeinfo.ti_Aint;
3 
4 private import tango.stdc.string : memcmp;
5 private import rt.compiler.util.hash;
6 
7 // int[]
8 
9 class TypeInfo_Ai : TypeInfo_Array
10 {
11     override char[] toString() { return "int[]"; }
12 
13     override hash_t getHash(in void* p)
14     {   int[] s = *cast(int[]*)p;
15         auto len = s.length;
16         auto str = s.ptr;
17         return rt_hash_str(str,len*int.sizeof,0);
18     }
19 
20     override equals_t equals(in void* p1, in void* p2)
21     {
22         int[] s1 = *cast(int[]*)p1;
23         int[] s2 = *cast(int[]*)p2;
24 
25         return s1.length == s2.length &&
26                memcmp(cast(void *)s1, cast(void *)s2, s1.length * int.sizeof) == 0;
27     }
28 
29     override int compare(in void* p1, in void* p2)
30     {
31         int[] s1 = *cast(int[]*)p1;
32         int[] s2 = *cast(int[]*)p2;
33         size_t len = s1.length;
34 
35         if (s2.length < len)
36             len = s2.length;
37         for (size_t u = 0; u < len; u++)
38         {
39             int result = s1[u] - s2[u];
40             if (result)
41                 return result;
42         }
43         if (s1.length < s2.length)
44             return -1;
45         else if (s1.length > s2.length)
46             return 1;
47         return 0;
48     }
49 
50     override size_t talign()
51     {
52         return (int[]).alignof;
53     }
54 
55     override size_t tsize()
56     {
57         return (int[]).sizeof;
58     }
59 
60     override uint flags()
61     {
62         return 1;
63     }
64 
65     override TypeInfo next()
66     {
67         return typeid(int);
68     }
69 }
70 
71 unittest
72 {
73     int[][] a = [[5,3,8,7], [2,5,3,8,7]];
74     a.sort;
75     assert(a == [[2,5,3,8,7], [5,3,8,7]]);
76 
77     a = [[5,3,8,7], [5,3,8]];
78     a.sort;
79     assert(a == [[5,3,8], [5,3,8,7]]);
80 }
81 
82 // uint[]
83 
84 class TypeInfo_Ak : TypeInfo_Ai
85 {
86     override char[] toString() { return "uint[]"; }
87 
88     override int compare(in void* p1, in void* p2)
89     {
90         uint[] s1 = *cast(uint[]*)p1;
91         uint[] s2 = *cast(uint[]*)p2;
92         size_t len = s1.length;
93 
94         if (s2.length < len)
95             len = s2.length;
96         for (size_t u = 0; u < len; u++)
97         {
98             int result = s1[u] - s2[u];
99             if (result)
100                 return result;
101         }
102         if (s1.length < s2.length)
103             return -1;
104         else if (s1.length > s2.length)
105             return 1;
106         return 0;
107     }
108 
109     override TypeInfo next()
110     {
111         return typeid(uint);
112     }
113 }
114 
115 // dchar[]
116 
117 class TypeInfo_Aw : TypeInfo_Ak
118 {
119     override char[] toString() { return "dchar[]"; }
120 
121     override TypeInfo next()
122     {
123         return typeid(dchar);
124     }
125 }