Its not that simple. Capacity != Count in underlying table. Still, IMO this 
should be in tables.nim. Its not ideal but better than nothing.
    
    
    proc raiseIndexError(ndx, max : int) =
        raise newException(IndexError, "index " & $ndx & " not in 0.." & 
$(max-1))
    
    proc keyAt*[A,B](t: OrderedTable[A, B], at: int) : A =
        if at<0 or at>=t.counter:
            raiseIndexError(at,t.counter)
        var ndx = 0
        forAllOrderedPairs:
            if at == ndx:
                result = t.data[h].key
                break
            inc(ndx)
    
    proc valueAt*[A,B](t: OrderedTable[A, B], at : int) : B =
        if at<0 or at>=t.counter:
            raiseIndexError(at,t.counter)
        if at<0 or at>=t.counter:
            raise newException(IndexError, $at)
        var ndx = 0
        forAllOrderedPairs:
            if at == ndx:
                result = t.data[h].val
                break
            inc(ndx)
    
    
    Run

Reply via email to