Commit 6056ebd4 authored by Jeroen F.J. Laros's avatar Jeroen F.J. Laros

Simplified counting for now.

parent 35176088
......@@ -16,8 +16,8 @@ def _add(root, word, count):
node = node[char]
if '' not in node:
node[''] = {'count': 0}
node['']['count'] += count
node[''] = 0
node[''] += count
def _find(root, word):
......@@ -49,8 +49,8 @@ def _remove(node, word, count):
"""
if not word:
if '' in node:
node['']['count'] -= count
if node['']['count'] < 1 or count == -1:
node[''] -= count
if node[''] < 1 or count == -1:
node.pop('')
return True
return False
......@@ -78,7 +78,7 @@ def _iterate(path, node, unique):
"""
if '' in node:
if not unique:
for _ in range(1, node['']['count']):
for _ in range(1, node['']):
yield path
yield path
......@@ -99,7 +99,7 @@ def _fill(node, alphabet, length):
{alphabet}.
"""
if not length:
node[''] = {'count': 1}
node[''] = 1
return
for char in alphabet:
......
......@@ -17,11 +17,11 @@ class TestTrie(object):
assert self._trie.root == {
'a': {
'b': {
'c': {'': {'count': 1}},
'd': {'': {'count': 2}}}},
'c': {'': 1},
'd': {'': 2}}},
't': {'e': {
'': {'count': 1},
's': {'t': {'': {'count': 1}}}}}}
'': 1,
's': {'t': {'': 1}}}}}
def test_word_present(self):
assert 'abc' in self._trie
......@@ -61,18 +61,18 @@ class TestTrie(object):
assert 'abx' in self._trie
def test_get_present(self):
assert self._trie.get('abc')['count'] == 1
assert self._trie.get('abc') == 1
def test_get_absent(self):
assert not self._trie.get('abx')
def test_add_twice(self):
self._trie.add('abc')
assert self._trie.get('abc')['count'] == 2
assert self._trie.get('abc') == 2
def test_add_multiple(self):
self._trie.add('abc', 2)
assert self._trie.get('abc')['count'] == 3
assert self._trie.get('abc') == 3
def test_remove_present(self):
assert self._trie.remove('test')
......@@ -93,14 +93,14 @@ class TestTrie(object):
def test_remove_twice(self):
self._trie.add('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 'abc' not in self._trie
def test_remove_multile(self):
self._trie.add('abc', 3)
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):
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!
Please register or to comment