MDB_INTEGERKEY usage
See original GitHub issueHi,
I’m trying to use ints as keys. As such, I assumed that MDB_INTEGERKEY
is the most efficient way to proceed. Unfortunately, I’m getting some keys “out of order”. I say that with quotations because it seems like LMDB is probably doing the correct thing, being the highly used and tested library that it is. This is likely a case of user error, in which case guidance would be much appreciated, or something funky with lmdbjava <-> lmdb. My first guess is that there is something funky going on with the byte ordering.
The int keys 0-255 seem to be in order, but when I transition to 256, it comes before 255.
Here are the relevant details to reproduce: https://gist.github.com/devinrsmith/ccb12bb1cb81dfc88e8f72e60cfb5666
Thanks.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
integer keys / Map encoding · Issue #63 · mcollina/msgpack5
Is there a way to force keys in a javascript object to be numbers when msgpack encoding is done? javascript Map allows to...
Read more >3.4 Hash Tables - Algorithms, 4th Edition
The hash function that we use uniformly distributes keys among the integer values between 0 and M-1. Hashing with separate chaining. A hash...
Read more >RFC 3279: Algorithms and Identifiers for the Internet X.509 ...
1 encoded as an INTEGER; this encoding shall be used as the contents (i.e., the value) of the subjectPublicKey component (a BIT STRING)...
Read more >Expressions, variables, and types - Roku Developer
Only when both operands are integers will a result be integer. Division follows the same rules as +, * and -, except that...
Read more >NIST.SP.800-56Br2.pdf
NIST Special Publication 800-56B. Revision 2. Recommendation for Pair-Wise. Key Establishment Using Integer. Factorization Cryptography.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The main challenge is LmdbJava’s API tries to be buffer implementation agnostic and the various buffer implementations have distinct methods or idioms to get/set values by byte order. For example
ByteBuffer
has theorder
method,byte[]
has no inbuilt byte order awareness at all, Agrona’sDirectBuffer
offers accessor methods with a byte order argument etc. As such most of the buffers don’t even have a buffer-wide byte order method we could conveniently call.We could change our
BufferProxy.allocate()
toBufferProxy.allocate(ByteOrder)
and acceptnull
to mean “don’t change it”, but I wonder if the complexity of the correspondingEnv.Builder<T>.setDefaultOrder(ByteOrder)
would be confusing for users where we cannot set the order anyway. It also seems undesirably asymmetric given users have to set byte orders on the put-time buffers anyway. /cc @krisskross thoughts on this?The working solution is below. I added a character to the value to help prove it’s outputting in the correct order. The output is now:
As shown below with the
*** CHANGED ***
comments, you just needed to set the key’s byte order to native, and remember to set the byte order on the returnedCursor
buffer as well. This is necessary as LmdbJava does not have any opinion on which byte order your buffer used (eg a user who is writing a Java only application storing say string keys and integer values may rely on the Java Big Endian default, and would be surprised if the buffer was set to Little Endian behind the scenes on the returned buffer).The code:
Thanks for trying LmdbJava. I hope you find it useful.