[Leveldb Source Analysis question]-block_builder.cc's add function

Source: Internet
Author: User
Tags assert

The Add function is to add the corresponding key and value to a data block, the function source code is as follows, one of which does not understand:

L30~L34 is updated last_key_, do not understand here why not directly last_key_ = key. ToString ();

Written

Update State
Last_key_.resize (shared);
Last_key_.append (Key.data () + GKFX, non_shared);
ASSERT (Slice (last_key_) = = key);

Is there any other reason?

1 voidBlockbuilder::add (Constslice& Key,Constslice&value) {2 Slice last_key_piece (LAST_KEY_);3ASSERT (!finished_);4ASSERT (Counter_ <= options_->block_restart_interval);5ASSERT (Buffer_.empty ()//No values yet?6|| Options_->comparator->compare (Key, last_key_piece) >0);7size_t shared =0;8   if(Counter_ < options_->block_restart_interval) {9     //See how much sharing to does with previous stringTen     Constsize_t min_length =std::min (Last_key_piece.size (), key.size ()); One      while(Shared < Min_length) && (last_key_piece[shared] = =key[shared])) { Ashared++; -     } -}Else { the     //Restart Compression - Restarts_.push_back (Buffer_.size ()); -Counter_ =0; -   } +   Constsize_t non_shared = key.size ()-Gkfx; -  +   //Add "<shared><non_shared><value_size>" to Buffer_ APutVarint32 (&Buffer_, GKFX); atPutVarint32 (&Buffer_, non_shared); -PutVarint32 (&Buffer_, Value.size ()); -  -   //Add string Delta to Buffer_ followed by value -Buffer_.append (Key.data () +gkfx, non_shared); - Buffer_.append (Value.data (), value.size ()); in  -   //Update State to last_key_.resize (shared); +Last_key_.append (Key.data () +gkfx, non_shared); -ASSERT (Slice (last_key_) = =key); thecounter_++; *}

[Leveldb Source Analysis question]-block_builder.cc's add function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.