PageRenderTime 42ms CodeModel.GetById 14ms app.highlight 22ms RepoModel.GetById 2ms app.codeStats 0ms

/runtime/typeinfo/ti_array_cfloat.d

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