Level / abstract-leveldown

An abstract prototype matching the leveldown API.
MIT License
146 stars 53 forks source link

Expose prev() ? #339

Closed MeirionHughes closed 2 years ago

MeirionHughes commented 5 years ago

leveldb appears to have the option to move to the previous entry during iteration via prev() https://github.com/Level/leveldown/blob/master/deps/leveldb/leveldb-1.20/db/db_iter.cc#L205

is there any reason this couldn't be exposed through AbstractLevelDown (and eventually up the ecosystem)

I have a rather specific use-case, where I want to seek forward (gte: X) and if the result is R > X then I want to get the immediate predecessor (P < X). In a binary-tree this would be O(1) from the current position, rather than O(log n) for a fresh search.

vweevers commented 5 years ago

I suggest to try this out in leveldown (because that's the trickiest to achieve, taking its highWaterMark logic into account etc), expose in abstract-leveldown later.