1 2 module rt.compiler.dmd.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 version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 71 { 72 return 0; 73 } 74 } 75 76 unittest 77 { 78 int[][] a = [[5,3,8,7], [2,5,3,8,7]]; 79 a.sort; 80 assert(a == [[2,5,3,8,7], [5,3,8,7]]); 81 82 a = [[5,3,8,7], [5,3,8]]; 83 a.sort; 84 assert(a == [[5,3,8], [5,3,8,7]]); 85 } 86 87 // uint[] 88 89 class TypeInfo_Ak : TypeInfo_Ai 90 { 91 override char[] toString() { return "uint[]"; } 92 93 override int compare(in void* p1, in void* p2) 94 { 95 uint[] s1 = *cast(uint[]*)p1; 96 uint[] s2 = *cast(uint[]*)p2; 97 size_t len = s1.length; 98 99 if (s2.length < len) 100 len = s2.length; 101 for (size_t u = 0; u < len; u++) 102 { 103 int result = s1[u] - s2[u]; 104 if (result) 105 return result; 106 } 107 if (s1.length < s2.length) 108 return -1; 109 else if (s1.length > s2.length) 110 return 1; 111 return 0; 112 } 113 114 override TypeInfo next() 115 { 116 return typeid(uint); 117 } 118 } 119 120 // dchar[] 121 122 class TypeInfo_Aw : TypeInfo_Ak 123 { 124 override char[] toString() { return "dchar[]"; } 125 126 override TypeInfo next() 127 { 128 return typeid(dchar); 129 } 130 }