PageRenderTime 43ms CodeModel.GetById 14ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/runtime/typeinfo/ti_array_creal.d

http://github.com/wilkie/djehuty
D | 95 lines | 69 code | 20 blank | 6 comment | 12 complexity | bce0d5c6c0558885fcca6ad3d7d9b313 MD5 | raw file
 1/*
 2 * ti_array_creal.d
 3 *
 4 * This module implements the TypeInfo for a creal[]
 5 *
 6 */
 7
 8module runtime.typeinfo.ti_array_creal;
 9
10import runtime.typeinfo.ti_creal;
11
12class TypeInfo_Ac : TypeInfo {
13	char[] toString() {
14		return "creal[]";
15	}
16
17	hash_t getHash(void *p) {
18		creal[] s = *cast(creal[]*)p;
19		size_t len = s.length;
20		creal *str = s.ptr;
21		hash_t hash = 0;
22
23		while (len) {
24			hash *= 9;
25			hash += (cast(uint *)str)[0];
26			hash += (cast(uint *)str)[1];
27			hash += (cast(uint *)str)[2];
28			hash += (cast(uint *)str)[3];
29			hash += (cast(uint *)str)[4];
30			str++;
31			len--;
32		}
33
34		return hash;
35	}
36
37	int equals(void *p1, void *p2) {
38		creal[] s1 = *cast(creal[]*)p1;
39		creal[] s2 = *cast(creal[]*)p2;
40		size_t len = s1.length;
41
42		if (len != s2.length) {
43			return 0;
44		}
45
46		for (size_t u = 0; u < len; u++) {
47			int c = TypeInfo_c._equals(s1[u], s2[u]);
48
49			if (c == 0) {
50				return 0;
51			}
52		}
53
54		return 1;
55	}
56
57	int compare(void *p1, void *p2) {
58		creal[] s1 = *cast(creal[]*)p1;
59		creal[] s2 = *cast(creal[]*)p2;
60		size_t len = s1.length;
61
62		if (s2.length < len) {
63			len = s2.length;
64		}
65
66		for (size_t u = 0; u < len; u++) {
67			int c = TypeInfo_c._compare(s1[u], s2[u]);
68
69			if (c) {
70				return c;
71			}
72		}
73
74		if (s1.length < s2.length) {
75			return -1;
76		}
77		else if (s1.length > s2.length) {
78			return 1;
79		}
80
81		return 0;
82	}
83
84	size_t tsize() {
85		return (creal[]).sizeof;
86	}
87
88	uint flags() {
89		return 1;
90	}
91
92	TypeInfo next() {
93		return typeid(creal);
94	}
95}