Jesse Dhillon avatar Jesse Dhillon committed 57a0f8c Draft

Added support for inserting set-type keys into indexes.

Comments (0)

Files changed (2)

CodernityDB/database.py

             should_index = None
         if should_index:
             key, value = should_index
+            if not isinstance(key, set):
+                key = set([key])
+
             if value:
                 storage = index.storage
                 start, size = storage.insert(value)
             else:
                 start = 1
                 size = 0
-            index.insert(doc_id, key, start, size)
+
+            for k in key:
+                index.insert(doc_id, k, start, size)
 
     def _insert_id_index(self, _rev, data):
         """

CodernityDB/hash_index.py

                 break
             else:
                 if status != 'd':
-                    if l_key == key:  # in case of hash function conflicts
+                    if self.compare_keys(l_key, key):  # in case of hash function conflicts
                         yield doc_id, start, size, status
                         limit -= 1
                 location = _next
 
+    def compare_keys(self, a, b):
+        return a == b
+
     def _calculate_position(self, key):
         return abs(hash(key) & self.hash_lim) * self.bucket_line_size + self._start_ind
 
             except struct.error:
                 raise ElemNotFound(
                     "Not found")  # not found but might be also broken
-            if l_key == key:
+            if self.compare_keys(l_key, key):
                 break
             else:
                 if not _next:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.