Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integer values in leveldb

I would like to use leveldb to store integers and integer arrays efficiently, in both c++ and python.

For integers in C++, i could convert the int to a char array. Any suggestions for storing the int array in c++ and int and int array in python?

like image 359
Ash Avatar asked Jun 04 '26 10:06

Ash


1 Answers

You could consider using a library like Google's protobuf (http://code.google.com/p/protobuf/) which is capable of (de)serializing structured data. For the case you mention, a repeated field would do the trick:

message List {
  repeated int64 val = 1;
}

Given the varint encoding used by protocol buffers (and depending on your range of values) this could be an efficient way to store the integers.

http://code.google.com/apis/protocolbuffers/docs/encoding.html#varints

It is tough to say more without knowing a bit more about your use case. How many integers are going to be stored per array on average? What is the range of integer values? etc.

like image 165
ahochhaus Avatar answered Jun 06 '26 00:06

ahochhaus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!