File: mobjhash.nim

package info (click to toggle)
nim 2.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,951,160 kB
  • sloc: sh: 24,599; ansic: 1,771; python: 1,493; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (80 lines) | stat: -rw-r--r-- 1,674 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import hashes

type
  Obj* = object
    x*, y*: int
    z*: string # to be ignored for equality

proc `==`*(a, b: Obj): bool =
  a.x == b.x and a.y == b.y

proc hash*(a: Obj): Hash =
  !$(hash(a.x) !& hash(a.y))

type
  RefObj* = ref object
    x*, y*: int
    z*: string # to be ignored for equality

proc `==`*(a, b: RefObj): bool =
  a.x == b.x and a.y == b.y

proc hash*(a: RefObj): Hash =
  !$(hash(a.x) !& hash(a.y))

type
  GenericObj1*[T] = object
    x*, y*: T
    z*: string # to be ignored for equality

proc `==`*[T](a, b: GenericObj1[T]): bool =
  a.x == b.x and a.y == b.y

proc hash*[T](a: GenericObj1[T]): Hash =
  !$(hash(a.x) !& hash(a.y))

type
  GenericObj2*[T] = object
    x*, y*: T
    z*: string # to be ignored for equality

proc `==`*(a, b: GenericObj2): bool =
  a.x == b.x and a.y == b.y

proc hash*(a: GenericObj2): Hash =
  !$(hash(a.x) !& hash(a.y))

type
  GenericObj3*[T] = object
    x*, y*: T
    z*: string # to be ignored for equality
  GenericObj3Alias*[T] = GenericObj3[T]

proc `==`*[T](a, b: GenericObj3Alias[T]): bool =
  a.x == b.x and a.y == b.y

proc hash*[T](a: GenericObj3Alias[T]): Hash =
  !$(hash(a.x) !& hash(a.y))

type
  GenericObj4*[T] = object
    x*, y*: T
    z*: string # to be ignored for equality
  GenericObj4Alias*[T] = GenericObj4[T]

proc `==`*(a, b: GenericObj4): bool =
  a.x == b.x and a.y == b.y

proc hash*(a: GenericObj4): Hash =
  !$(hash(a.x) !& hash(a.y))

type
  GenericRefObj*[T] = ref object
    x*, y*: T
    z*: string # to be ignored for equality

proc `==`*[T](a, b: GenericRefObj[T]): bool =
  a.x == b.x and a.y == b.y

proc hash*[T](a: GenericRefObj[T]): Hash =
  !$(hash(a.x) !& hash(a.y))