I have a list of int-int, which I'm storing as a _seq_ of _(int,int)_ tuples
(the first int being a hash value, so it's not like 0-1-2-3...)
I have to test this structure for membership (whether an index - the first
_int_ \- exists), look up a value (get the second _int_ for a specific first
_int_ ), update a value, etc. Pretty much like a dictionary / hash table.
Right now, this is how I'm doing it:
proc getValueForKey(ctx: Context, hs: int): Value {.inline.} =
var j = 0
while j<ctx.len:
if ctx[j][0]==hs:
return Stack[i][j][1]
inc(j)
return 0
Run
proc hasKey*(ctx: Context, key: int): bool {.inline.} =
var i = 0
while i<ctx.len:
if ctx[i][0]==key: return true
inc(i)
return false
Run
proc setValueForKey(ctx: Context, hs: int, v: Value): Value {.inline.} =
var j = 0
while j<ctx.len:
if ctx[j][0]==hs:
ctx[j][1] = v
return ctx[j][1]
inc(j)
# value did not exist in current ctx
result = 0
Run
\---
**The question is:** Is there any way I could do this more efficiently? (What
matters to me is performance)