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