Is it possible to store whole keys / values ​​in LevelDB?

I searched for key value stores that support integer keys and integer values. LevelDB seems like a good option, although I cannot find information on whether integer values ​​/ keys are supported

+5
source share
4 answers

You can store almost everything in LevelDB. You provide opaque pieces of data to LevelDB through a structure Slice. 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 is pretty much!

, , LevelDB ( , ) BytewiseComparator, . , , , .

Comparator, BytewiseComparator.

+10

. int char * ( ) ; varint- - ( , ).

+1

, , , , , BytewiseComparator, .

- , . . long flippedI = htonl(i);

, LevelDB . iPhone4 50 000 , 100 000 / .

, - ByteWiseComparator , . , , .

, 4 , , 4- . , - , . , , . .

int, 1 1 1000, BytewiseComparator

Listing the keys in decimal and hex
 256 ( 100)
 512 ( 200)
 768 ( 300)
   1 (   1)
 257 ( 101)
 513 ( 201)
 769 ( 301)
   2 (   2)
 258 ( 102)
 514 ( 202)
 770 ( 302)
   3 (   3)
 259 ( 103)
 515 ( 203)
 771 ( 303)
...
 254 (  fe)
 510 ( 1fe)
 766 ( 2fe)
 255 (  ff)
 511 ( 1ff)
 767 ( 2ff)
0

LMDB ( , ). http://symas.com/mdb

DB , , , , .

: LMDB. , .

0

All Articles