/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. module runtime.typeinfo.ti_array_float;
  8. import runtime.typeinfo.ti_float;
  9. class TypeInfo_Af : TypeInfo {
  10. char[] toString() {
  11. return "float[]";
  12. }
  13. hash_t getHash(void *p) {
  14. float[] s = *cast(float[]*)p;
  15. size_t len = s.length;
  16. auto str = s.ptr;
  17. hash_t hash = 0;
  18. while (len) {
  19. hash *= 9;
  20. hash += *cast(uint *)str;
  21. str++;
  22. len--;
  23. }
  24. return hash;
  25. }
  26. int equals(void *p1, void *p2) {
  27. float[] s1 = *cast(float[]*)p1;
  28. float[] s2 = *cast(float[]*)p2;
  29. size_t len = s1.length;
  30. if (len != s2.length) {
  31. return 0;
  32. }
  33. for (size_t u = 0; u < len; u++) {
  34. int c = TypeInfo_f._equals(s1[u], s2[u]);
  35. if (c == 0) {
  36. return 0;
  37. }
  38. }
  39. return 1;
  40. }
  41. int compare(void *p1, void *p2) {
  42. float[] s1 = *cast(float[]*)p1;
  43. float[] s2 = *cast(float[]*)p2;
  44. size_t len = s1.length;
  45. if (s2.length < len) {
  46. len = s2.length;
  47. }
  48. for (size_t u = 0; u < len; u++) {
  49. int c = TypeInfo_f._compare(s1[u], s2[u]);
  50. if (c) {
  51. return c;
  52. }
  53. }
  54. if (s1.length < s2.length) {
  55. return -1;
  56. }
  57. else if (s1.length > s2.length) {
  58. return 1;
  59. }
  60. return 0;
  61. }
  62. size_t tsize() {
  63. return (float[]).sizeof;
  64. }
  65. uint flags() {
  66. return 1;
  67. }
  68. TypeInfo next() {
  69. return typeid(float);
  70. }
  71. }