forked from dlang/phobos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ti_Ashort.d
69 lines (56 loc) · 1.02 KB
/
ti_Ashort.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import string;
// short[]
class TypeInfo_As : TypeInfo
{
uint getHash(void *p)
{ short[] s = *(short[]*)p;
uint len = s.length;
short *str = s;
uint hash = 0;
while (1)
{
switch (len)
{
case 0:
return hash;
case 1:
hash *= 9;
hash += *(short *)str;
return hash;
default:
hash *= 9;
hash += *(uint *)str;
str += 2;
len -= 2;
break;
}
}
return hash;
}
int equals(void *p1, void *p2)
{
short[] s1 = *(short[]*)p1;
short[] s2 = *(short[]*)p2;
return s1.length == s2.length &&
memcmp((void *)s1, (void *)s2, s1.length * short.size) == 0;
}
int compare(void *p1, void *p2)
{
short[] s1 = *(short[]*)p1;
short[] s2 = *(short[]*)p2;
uint len = s1.length;
if (s2.length < len)
len = s2.length;
for (uint u = 0; u < len; u++)
{
int result = s1[u] - s2[u];
if (result)
return result;
}
return cast(int)s1.length - cast(int)s2.length;
}
int tsize()
{
return (short[]).size;
}
}