首页 > 数据库技术 > 详细

Leveldb Advanced

时间:2014-01-28 20:43:14      阅读:461      评论:0      收藏:0      [点我收藏+]

[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:

  bubuko.com,布布扣

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

  bubuko.com,布布扣

  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:

  bubuko.com,布布扣

[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:

  bubuko.com,布布扣

  Now create a database using this custom comparator:

  bubuko.com,布布扣

[Filters]

  

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

Leveldb Advanced

原文:http://www.cnblogs.com/tekkaman/p/3535615.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!