Browse Source

Make DBI flags Python numbers; slightly simplify append operation.

Stefano Cossu 5 years ago
parent
commit
3240bed02e

+ 4 - 23
lakesuperior/store/ldp_rs/lmdb_triplestore.pxd

@@ -1,5 +1,3 @@
-import sys
-
 cimport lakesuperior.cy_include.collections as cc
 cimport lakesuperior.cy_include.cylmdb as lmdb
 cimport lakesuperior.cy_include.cytpl as tpl
@@ -11,31 +9,14 @@ from lakesuperior.model.graph.graph cimport SimpleGraph
 from lakesuperior.model.structures.keyset cimport Keyset
 from lakesuperior.store.base_lmdb_store cimport BaseLmdbStore
 
-# Integer keys and values are stored in the system's native byte order.
-# Therefore they must be parsed left-to-right if the system is big-endian,
-# and right-to-left if little-endian, in order to maintain the correct
-# sorting order.
-cdef bint BIG_ENDIAN = sys.byteorder == 'big'
-cdef unsigned int LSUP_REVERSEKEY = 0 if BIG_ENDIAN else lmdb.MDB_REVERSEKEY
-cdef unsigned int LSUP_REVERSEDUP = 0 if BIG_ENDIAN else lmdb.MDB_REVERSEDUP
-
-
-cdef enum:
-    IDX_OP_ADD = 1
-    IDX_OP_REMOVE = -1
-
 cdef:
+    enum:
+        IDX_OP_ADD = 1
+        IDX_OP_REMOVE = -1
+
     unsigned char lookup_rank[3]
     unsigned char lookup_ordering[3][3]
     unsigned char lookup_ordering_2bound[3][3]
-    unsigned int INT_KEY_MASK = (
-        lmdb.MDB_DUPSORT | lmdb.MDB_DUPFIXED | lmdb.MDB_INTEGERKEY
-        | LSUP_REVERSEKEY
-    )
-    unsigned int INT_DUP_MASK = (
-        lmdb.MDB_DUPSORT | lmdb.MDB_DUPFIXED | lmdb.MDB_INTEGERDUP
-        | LSUP_REVERSEDUP
-    )
 
 
 

+ 26 - 7
lakesuperior/store/ldp_rs/lmdb_triplestore.pyx

@@ -1,4 +1,5 @@
 import logging
+import sys
 
 from cython.parallel import prange
 from rdflib import Graph
@@ -33,6 +34,23 @@ from lakesuperior.model.structures.hash cimport (
         HLEN_128 as HLEN, Hash128, hash128)
 
 
+# Integer keys and values are stored in the system's native byte order.
+# Therefore they must be parsed left-to-right if the system is big-endian,
+# and right-to-left if little-endian, in order to maintain the correct
+# sorting order.
+BIG_ENDIAN = sys.byteorder == 'big'
+LSUP_REVERSEKEY = 0 if BIG_ENDIAN else lmdb.MDB_REVERSEKEY
+LSUP_REVERSEDUP = 0 if BIG_ENDIAN else lmdb.MDB_REVERSEDUP
+
+INT_KEY_MASK = lmdb.MDB_INTEGERKEY | LSUP_REVERSEKEY
+INT_DUP_KEY_MASK = (
+    lmdb.MDB_DUPSORT | lmdb.MDB_DUPFIXED | lmdb.MDB_INTEGERKEY
+    | LSUP_REVERSEKEY | LSUP_REVERSEDUP
+)
+INT_DUP_MASK = (
+    lmdb.MDB_DUPSORT | lmdb.MDB_DUPFIXED | lmdb.MDB_INTEGERDUP
+    | LSUP_REVERSEKEY | LSUP_REVERSEDUP
+)
 
 lookup_rank = [0, 2, 1]
 """
@@ -110,16 +128,18 @@ cdef class LmdbTriplestore(BaseLmdbStore):
     ]
 
     dbi_flags = {
-        'c': lmdb.MDB_INTEGERKEY,
-        's:po': INT_KEY_MASK,
-        'p:so': INT_KEY_MASK,
-        'o:sp': INT_KEY_MASK,
+        'c': INT_KEY_MASK,
+        't:st': INT_KEY_MASK,
+        's:po': INT_DUP_KEY_MASK,
+        'p:so': INT_DUP_KEY_MASK,
+        'o:sp': INT_DUP_KEY_MASK,
         'po:s': INT_DUP_MASK,
         'so:p': INT_DUP_MASK,
         'sp:o': INT_DUP_MASK,
-        'c:spo': INT_KEY_MASK,
+        'c:spo': INT_DUP_KEY_MASK,
         'spo:c': INT_DUP_MASK,
     }
+    logger.info(f'DBI flags: {dbi_flags}')
 
     flags = 0
 
@@ -1523,8 +1543,7 @@ cdef class LmdbTriplestore(BaseLmdbStore):
         except KeyNotFoundError:
             new_idx = 0
         else:
-            new_idx = (<Key>key_v.mv_data)[0]
-            new_idx += 1
+            new_idx = (<Key>key_v.mv_data)[0] + 1
         finally:
             #pass
             self._cur_close(cur)