I've almost finished converting the default Table implementations to running on the shared heap, using my "shared seq". But I'm running into trouble because my type doesn't handle indexes like the seq does. Unless I'm mistaken, it seems that seq can accept negative array indexes too.
Here is the code lines that cause an error when using replacing seq with my "shared seq".
template maxHash(t): untyped = high(t.data)
# ...
var h: Hash = hc and maxHash(t)
while isFilled(t.data[h].hcode): # t.data is a seq in the original code.
# ...
And my "shared seq" gets called with an index of -3359640189252970303, which it (obviously) doesn't like. Idk where the implementation of "proc []" for seq is, so I cannot look it up. The closest I have found (in system.nim) is this:
# :array|openarray|string|seq|cstring|tuple
proc `[]`*[I: Ordinal;T](a: T; i: I): T {.
noSideEffect, magic: "ArrGet".}
But idk where/how "ArrGet" is defined.
var a = 0
a -= 1
echo @[1, 2, 3, 4, 5][a]
gives Error: unhandled exception: index out of bounds [IndexError] during runtime
echo @[1, 2, 3, 4, 5][-1]
gives the same error during compile time
Unless I'm mistaken, it seems that seq can accept negative array indexes too.
Unless I'm mistaken, it cannot :)
The "negative" indices that works are ^1, ^2, etc., not -1, -2.
You need to implement [] that accepts int or Backwardsindex like I do here.
(This is assuming you are on Nim master)
Hi, mratsim! I'm actually using Nim version "whatever was available when I installed it", which is "0.17.2".
Thanks a lot; that sure will save me masses of time!
EDIT: Looking at your code, it seems I "missed" a bunch of methods (like "low()") that I assume would also work on seq. So, double thanks!