diff options
Diffstat (limited to 'include/leveldb/write_batch.h')
-rw-r--r-- | include/leveldb/write_batch.h | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/include/leveldb/write_batch.h b/include/leveldb/write_batch.h index b6d72cb..94d4115 100644 --- a/include/leveldb/write_batch.h +++ b/include/leveldb/write_batch.h @@ -22,6 +22,7 @@ #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ #include <string> + #include "leveldb/export.h" #include "leveldb/status.h" @@ -31,11 +32,18 @@ class Slice; class LEVELDB_EXPORT WriteBatch { public: + class LEVELDB_EXPORT Handler { + public: + virtual ~Handler(); + virtual void Put(const Slice& key, const Slice& value) = 0; + virtual void Delete(const Slice& key) = 0; + }; + WriteBatch(); // Intentionally copyable. WriteBatch(const WriteBatch&) = default; - WriteBatch& operator =(const WriteBatch&) = default; + WriteBatch& operator=(const WriteBatch&) = default; ~WriteBatch(); @@ -52,15 +60,16 @@ class LEVELDB_EXPORT WriteBatch { // // This number is tied to implementation details, and may change across // releases. It is intended for LevelDB usage metrics. - size_t ApproximateSize(); + size_t ApproximateSize() const; + + // Copies the operations in "source" to this batch. + // + // This runs in O(source size) time. However, the constant factor is better + // than calling Iterate() over the source batch with a Handler that replicates + // the operations into this batch. + void Append(const WriteBatch& source); // Support for iterating over the contents of a batch. - class Handler { - public: - virtual ~Handler(); - virtual void Put(const Slice& key, const Slice& value) = 0; - virtual void Delete(const Slice& key) = 0; - }; Status Iterate(Handler* handler) const; private: |