support nim 2.0

This commit is contained in:
Eric 2024-01-30 19:25:24 +11:00
parent 92b8ea028a
commit 64cc99442d
No known key found for this signature in database

View File

@ -49,6 +49,22 @@ proc setMethodHandler(
) =
subscriptions.methodHandlers[`method`] = handler
when (NimMajor) >= 2:
proc hash*[A](x: openArray[A]): Hash {.raises: [].} =
## Efficient hashing of arrays and sequences.
## There must be a `hash` proc defined for the element type `A`.
when A is byte:
result = murmurHash(x)
elif A is char:
when nimvm:
result = hashVmImplChar(x, 0, x.high)
else:
result = murmurHash(toOpenArrayByte(x, 0, x.high))
else:
for a in x:
result = result !& hash(a)
result = !$result
func hash*(n: OrderedTable[string, JsonNode]): Hash {.raises: [].}
proc hash*(n: JsonNode): Hash {.noSideEffect, raises: [].} =