File: merge_operators.py

package info (click to toggle)
python-rocksdb 0.8.0~rc3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 480 kB
  • sloc: python: 798; cpp: 408; makefile: 158
file content (22 lines) | stat: -rw-r--r-- 723 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import struct as py_struct
from rocksdb.interfaces import AssociativeMergeOperator

class UintAddOperator(AssociativeMergeOperator):
    def merge(self, key, existing_value, value):
        if existing_value:
            s = py_struct.unpack('Q', existing_value)[0] + py_struct.unpack('Q', value)[0]
            return (True, py_struct.pack('Q', s))
        return (True, value)

    def name(self):
        return b'uint64add'

class StringAppendOperator(AssociativeMergeOperator):
    def merge(self, key, existing_value, value):
        if existing_value:
            s = existing_value + b',' + value
            return (True, s)
        return (True, value)

    def name(self):
        return b'StringAppendOperator'