Mikhail Korobov avatar Mikhail Korobov committed 21752ae

bug with empty dawgs is fixed

Comments (0)

Files changed (3)

dawg_python/wrapper.py

         base_size = struct.unpack(str("=I"), fp.read(4))[0]
         self._units = bytearray(fp.read(base_size*2))
 
+    def size(self):
+        return len(self._units) if self._units is not None else 0
+
 
 class Completer(object):
 
 
     def start(self, index, prefix=b""):
         self.key = bytearray(prefix)
-        self._index_stack = [index]
-        self._last_index = self._dic.root()
+
+        if self._guide.size():
+            self._index_stack = [index]
+            self._last_index = self._dic.root()
+        else:
+            self._index_stack = []
+
 
     def next(self):
         "Gets the next key"
Add a comment to this file

dev_data/small/completion-empty.dawg

Binary file added.

tests/test_dawg.py

         with pytest.raises(Exception) as e:
             d.load(path)
 
+    def test_empty_dawg(self):
+        d = dawg_python.CompletionDAWG().load(data_path('small', 'completion-empty.dawg'))
+        assert d.keys() == []
+
     def test_prefixes(self):
         d = self.dawg()
         assert d.prefixes("foobarz") == ["f", "foo", "foobar"]
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.