mobjhash.nim 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import hashes
  2. type
  3. Obj* = object
  4. x*, y*: int
  5. z*: string # to be ignored for equality
  6. proc `==`*(a, b: Obj): bool =
  7. a.x == b.x and a.y == b.y
  8. proc hash*(a: Obj): Hash =
  9. !$(hash(a.x) !& hash(a.y))
  10. type
  11. RefObj* = ref object
  12. x*, y*: int
  13. z*: string # to be ignored for equality
  14. proc `==`*(a, b: RefObj): bool =
  15. a.x == b.x and a.y == b.y
  16. proc hash*(a: RefObj): Hash =
  17. !$(hash(a.x) !& hash(a.y))
  18. type
  19. GenericObj1*[T] = object
  20. x*, y*: T
  21. z*: string # to be ignored for equality
  22. proc `==`*[T](a, b: GenericObj1[T]): bool =
  23. a.x == b.x and a.y == b.y
  24. proc hash*[T](a: GenericObj1[T]): Hash =
  25. !$(hash(a.x) !& hash(a.y))
  26. type
  27. GenericObj2*[T] = object
  28. x*, y*: T
  29. z*: string # to be ignored for equality
  30. proc `==`*(a, b: GenericObj2): bool =
  31. a.x == b.x and a.y == b.y
  32. proc hash*(a: GenericObj2): Hash =
  33. !$(hash(a.x) !& hash(a.y))
  34. type
  35. GenericObj3*[T] = object
  36. x*, y*: T
  37. z*: string # to be ignored for equality
  38. GenericObj3Alias*[T] = GenericObj3[T]
  39. proc `==`*[T](a, b: GenericObj3Alias[T]): bool =
  40. a.x == b.x and a.y == b.y
  41. proc hash*[T](a: GenericObj3Alias[T]): Hash =
  42. !$(hash(a.x) !& hash(a.y))
  43. type
  44. GenericObj4*[T] = object
  45. x*, y*: T
  46. z*: string # to be ignored for equality
  47. GenericObj4Alias*[T] = GenericObj4[T]
  48. proc `==`*(a, b: GenericObj4): bool =
  49. a.x == b.x and a.y == b.y
  50. proc hash*(a: GenericObj4): Hash =
  51. !$(hash(a.x) !& hash(a.y))
  52. type
  53. GenericRefObj*[T] = ref object
  54. x*, y*: T
  55. z*: string # to be ignored for equality
  56. proc `==`*[T](a, b: GenericRefObj[T]): bool =
  57. a.x == b.x and a.y == b.y
  58. proc hash*[T](a: GenericRefObj[T]): Hash =
  59. !$(hash(a.x) !& hash(a.y))