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.

2017-12-05 20:15:51

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

2017-12-06 04:31:49

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.

2017-12-06 14:33:20
It seems "newSeq[T](N)" creates a seq with not only N "capacity", but also N "size" (which contradict my general assumption has to how newly created "empty" "collections" normally work (mostly based on coding on Java), and hence my mistake trying to emulate seq on the shared heap).
2017-12-06 19:54:41

You need to implement [] that accepts int or Backwardsindex like I do here.

(This is assuming you are on Nim master)

2017-12-07 12:34:45

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!

2017-12-07 18:47:44