| 215 | : Constructor(cmp), source_(nullptr), table_(nullptr) {} |
| 216 | ~TableConstructor() override { Reset(); } |
| 217 | Status FinishImpl(const Options& options, const KVMap& data) override { |
| 218 | Reset(); |
| 219 | StringSink sink; |
| 220 | TableBuilder builder(options, &sink); |
| 221 | |
| 222 | for (const auto& kvp : data) { |
| 223 | builder.Add(kvp.first, kvp.second); |
| 224 | ASSERT_TRUE(builder.status().ok()); |
| 225 | } |
| 226 | Status s = builder.Finish(); |
| 227 | ASSERT_TRUE(s.ok()) << s.ToString(); |
| 228 | |
| 229 | ASSERT_EQ(sink.contents().size(), builder.FileSize()); |
| 230 | |
| 231 | // Open the table |
| 232 | source_ = new StringSource(sink.contents()); |
| 233 | Options table_options; |
| 234 | table_options.comparator = options.comparator; |
| 235 | return Table::Open(table_options, source_, sink.contents().size(), &table_); |
| 236 | } |
| 237 | |
| 238 | Iterator* NewIterator() const override { |
| 239 | return table_->NewIterator(ReadOptions()); |