One function

PrefixSet in mina86/pygtrie

The author described this change as Fix prefixes not pruning long keys in PrefixSet.__init__. It counts as a record because the check below fails on the code as it stood at 2404a55e0 and passes on 15c095593, with nothing else changed between the two runs.

Fix saved2019-07-17
Sharing licenceApache-2.0 · LICENSE
Change size+3 3

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

A set of prefixes. :class:`pygtrie.PrefixSet` works similar to a normal set except it is said to contain a key if the key or it's prefix is stored in the set. For instance, if "foo" is added to the set, the set contains "foo" as well as "foobar". The set supports addition of elements but does *not* support removal of elements. This is because there's no obvious consistent and intuitive behaviour for element deletion.

The change

2020 :class:`pygtrie.PrefixSet`.
2121 kwargs: Additional keyword arguments passed to the factory function.
2222 """
23- trie = factory(**kwargs)
23+ super(PrefixSet, self).__init__()
24+ self._trie = factory(**kwargs)
2425 for key in iterable:
25- trie[key:] = True
26- self._trie = trie
26+ self.add(key)
2727
2828 def copy(self):
2929 """Returns a copy of the prefix set."""

The check that tells the two apart

failpass·test.py::TrieTestCase::test_prefix_set_init_prunes_branch

Check file test.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 it2404a55e094f159fbcece634f206e09aa04ca461
Broken version dated2019-05-29
Modulepygtrie
Units changedPrefixSet
Fingerprint3d0a3e04d98d5ce8
Checked2026-08-18 by goldset/0.1

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

Other bugs found in mina86/pygtrie