0
0
bleve/index/store/inmem/batch.go
Marty Schoch d48eee948e refactored index to separate out kv storage
now how pluggable options for
leveldb
gouchstore
in memory only
2014-05-09 16:37:04 -04:00

43 lines
726 B
Go

package inmem
type InMemBatch struct {
store *InMemStore
keys [][]byte
vals [][]byte
}
func newInMemBatch(store *InMemStore) *InMemBatch {
rv := InMemBatch{
store: store,
keys: make([][]byte, 0),
vals: make([][]byte, 0),
}
return &rv
}
func (i *InMemBatch) Set(key, val []byte) {
i.keys = append(i.keys, key)
i.vals = append(i.vals, val)
}
func (i *InMemBatch) Delete(key []byte) {
i.keys = append(i.keys, key)
i.vals = append(i.vals, nil)
}
func (i *InMemBatch) Execute() error {
for index, key := range i.keys {
val := i.vals[index]
if val == nil {
i.store.list.Delete(string(key))
} else {
i.store.Set(key, val)
}
}
return nil
}
func (i *InMemBatch) Close() error {
return nil
}