Congyuwang / RocksDict

Python fast on-disk dictionary / RocksDB & SpeeDB Python binding
https://congyuwang.github.io/RocksDict/rocksdict.html
MIT License
176 stars 8 forks source link

(Insert) order guarantee #76

Closed fungs closed 1 year ago

fungs commented 1 year ago

Hi,

starting from Python 3.7, dict() objects guarantee insert order, much like collections.OrderedDict. Is there any order guarantee or possibilities for this library? I didn't find any statement in the docs.

Best

Congyuwang commented 1 year ago

In raw mode. Keys are ordered as rocksdb will order them (just ordered). If you are storing Python string / int / etc., each type of keys are group ordered.

However for other objects, since the keys are pickle serialized, the order is uncertain. There is no way to ensure for these keys since calling into Python for comparison would be too slow.

Congyuwang commented 1 year ago

I do recommend using raw mode for better performance though.

fungs commented 1 year ago

Thanks. I assume you mean byte order and not insert (time) order.

fungs commented 1 year ago

Seems like it is nothing one should rely on.

Congyuwang commented 1 year ago

Right. They are sorted like a treemap. Not like a queue.

Congyuwang commented 1 year ago

If you need to iterate them according to insertion order. Just make a new column family to map (insert sequence no) -> (key). And then iterate over that column family and fetch the value using the keys.