| 92 | } |
| 93 | |
| 94 | void TableBuilder::Add(const Slice& key, const Slice& value) { |
| 95 | Rep* r = rep_; |
| 96 | assert(!r->closed); |
| 97 | if (!ok()) return; |
| 98 | if (r->num_entries > 0) { |
| 99 | assert(r->options.comparator->Compare(key, Slice(r->last_key)) > 0); |
| 100 | } |
| 101 | |
| 102 | if (r->pending_index_entry) { |
| 103 | assert(r->data_block.empty()); |
| 104 | r->options.comparator->FindShortestSeparator(&r->last_key, key); |
| 105 | std::string handle_encoding; |
| 106 | r->pending_handle.EncodeTo(&handle_encoding); |
| 107 | r->index_block.Add(r->last_key, Slice(handle_encoding)); |
| 108 | r->pending_index_entry = false; |
| 109 | } |
| 110 | |
| 111 | if (r->filter_block != nullptr) { |
| 112 | r->filter_block->AddKey(key); |
| 113 | } |
| 114 | |
| 115 | r->last_key.assign(key.data(), key.size()); |
| 116 | r->num_entries++; |
| 117 | r->data_block.Add(key, value); |
| 118 | |
| 119 | const size_t estimated_block_size = r->data_block.CurrentSizeEstimate(); |
| 120 | if (estimated_block_size >= r->options.block_size) { |
| 121 | Flush(); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | void TableBuilder::Flush() { |
| 126 | Rep* r = rep_; |
no test coverage detected