PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/runtime/typeinfo/ti_array_float.d

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