Browse Source

Minor tweaks.

Stefano Cossu 6 years ago
parent
commit
64f6476173

+ 2 - 2
lakesuperior/endpoints/ldp.py

@@ -179,7 +179,7 @@ def get_resource(uid, out_fmt=None):
         out_headers.update(_headers_from_metadata(rsrc, out_fmt))
         out_headers.update(_headers_from_metadata(rsrc, out_fmt))
         uri = g.tbox.uid_to_uri(uid)
         uri = g.tbox.uid_to_uri(uid)
 
 
-# RDF output.
+        # RDF output.
         if out_fmt == 'rdf':
         if out_fmt == 'rdf':
             if locals().get('rdf_mimetype', None) is None:
             if locals().get('rdf_mimetype', None) is None:
                 rdf_mimetype = DEFAULT_RDF_MIMETYPE
                 rdf_mimetype = DEFAULT_RDF_MIMETYPE
@@ -188,7 +188,7 @@ def get_resource(uid, out_fmt=None):
             return _negotiate_content(
             return _negotiate_content(
                     ggr, rdf_mimetype, out_headers, uid=uid, uri=uri)
                     ggr, rdf_mimetype, out_headers, uid=uid, uri=uri)
 
 
-# Datastream.
+        # Datastream.
         else:
         else:
             if not getattr(rsrc, 'local_path', False):
             if not getattr(rsrc, 'local_path', False):
                 return ('{} has no binary content.'.format(rsrc.uid), 404)
                 return ('{} has no binary content.'.format(rsrc.uid), 404)

+ 2 - 2
lakesuperior/model/structures/keyset.pxd

@@ -22,9 +22,9 @@ cdef class Keyset:
         size_t size(self)
         size_t size(self)
         size_t tell(self)
         size_t tell(self)
         bint get_next(self, TripleKey* item)
         bint get_next(self, TripleKey* item)
-        void add(self, const TripleKey* val, bint check_dup=*) except *
+        int add(self, const TripleKey* val, bint check_dup=*, bint check_cap=*) except -1
         void remove(self, const TripleKey* val) except *
         void remove(self, const TripleKey* val) except *
-        bint contains(self, const TripleKey* val) nogil
+        bint contains(self, const TripleKey* val)
         Keyset copy(self)
         Keyset copy(self)
         Keyset sparse_copy(self)
         Keyset sparse_copy(self)
         void resize(self, size_t size=*) except *
         void resize(self, size_t size=*) except *

+ 11 - 7
lakesuperior/model/structures/keyset.pyx

@@ -26,7 +26,7 @@ cdef class Keyset:
     data block, so e.g. bulk removal and intersection are much more efficient
     data block, so e.g. bulk removal and intersection are much more efficient
     than individual record operations.
     than individual record operations.
     """
     """
-    def __cinit__(self, size_t capacity=0, expand_ratio=.5):
+    def __cinit__(self, size_t capacity=0, expand_ratio=.75):
         """
         """
         Initialize and allocate memory for the data set.
         Initialize and allocate memory for the data set.
 
 
@@ -98,15 +98,18 @@ cdef class Keyset:
         return True
         return True
 
 
 
 
-    cdef void add(self, const TripleKey* val, bint check_dup=False) except *:
+    cdef inline int add(
+            self, const TripleKey* val, bint check_dup=False,
+            bint check_cap=True
+    ) except -1:
         """
         """
         Add a triple key to the array.
         Add a triple key to the array.
         """
         """
         # Check for deleted triples and optionally duplicates.
         # Check for deleted triples and optionally duplicates.
-        if val[0] == NULL_TRP or (check_dup and self.contains(val)):
-            return
+        if check_dup and self.contains(val):
+            return 1
 
 
-        if self.free_i >= self.capacity:
+        if check_cap and self.free_i >= self.capacity:
             if self.expand_ratio > 0:
             if self.expand_ratio > 0:
                 # In some edge casees, a very small ratio may round down to a
                 # In some edge casees, a very small ratio may round down to a
                 # zero increase, so the baseline increase is 1 element.
                 # zero increase, so the baseline increase is 1 element.
@@ -115,9 +118,10 @@ cdef class Keyset:
                 raise MemoryError('No space left in key set.')
                 raise MemoryError('No space left in key set.')
 
 
         self.data[self.free_i] = val[0]
         self.data[self.free_i] = val[0]
-
         self.free_i += 1
         self.free_i += 1
 
 
+        return 0
+
 
 
     cdef void remove(self, const TripleKey* val) except *:
     cdef void remove(self, const TripleKey* val) except *:
         """
         """
@@ -138,7 +142,7 @@ cdef class Keyset:
                 return
                 return
 
 
 
 
-    cdef bint contains(self, const TripleKey* val) nogil:
+    cdef bint contains(self, const TripleKey* val):
         """
         """
         Whether a value exists in the set.
         Whether a value exists in the set.
         """
         """