comparison lphobos/std/typeinfounsupported/ti_Ashort.d @ 1:c53b6e3fe49a trunk

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