Convert store iterators to variants rather than using polymorphism.#4759
Convert store iterators to variants rather than using polymorphism.#4759clemahieu merged 2 commits intonanocurrency:developfrom
Conversation
Test Results for Commit 37f4f5cPull Request 4759: Results Test Case Results
Last updated: 2024-10-27 03:00:50 UTC |
be25823 to
d71b556
Compare
…transaction->GetHandle() Returning either Transaction * or ReadOptions * seems dubious, the intent of this commit is to retain 1-to-1 compatibility while adding strong typing.
d71b556 to
0cffbf5
Compare
|
I checked on using std::reverse_iterator rather than implementing our own though it looks like it only supports copyable iterators. https://en.cppreference.com/w/cpp/iterator/reverse_iterator/reverse_iterator |
0cffbf5 to
4bfdbee
Compare
pwojcikdev
left a comment
There was a problem hiding this comment.
Really, really good. Already makes working with database backends simpler.
| { | ||
| if (dynamic_cast<nano::store::read_transaction const *> (&transaction_a) != nullptr) | ||
| { | ||
| return static_cast<::rocksdb::ReadOptions *> (transaction_a.get_handle ()); |
There was a problem hiding this comment.
Is it possible for the handle to store the pointer as std::any and use type safe cast std::any_cast? Or is that not necessary here
There was a problem hiding this comment.
Yes, I think applying a similar change to transactions would be another good improvement. I'll leave that to another PR though.
| { | ||
| // FIXME Don't convert via lmdb::db_val, this is just a placeholder | ||
| auto const & data = *iter; | ||
| lmdb::db_val key_val{ MDB_val{ data.first.size (), const_cast<void *> (reinterpret_cast<void const *> (data.first.data ())) } }; |
There was a problem hiding this comment.
Well, if it works it works 😆
4bfdbee to
8b097a3
Compare
8b097a3 to
37f4f5c
Compare
This converts the store iterators from version that use polymorphism to using std::variant.
The primary drivers for this change is to simplify and allow more complex iterators to be created where this was previously fairly difficult to do.
The iterators are separated in the 3 parts:
The iterators are bi-directional with a sentinel value to signify end of iteration. The iterators are also circular so after reaching the end-sentinel value, further incrementing will wrap around to the beginning, or decrementing will position the iterator at the last key/value.
Using std::variant also eliminates heap allocations when constructing iterators which can improve performance in some circumstances.