本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.4KB

  1. // Copyright (c) 2014 Couchbase, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package store
  15. type op struct {
  16. K []byte
  17. V []byte
  18. }
  19. type EmulatedBatch struct {
  20. Ops []*op
  21. Merger *EmulatedMerge
  22. }
  23. func NewEmulatedBatch(mo MergeOperator) *EmulatedBatch {
  24. return &EmulatedBatch{
  25. Ops: make([]*op, 0, 1000),
  26. Merger: NewEmulatedMerge(mo),
  27. }
  28. }
  29. func (b *EmulatedBatch) Set(key, val []byte) {
  30. ck := make([]byte, len(key))
  31. copy(ck, key)
  32. cv := make([]byte, len(val))
  33. copy(cv, val)
  34. b.Ops = append(b.Ops, &op{ck, cv})
  35. }
  36. func (b *EmulatedBatch) Delete(key []byte) {
  37. ck := make([]byte, len(key))
  38. copy(ck, key)
  39. b.Ops = append(b.Ops, &op{ck, nil})
  40. }
  41. func (b *EmulatedBatch) Merge(key, val []byte) {
  42. ck := make([]byte, len(key))
  43. copy(ck, key)
  44. cv := make([]byte, len(val))
  45. copy(cv, val)
  46. b.Merger.Merge(key, val)
  47. }
  48. func (b *EmulatedBatch) Reset() {
  49. b.Ops = b.Ops[:0]
  50. }
  51. func (b *EmulatedBatch) Close() error {
  52. return nil
  53. }
上海开阖软件有限公司 沪ICP备12045867号-1