2017-04-25 13:33:42 +02:00
|
|
|
import struct as py_struct
|
2018-02-09 06:37:09 +01:00
|
|
|
from rocksdb.interfaces import AssociativeMergeOperator
|
2017-04-25 13:33:42 +02:00
|
|
|
|
|
|
|
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:
|
2018-11-02 19:27:14 +01:00
|
|
|
s = existing_value + b',' + value
|
2017-04-25 13:33:42 +02:00
|
|
|
return (True, s)
|
|
|
|
return (True, value)
|
|
|
|
|
|
|
|
def name(self):
|
|
|
|
return b'StringAppendOperator'
|