comparison lphobos/typeinfo2/ti_Ashort.d @ 59:362825278842 trunk

[svn r63] Forgot lphobos/typeinfo2
author lindquist
date Thu, 25 Oct 2007 09:04:00 +0200
parents
children
comparison
equal deleted inserted replaced
58:2c3cd3596187 59:362825278842
1 module typeinfo2.ti_Ashort;
2
3 extern(C) int memcmp(void*,void*,size_t);
4
5 // short[]
6
7 class TypeInfo_As : TypeInfo
8 {
9 char[] toString() { return "short[]"; }
10
11 hash_t getHash(void *p)
12 { short[] s = *cast(short[]*)p;
13 size_t len = s.length;
14 short *str = s.ptr;
15 hash_t hash = 0;
16
17 while (1)
18 {
19 switch (len)
20 {
21 case 0:
22 return hash;
23
24 case 1:
25 hash *= 9;
26 hash += *cast(ushort *)str;
27 return hash;
28
29 default:
30 hash *= 9;
31 hash += *cast(uint *)str;
32 str += 2;
33 len -= 2;
34 break;
35 }
36 }
37
38 return hash;
39 }
40
41 int equals(void *p1, void *p2)
42 {
43 short[] s1 = *cast(short[]*)p1;
44 short[] s2 = *cast(short[]*)p2;
45
46 return s1.length == s2.length &&
47 memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.sizeof) == 0;
48 }
49
50 int compare(void *p1, void *p2)
51 {
52 short[] s1 = *cast(short[]*)p1;
53 short[] s2 = *cast(short[]*)p2;
54 size_t len = s1.length;
55
56 if (s2.length < len)
57 len = s2.length;
58 for (size_t u = 0; u < len; u++)
59 {
60 int result = s1[u] - s2[u];
61 if (result)
62 return result;
63 }
64 return cast(int)s1.length - cast(int)s2.length;
65 }
66
67 size_t tsize()
68 {
69 return (short[]).sizeof;
70 }
71
72 uint flags()
73 {
74 return 1;
75 }
76
77 TypeInfo next()
78 {
79 return typeid(short);
80 }
81 }
82
83
84 // ushort[]
85
86 class TypeInfo_At : TypeInfo_As
87 {
88 char[] toString() { return "ushort[]"; }
89
90 int compare(void *p1, void *p2)
91 {
92 ushort[] s1 = *cast(ushort[]*)p1;
93 ushort[] s2 = *cast(ushort[]*)p2;
94 size_t len = s1.length;
95
96 if (s2.length < len)
97 len = s2.length;
98 for (size_t u = 0; u < len; u++)
99 {
100 int result = s1[u] - s2[u];
101 if (result)
102 return result;
103 }
104 return cast(int)s1.length - cast(int)s2.length;
105 }
106
107 TypeInfo next()
108 {
109 return typeid(ushort);
110 }
111 }
112
113 // wchar[]
114
115 class TypeInfo_Au : TypeInfo_At
116 {
117 char[] toString() { return "wchar[]"; }
118
119 TypeInfo next()
120 {
121 return typeid(wchar);
122 }
123 }
124
125