mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-22 00:41:28 +00:00
added hash for uints (#5435)
This commit is contained in:
committed by
Andreas Rumpf
parent
f250c30b9d
commit
5774145f5d
@@ -112,6 +112,14 @@ proc hash*(x: int64): Hash {.inline.} =
|
||||
## efficient hashing of int64 integers
|
||||
result = toU32(x)
|
||||
|
||||
proc hash*(x: uint): Hash {.inline.} =
|
||||
## efficient hashing of unsigned integers
|
||||
result = cast[int](x)
|
||||
|
||||
proc hash*(x: uint64): Hash {.inline.} =
|
||||
## efficient hashing of uint64 integers
|
||||
result = toU32(cast[int](x))
|
||||
|
||||
proc hash*(x: char): Hash {.inline.} =
|
||||
## efficient hashing of characters
|
||||
result = ord(x)
|
||||
|
||||
@@ -72,4 +72,19 @@ block:
|
||||
var t = initTable[int, int]()
|
||||
t[0] = 0
|
||||
|
||||
# Check hashability of all integer types (issue #5429)
|
||||
block:
|
||||
let intTables = (
|
||||
newTable[int, string](),
|
||||
newTable[int8, string](),
|
||||
newTable[int16, string](),
|
||||
newTable[int32, string](),
|
||||
newTable[int64, string](),
|
||||
newTable[uint, string](),
|
||||
newTable[uint8, string](),
|
||||
newTable[uint16, string](),
|
||||
newTable[uint32, string](),
|
||||
newTable[uint64, string](),
|
||||
)
|
||||
|
||||
echo "true"
|
||||
|
||||
Reference in New Issue
Block a user