mina_tree/ondisk/
batch.rs1use super::{Key, Value};
2
3pub(super) enum Action {
4 Set(Key, Value),
5 Remove(Key),
6}
7
8pub struct Batch {
9 actions: Vec<Action>,
10}
11
12impl Default for Batch {
13 fn default() -> Self {
14 Self::new()
15 }
16}
17
18impl Batch {
19 pub fn new() -> Self {
20 Self {
21 actions: Vec::with_capacity(32),
22 }
23 }
24
25 pub fn set(&mut self, key: Key, value: Value) {
26 self.actions.push(Action::Set(key, value));
27 }
28
29 pub fn remove(&mut self, key: Key) {
30 self.actions.push(Action::Remove(key));
31 }
32
33 pub(super) fn take(&mut self) -> Vec<Action> {
34 std::mem::take(&mut self.actions)
35 }
36}