tneginthash.nim 363 B

12345678910111213141516171819202122
  1. # issue #19929
  2. import std/[tables, hashes]
  3. type Foo = object
  4. a: int
  5. proc hash(f: Foo): Hash =
  6. var h: Hash = 0
  7. h = h !& hash(f.a)
  8. result = !$h
  9. proc transpose[T, S](data: array[T, S]): Table[S, T] =
  10. for i, x in data:
  11. result[x] = i
  12. const xs = [Foo(a: 5), Foo(a: -5)]
  13. const x = transpose(xs)
  14. doAssert x[Foo(a: -5)] == 1
  15. doAssert x[Foo(a: 5)] == 0