@cricket \- also note that perhaps non-intuitively (but well documented) `proc 
pop*[A, B](t: OrderedTable, key: A,...)` and its related `del` are `O(n)` 
operations where `n` here is the size of the `t` in question. Fixing that 
requires the intrusively merged linked list to go from singly- to doubly- 
linked and @Araq does not like to charge "non-delete workload" cases for things 
only needed by mixed workloads. (In this case the charge is space for the 2nd 
link.)

So, you should definitely use @jibal's fine final approach with a `Table` of 
indices into a `seq` if you don't need to iterate over keys in insert-order, 
but you want to iterate over the values in insert-order.

You can also store only the index in the `Table` and have a `seq[(K,V)]` which 
is often called a "compact table", but then you probably need to write your own 
hash table impl that will do the delete-re-insert in the "index/hash part" 
without disturbing the `seq[(K,V)]` part that is keeping insert order for you. 
I have an impl of this at 
<https://github.com/c-blake/adix/blob/master/adix/olset.nim> (I am in the 
middle of a kind of big re-org/re-write of all that stuff this weekend/early 
next week, but that code might help get you started.) That does not yet have an 
`editKey` operation yet, though it would be possible with this kind of set up. 
(Honestly, that operation is more rarely provided than `add`/`allValues` 
duplicate key stuff.) There is also <https://github.com/LemonBoy/compactdict> 
which may be more easy to amend/understand.

Reply via email to