-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwrite_batch.go
49 lines (42 loc) · 1.21 KB
/
write_batch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package lm2
// WriteBatch represents a set of modifications.
type WriteBatch struct {
sets map[string]string
deletes map[string]struct{}
allowOverwrite bool
secureDelete bool
}
// NewWriteBatch returns a new WriteBatch.
func NewWriteBatch() *WriteBatch {
return &WriteBatch{
sets: map[string]string{},
deletes: map[string]struct{}{},
allowOverwrite: true,
}
}
// Set adds key => value to the WriteBatch.
// Note: If a key is passed to Delete and Set,
// then the Set will be ignored.
func (wb *WriteBatch) Set(key, value string) {
wb.sets[key] = value
}
// Delete marks a key for deletion.
func (wb *WriteBatch) Delete(key string) {
wb.deletes[key] = struct{}{}
}
// AllowOverwrite determines whether keys will be overwritten.
// If allow is false and an existing key is being
// set, updates will be rolled back.
func (wb *WriteBatch) AllowOverwrite(allow bool) {
wb.allowOverwrite = allow
}
// SetSecureDelete determines whether record values are cleared with zero
// bytes when deleted.
func (wb *WriteBatch) SetSecureDelete(secureDelete bool) {
wb.secureDelete = secureDelete
}
func (wb *WriteBatch) cleanup() {
for key := range wb.deletes {
delete(wb.sets, key)
}
}