作者: 韩晨旭 10225101440 李畅 10225102463
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

91 linhas
3.2 KiB

  1. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. //
  5. // TableBuilder provides the interface used to build a Table
  6. // (an immutable and sorted map from keys to values).
  7. //
  8. // Multiple threads can invoke const methods on a TableBuilder without
  9. // external synchronization, but if any of the threads may call a
  10. // non-const method, all threads accessing the same TableBuilder must use
  11. // external synchronization.
  12. #ifndef STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_
  13. #define STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_
  14. #include <stdint.h>
  15. #include "leveldb/options.h"
  16. #include "leveldb/status.h"
  17. namespace leveldb {
  18. class BlockBuilder;
  19. class BlockHandle;
  20. class WritableFile;
  21. class TableBuilder {
  22. public:
  23. // Create a builder that will store the contents of the table it is
  24. // building in *file. Does not close the file. It is up to the
  25. // caller to close the file after calling Finish().
  26. TableBuilder(const Options& options, WritableFile* file);
  27. // REQUIRES: Either Finish() or Abandon() has been called.
  28. ~TableBuilder();
  29. // Change the options used by this builder. Note: only some of the
  30. // option fields can be changed after construction. If a field is
  31. // not allowed to change dynamically and its value in the structure
  32. // passed to the constructor is different from its value in the
  33. // structure passed to this method, this method will return an error
  34. // without changing any fields.
  35. Status ChangeOptions(const Options& options);
  36. // Add key,value to the table being constructed.
  37. // REQUIRES: key is after any previously added key according to comparator.
  38. // REQUIRES: Finish(), Abandon() have not been called
  39. void Add(const Slice& key, const Slice& value);
  40. // Advanced operation: flush any buffered key/value pairs to file.
  41. // Can be used to ensure that two adjacent entries never live in
  42. // the same data block. Most clients should not need to use this method.
  43. // REQUIRES: Finish(), Abandon() have not been called
  44. void Flush();
  45. // Return non-ok iff some error has been detected.
  46. Status status() const;
  47. // Finish building the table. Stops using the file passed to the
  48. // constructor after this function returns.
  49. // REQUIRES: Finish(), Abandon() have not been called
  50. Status Finish();
  51. // Indicate that the contents of this builder should be abandoned. Stops
  52. // using the file passed to the constructor after this function returns.
  53. // If the caller is not going to call Finish(), it must call Abandon()
  54. // before destroying this builder.
  55. // REQUIRES: Finish(), Abandon() have not been called
  56. void Abandon();
  57. // Number of calls to Add() so far.
  58. uint64_t NumEntries() const;
  59. // Size of the file generated so far. If invoked after a successful
  60. // Finish() call, returns the size of the final generated file.
  61. uint64_t FileSize() const;
  62. private:
  63. bool ok() const { return status().ok(); }
  64. void WriteBlock(BlockBuilder* block, BlockHandle* handle);
  65. struct Rep;
  66. Rep* rep_;
  67. // No copying allowed
  68. TableBuilder(const TableBuilder&);
  69. void operator=(const TableBuilder&);
  70. };
  71. }
  72. #endif // STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_