I was trying to add an items() iterator. As Nim interators do not support direct iteration, it can be done with a stack or references to the parent and the current child. As the parent reference was already there I added a cur index and got this, which seems to be OK:
H[M, D: Dim; RT, LT] = ref object of RTRef[RT]
parent: H[M, D, RT, LT]
numEntries: int
cur: int # for iteration
level: int
iterator items*[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]): L[D, RT, LT] =
var el: H[M, D, RT, LT] = t.root
assert el.parent == nil
el.cur = 0
while el != nil:
if el of Leaf[M, D, RT, LT]:
for i, o in Leaf[M, D, RT, LT](el).a:
if i == Leaf[M, D, RT, LT](el).numEntries: break
yield o
el = el.parent
elif el of Node[M, D, RT, LT]:
if el.cur < el.numEntries:
let h = el
el = Node[M, D, RT, LT](el).a[el.cur].n
assert el.parent == h
el.cur = 0
h.cur += 1
else:
el = el.parent
else: assert false
But the initial module gives a lot of warnings, see
https://github.com/StefanSalewski/RTree/issues/1
The "Hint: condition is always true:" should be no problem.
For /tmp/hhh/rtree.nim(283, 24) Warning: Deprecated since v1.4; there should not be high(value). Use high(type).; high is deprecated [Deprecated]
Should I really replace
var m0 = lx.b[0].a.high
with
var m0 = lx.b[0].a.typeof.high ?
And the final problem which I could not fix 3 years ago is:
I am still not able to avoid the auto keyword. This does not compile:
proc center(r: Box): BoxCenter[r.len, type(r[0].a)]
Is there a trick available to avoid auto? Because I can remember a discussion maybe two years ago that Mr. Rumpf considers to remove the auto keyword?
Final question: In the code I am using many constructs like type(r[0].a) which seems to be accepted by the compiler. Should we better use typeof() like typeof(r[0].a) now?