Commit e340fdda authored by siddontang's avatar siddontang Committed by GitHub

Merge pull request #22 from siddontang/siddontang/writebatch-count

support writebatch count
parents 7de3c903 98ebc5d4
......@@ -960,6 +960,14 @@ impl WriteBatch {
pub fn new() -> WriteBatch {
WriteBatch::default()
}
pub fn count(&self) -> usize {
unsafe { rocksdb_ffi::rocksdb_writebatch_count(self.inner) as usize }
}
pub fn is_empty(&self) -> bool {
self.count() == 0
}
}
impl Drop for WriteBatch {
......@@ -1162,7 +1170,11 @@ mod test {
// test put
let batch = WriteBatch::new();
assert!(db.get(b"k1").unwrap().is_none());
assert_eq!(batch.count(), 0);
assert!(batch.is_empty());
let _ = batch.put(b"k1", b"v1111");
assert_eq!(batch.count(), 1);
assert!(!batch.is_empty());
assert!(db.get(b"k1").unwrap().is_none());
let p = db.write(batch);
assert!(p.is_ok());
......@@ -1172,6 +1184,8 @@ mod test {
// test delete
let batch = WriteBatch::new();
let _ = batch.delete(b"k1");
assert_eq!(batch.count(), 1);
assert!(!batch.is_empty());
let p = db.write(batch);
assert!(p.is_ok());
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