I have searched for key value stores that support integer keys and integer values. LevelDB seems a good option, though I can't find any information on whether integer values/keys are supported
You can store pretty much anything in LevelDB. You provide opaque slices of data into LevelDB via the Slice
structure. Here is an example:
int intKey = 256;
int intValue = 256*256;
Slice key((char*)&intKey, sizeof(int));
Slice value((char*)&intValue, sizeof(int));
db->Put(leveldb::WriteOptions(), key, value);
And that's pretty much it!
However, one thing to note is that while it's generally fine to store integers in LevelDB (as both keys and values), they will be order via the BytewiseComparator
so your key has to support bytewise comparison. This also means that if you rely on specific ordering of the keys, then you have to be mindful of the endian-ness on the system.
You can also write your own comparator via the Comparator
interface which will allow you to replace the default BytewiseComparator
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With