added a .since annotation to hashIdentity

This commit is contained in:
Andreas Rumpf 2020-04-15 23:35:10 +02:00
commit 60ec5c89c5

View file

@ -44,6 +44,8 @@
## * `std/sha1 module <sha1.html>`_ for a sha1 encoder and decoder ## * `std/sha1 module <sha1.html>`_ for a sha1 encoder and decoder
## * `tables module <tables.html>`_ for hash tables ## * `tables module <tables.html>`_ for hash tables
include "system/inclrtl"
type type
Hash* = int ## A hash value. Hash tables using these values should Hash* = int ## A hash value. Hash tables using these values should
## always have a size of a power of two and can use the ``and`` ## always have a size of a power of two and can use the ``and``
@ -172,14 +174,14 @@ proc hash*[T: proc](x: T): Hash {.inline.} =
else: else:
result = hash(pointer(x)) result = hash(pointer(x))
proc hashIdentity*[T: Ordinal](x: T): Hash {.inline.} = proc hashIdentity*[T: Ordinal](x: T): Hash {.inline, since: (1, 3).} =
## The identity hash. I.e. ``hashIdentity(x) = x``. ## The identity hash. I.e. ``hashIdentity(x) = x``.
cast[Hash](ord(x)) cast[Hash](ord(x))
when defined(nimIntHash1): when defined(nimIntHash1):
proc hash*[T: Ordinal](x: T): Hash {.inline.} = proc hash*[T: Ordinal](x: T): Hash {.inline.} =
## Efficient hashing of integers. ## Efficient hashing of integers.
hashIdentity(x) cast[Hash](ord(x))
else: else:
proc hash*[T: Ordinal](x: T): Hash {.inline.} = proc hash*[T: Ordinal](x: T): Hash {.inline.} =
## Efficient hashing of integers. ## Efficient hashing of integers.