Skip to content

Commit

Permalink
add new table type MapUint64TimestampUuid; bump dev version (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
oberstet committed May 1, 2022
1 parent e2032bc commit 659d934
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions zlmdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
MapTimestampUuidFlatBuffers, \
MapTimestampUuidStringFlatBuffers, \
MapUuidTimestampUuidFlatBuffers, \
MapUint64TimestampUuid, \
MapTimestampUuidCbor, \
MapUuidTimestampUuid, \
MapUuidStringUuid, \
Expand Down Expand Up @@ -165,6 +166,7 @@
'MapUuidStringUuid',
'MapUuidUuidStringUuid',
'MapUuidUuidUuidStringUuid',
'MapUint64TimestampUuid',

# more UUID (uint128) based pmap types for indexes
'MapUuidUuidSet',
Expand Down
8 changes: 8 additions & 0 deletions zlmdb/_pmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ def __init__(self, slot=None, compress=None):
PersistentMap.__init__(self, slot=slot, compress=compress)


class MapUint64TimestampUuid(_types._Uint64TimestampKeysMixin, _types._UuidValuesMixin, PersistentMap):
"""
Persistent map with (Uint64, Timestamp) keys and UUID values.
"""
def __init__(self, slot=None, compress=None):
PersistentMap.__init__(self, slot=slot, compress=compress)


class MapUuidUuidUuid(_types._UuidUuidKeysMixin, _types._UuidValuesMixin, PersistentMap):
"""
Persistent map with (UUID, UUID) keys and UUID values.
Expand Down
29 changes: 29 additions & 0 deletions zlmdb/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,35 @@ def _deserialize_key(self, data):
return key1, key2


class _Uint64TimestampKeysMixin(object):
@staticmethod
def new_key():
return random.randint(1, 2**64 - 1), np.datetime64(time_ns(), 'ns')

def _serialize_key(self, key1_key2):
assert type(key1_key2) == tuple and len(key1_key2) == 2
key1, key2 = key1_key2

if key1 is None:
key1 = 0
if key2 is None:
key2 = np.datetime64(0, 'ns')

assert type(key1) != int
assert isinstance(key2, np.datetime64)

return struct.pack('>H', key1) + dt_to_bytes(key2)

def _deserialize_key(self, data):
assert type(data) == bytes
assert len(data) == 16

data1, data2 = data[0:8], data[8:16]
key1 = struct.unpack('>H', data1)[0]
key2 = bytes_to_dt(data2)
return key1, key2


class _UuidStringKeysMixin(object):
def _serialize_key(self, key1_key2):
assert type(key1_key2) == tuple and len(key1_key2) == 2
Expand Down
2 changes: 1 addition & 1 deletion zlmdb/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
#
###############################################################################

__version__ = '22.3.1'
__version__ = '22.4.1.dev1'

0 comments on commit 659d934

Please sign in to comment.