Nim: Orderedtable only works with sequential keys

Created on 30 May 2017  路  3Comments  路  Source: nim-lang/Nim

OrderedTable does not work with non-sequential keys. tested on nim-0.17

var t = initOrderedTable[int,string]()

for i in countUp(1,1000):
 var x = random(1000)
 t.add(x,"meh")

Traceback (most recent call last)
a10.nim(8)               a10
tableimpl.nim(82)        add
tables.nim(596)          enlarge
tables.nim               rawInsert
system.nim(2656)         sysFatal
Error: unhandled exception: index out of bounds [IndexError]
Showstopper Stdlib

Most helpful comment

As discussed with @Araq I will try to reimplement OrderedTable with a more optimized approach

references for hashmap algorithm, although it will likely end up quite different as Nim is not Python.
https://morepypy.blogspot.fr/2015/01/faster-more-memory-efficient-and-more.html
https://github.com/python/cpython/blob/master/Objects/dictobject.c

All 3 comments

As discussed with @Araq I will try to reimplement OrderedTable with a more optimized approach

references for hashmap algorithm, although it will likely end up quite different as Nim is not Python.
https://morepypy.blogspot.fr/2015/01/faster-more-memory-efficient-and-more.html
https://github.com/python/cpython/blob/master/Objects/dictobject.c

Awesome @Parashurama

This has been fixed.

Was this page helpful?
0 / 5 - 0 ratings