-
-
Notifications
You must be signed in to change notification settings - Fork 112
Can help implement MDBX_SET_UPPERBOUND
?
#250
Comments
MDBX_ SET_ UPPERBOUND
?MDBX_SET_UPPERBOUND
?
Unfortunately, I don't have time to do this right now. Please wait a few days. |
Thanks for the reply, I have tried to implement a version by myself, see pull request #251. I am not in a hurry. |
Please check it. |
I use test code output as the image above The left side of the screenshot is my code implementation output, and the right side of the screenshot is your code implementation output I just change c code from my implementation to your implementation I found that there are some inconsistencies with expectations Database Test
Database Test2
|
Semantic of the Semantic of |
I did not express myself accurately. What I need is not MDBX_SET_UPPERBOUND for example the database have value (3,0) (3,8) (9,0) and when I use key 10 , upper bound should be (9,0) |
This is wrong. |
sorry, I corrected my description What I need is not MDBX_SET_UPPERBOUND for example the database have value (3,0) (3,8) (9,0) and when I use key 10 , upper bound should be (9,0) |
Anyway you can and should implement any custom search operation by available cursor operations, the ones are enough for this (sure). Please study a theoretical basis to be known how do to that you need with currently available ops but without extra ones. |
C++ only has upper_bound and lower_bound but not upper_bound_rev and lower_bound_rev because it is easy to achieve this with the C++ interface via the reverse iterator. Find last element less than x: auto iter = std::upper_bound(v.rbegin(), v.rend(), x, std::greater<int>());
if(iter == v.rend())
std::cout<<"no found";
else
std::cout<<*iter; Find last element less than equal x: auto iter = std::lower_bound(v.rbegin(), v.rend(), x, std::greater<int>());
if(iter == v.rend())
std::cout<<"no found";
else
std::cout<<*iter; But the lower_bound interface of mdbx is different from the lower_bound interface of C++. Based on the existing lower_bound interface of mdbx, it is very troublesome to implement Find last element less than or equal x. For example, when the data entries in the database are (3,0), (3,1), (4,1), and lower_bound(10,empty), it will return not found. At this time, you need to locate mdbx_last by yourself. When lower_bound(3,empty), lower_bound will return (3,0) instead of (3,1) So, I think if there is a reverse lower_bound interface, it will be easier for the upper layer to implement reverse iteration. |
Historically (inherited from LMDB) libmdbx have Additionally libmdbx have the So as I answered earlier:
|
I'll use an integer key to illustrate.
I have implemented range (1..3) in rust, where the interval is open and closed, that is, contains 1, does not contain 3, and uses
MDBX_SET_LOWERBOUND
is easy to implement.Now, I want to implement range (3..1), which is an iterator from 3 to 1, with 3 and no 1.
But I find there is no
MDBX_ SET_ UPPERBOUND
, it is not easy to locate the first key less than or equal to 3 (also need to locate the last value of the key if it is DUPSORT).If want to do this in rust, of course can, but it's not elegant. There are many logic to process (for example, if the starting number is greater than all values, MDBX_SET_RANGE returns MDBX_NOTFOUND, which requires MDBX_LAST).
If there is an MDBX_SET_UPPERBOUND Everything will be simple
The text was updated successfully, but these errors were encountered: