Commit 98ebc5d4 authored by siddontang's avatar siddontang

support writebatch is_empty

parent 10d6c7f0
...@@ -964,6 +964,10 @@ impl WriteBatch { ...@@ -964,6 +964,10 @@ impl WriteBatch {
pub fn count(&self) -> usize { pub fn count(&self) -> usize {
unsafe { rocksdb_ffi::rocksdb_writebatch_count(self.inner) as usize } unsafe { rocksdb_ffi::rocksdb_writebatch_count(self.inner) as usize }
} }
pub fn is_empty(&self) -> bool {
self.count() == 0
}
} }
impl Drop for WriteBatch { impl Drop for WriteBatch {
...@@ -1167,8 +1171,10 @@ mod test { ...@@ -1167,8 +1171,10 @@ mod test {
let batch = WriteBatch::new(); let batch = WriteBatch::new();
assert!(db.get(b"k1").unwrap().is_none()); assert!(db.get(b"k1").unwrap().is_none());
assert_eq!(batch.count(), 0); assert_eq!(batch.count(), 0);
assert!(batch.is_empty());
let _ = batch.put(b"k1", b"v1111"); let _ = batch.put(b"k1", b"v1111");
assert_eq!(batch.count(), 1); assert_eq!(batch.count(), 1);
assert!(!batch.is_empty());
assert!(db.get(b"k1").unwrap().is_none()); assert!(db.get(b"k1").unwrap().is_none());
let p = db.write(batch); let p = db.write(batch);
assert!(p.is_ok()); assert!(p.is_ok());
...@@ -1179,6 +1185,7 @@ mod test { ...@@ -1179,6 +1185,7 @@ mod test {
let batch = WriteBatch::new(); let batch = WriteBatch::new();
let _ = batch.delete(b"k1"); let _ = batch.delete(b"k1");
assert_eq!(batch.count(), 1); assert_eq!(batch.count(), 1);
assert!(!batch.is_empty());
let p = db.write(batch); let p = db.write(batch);
assert!(p.is_ok()); assert!(p.is_ok());
assert!(db.get(b"k1").unwrap().is_none()); assert!(db.get(b"k1").unwrap().is_none());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment