I did a little research and found an interesting post on mixing signed /
unsigned issues, so I guess it's a good idea Nim doesn't like that:
[https://critical.eschertech.com/2010/04/07/danger-unsigned-types-used-here](https://critical.eschertech.com/2010/04/07/danger-unsigned-types-used-here)
It's still a little confusing to me that int64 isn't compatible with int on a
64-bit machine, and that it's necessary to add types to integer constants. I've
seen that in Nim system code and am not too crazy about it, but there's
probably a good reason for it that I just don't understand. I've never seen it
much in other code except when doing right shifts to control whether signs
extend or not.
And thanks @cblake for your post about hash(x) = x. I revised my test to
actually hash the integers as you advised, and probably like Go does (though I
haven't verified that):
import hashes
proc hash(x: int): Hash {.inline.} =
## This is from https://github.com/tommyettinger
var x = uint64(x)
x = x xor (x shr 27)
x = x * 0x3C79AC492BA7B653'u64
x = x xor (x shr 33)
x = x * 0x1C69B3F74AC4AE35'u64
x = x xor (x shr 27)
result = Hash(x)
import tables
const
n = 10_000_000
var
map = initTable[int, int]()
for i in 0..<n:
map[i] = i
for i in 0..<3:
for j in 0..<n:
map[j] = map[j] + 1
echo map[13]
ms:nim jim$ /usr/bin/time -l ./p3hash
16
3.69 real 3.46 user 0.22 sys
806027264 maximum resident set size
196793 page reclaims
9 page faults
1 voluntary context switches
5 involuntary context switches
Run