4 ms·
OrderedTable in Nim appears to be the same and still have O(n) performance. On a delete, an entirely new table is constructed. https://github.com/nim-lang/Nim
by prirun 1mo ago
OrderedTable in Nim appears to be the same and still have O(n) performance. On a delete, an entirely new table is constructed.
https://github.com/nim-lang/Nim/blob/devel/lib/pure/collections/tables.nim https://github.com/nim-lang/Nim/blob/devel/lib/pure/collecti...
I didn't know about Nimony and just took a look.
https://github.com/nim-lang/nimony/blob/master/lib/std/tables.nim https://github.com/nim-lang/nimony/blob/master/lib/std/table...
OrderedTable is now a synonym for Table, ie, both are ordered. To delete a key, the key is looked up to get an index position x in a Seq, the Seq entries after x are shifted left, the Seq is trimmed of the last element, and then the entire table is rehashed because shifting the Seq invalidates the previous hash codes. The performance is better than Nim OrderedTables because at least an entirely new table isn't created, and it probably works fine for small tables, but it still isn't O(1). The performance would be similar to removing an item from a single-threaded sorted list: most painful to remove the 1st element, least painful to remove the last element, but then you still have to rehash the entire table.