Whole file

kmike/DAWG-Python

The author described this change as bug with empty dawgs is fixed. It counts as a record because the check below fails on the code as it stood at f505de91f and passes on 5abda1b18, with nothing else changed between the two runs.

Fix saved2012-10-01
Sharing licenceMIT · LICENSE
Change size+10 2

What the code was meant to do, written into the code itself as a save note

bug with empty dawgs is fixed

The change

9292 base_size = struct.unpack(str("=I"), fp.read(4))[0]
9393 self._units = bytearray(fp.read(base_size*2))
9494
95+ def size(self):
96+ return len(self._units) if self._units is not None else 0
9597
98+
9699 class Completer(object):
97100
98101 def __init__(self, dic=None, guide=None):
104107
105108 def start(self, index, prefix=b""):
106109 self.key = bytearray(prefix)
107- self._index_stack = [index]
108- self._last_index = self._dic.root()
110+
111+ if self._guide.size():
112+ self._index_stack = [index]
113+ self._last_index = self._dic.root()
114+ else:
115+ self._index_stack = []
116+
109117
110118 def next(self):
111119 "Gets the next key"

The check that tells the two apart

failpass·tests/test_dawg.py::TestCompletionDAWG::test_empty_dawg

Check file tests/test_dawg.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itf505de91f33d491e46c36d8c96889ebc413de9c4
Broken version dated2012-09-26
Moduledawg_python.wrapper
Units changedCompleter, Guide
Fingerprintddf208060b5f2b66
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.