Leveldb Advanced

[Slice]

  The return value of the it->key() and it->value() is a simple structure that contains a length and a pointer to an external byte array. Returning a Slice is a cheaper alternative to returning a std::string since we do not need to copy potentially large keys and values. 

  C++ strings and null-terminated C-style strings can be easily converted to a Slice:

  Leveldb Advanced

  A Slice can be easily converted back to a C++ string:

  Leveldb Advanced

  Be careful when using Slices since it is up to the caller to ensure that the external byte array into which the Slice points remains live while the Slice is in use. For example, the following is buggy:

  Leveldb Advanced

[Comparators]

  The default ordering function for key, which orders bytes lexicographically. You can however supply a custom comparator when opening a database. For example, suppose each database key consists of two numbers and we should sort by the first number, breaking ties by the second number. First, define a proper subclass ofleveldb::Comparator that expresses these rules:

  Leveldb Advanced

  Now create a database using this custom comparator:

  Leveldb Advanced

[Filters]

  

链接: http://leveldb.googlecode.com/svn/trunk/doc/index.html

Leveldb Advanced

上一篇:利用 __FUNCTION__ 宏打印函数调用信息


下一篇:SQL Server 批量备份数据库(主分区)