summary refs log tree commit diff stats
path: root/tests/js/tneginthash.nim
blob: c082405c9f2cf6dbb606f955b74a217b03f09130 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# issue #19929

import std/[tables, hashes]

type Foo = object
  a: int

proc hash(f: Foo): Hash =
  var h: Hash = 0
  h = h !& hash(f.a)
  result = !$h

proc transpose[T, S](data: array[T, S]): Table[S, T] =
  for i, x in data:
    result[x] = i

const xs = [Foo(a: 5), Foo(a: -5)]
const x = transpose(xs)

doAssert x[Foo(a: -5)] == 1
doAssert x[Foo(a: 5)] == 0