Commit 6056ebd4 by Jeroen F.J. Laros

Simplified counting for now.

parent 35176088
 ... @@ -16,8 +16,8 @@ def _add(root, word, count): ... @@ -16,8 +16,8 @@ def _add(root, word, count): node = node[char] node = node[char] if '' not in node: if '' not in node: node[''] = {'count': 0} node[''] = 0 node['']['count'] += count node[''] += count def _find(root, word): def _find(root, word): ... @@ -49,8 +49,8 @@ def _remove(node, word, count): ... @@ -49,8 +49,8 @@ def _remove(node, word, count): """ """ if not word: if not word: if '' in node: if '' in node: node['']['count'] -= count node[''] -= count if node['']['count'] < 1 or count == -1: if node[''] < 1 or count == -1: node.pop('') node.pop('') return True return True return False return False ... @@ -78,7 +78,7 @@ def _iterate(path, node, unique): ... @@ -78,7 +78,7 @@ def _iterate(path, node, unique): """ """ if '' in node: if '' in node: if not unique: if not unique: for _ in range(1, node['']['count']): for _ in range(1, node['']): yield path yield path yield path yield path ... @@ -99,7 +99,7 @@ def _fill(node, alphabet, length): ... @@ -99,7 +99,7 @@ def _fill(node, alphabet, length): {alphabet}. {alphabet}. """ """ if not length: if not length: node[''] = {'count': 1} node[''] = 1 return return for char in alphabet: for char in alphabet: ... ...
 ... @@ -17,11 +17,11 @@ class TestTrie(object): ... @@ -17,11 +17,11 @@ class TestTrie(object): assert self._trie.root == { assert self._trie.root == { 'a': { 'a': { 'b': { 'b': { 'c': {'': {'count': 1}}, 'c': {'': 1}, 'd': {'': {'count': 2}}}}, 'd': {'': 2}}}, 't': {'e': { 't': {'e': { '': {'count': 1}, '': 1, 's': {'t': {'': {'count': 1}}}}}} 's': {'t': {'': 1}}}}} def test_word_present(self): def test_word_present(self): assert 'abc' in self._trie assert 'abc' in self._trie ... @@ -61,18 +61,18 @@ class TestTrie(object): ... @@ -61,18 +61,18 @@ class TestTrie(object): assert 'abx' in self._trie assert 'abx' in self._trie def test_get_present(self): def test_get_present(self): assert self._trie.get('abc')['count'] == 1 assert self._trie.get('abc') == 1 def test_get_absent(self): def test_get_absent(self): assert not self._trie.get('abx') assert not self._trie.get('abx') def test_add_twice(self): def test_add_twice(self): self._trie.add('abc') self._trie.add('abc') assert self._trie.get('abc')['count'] == 2 assert self._trie.get('abc') == 2 def test_add_multiple(self): def test_add_multiple(self): self._trie.add('abc', 2) self._trie.add('abc', 2) assert self._trie.get('abc')['count'] == 3 assert self._trie.get('abc') == 3 def test_remove_present(self): def test_remove_present(self): assert self._trie.remove('test') assert self._trie.remove('test') ... @@ -93,14 +93,14 @@ class TestTrie(object): ... @@ -93,14 +93,14 @@ class TestTrie(object): def test_remove_twice(self): def test_remove_twice(self): self._trie.add('abc') self._trie.add('abc') assert not self._trie.remove('abc') assert not self._trie.remove('abc') assert self._trie.get('abc')['count'] == 1 assert self._trie.get('abc') == 1 assert self._trie.remove('abc') assert self._trie.remove('abc') assert 'abc' not in self._trie assert 'abc' not in self._trie def test_remove_multile(self): def test_remove_multile(self): self._trie.add('abc', 3) self._trie.add('abc', 3) assert not self._trie.remove('abc', 2) assert not self._trie.remove('abc', 2) assert self._trie.get('abc')['count'] == 2 assert self._trie.get('abc') == 2 def test_remove_force(self): def test_remove_force(self): self._trie.add('abc') self._trie.add('abc') ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!