Beispiel #1
0
def test_keys():
    trie = _trie()
    state = datrie.State(trie)
    it = datrie.Iterator(state)

    keys = []
    while it.next():
        keys.append(it.key())

    assert keys == sorted(WORDS)
Beispiel #2
0
def test_keys_tail():
    trie = _trie()
    state = datrie.State(trie)
    state.walk('pro')
    it = datrie.Iterator(state)

    keys = []
    while it.next():
        keys.append(it.key())

    assert keys == ['duce', 'ducer', 'ducers', 'gress']
Beispiel #3
0
def test_next_tail():
    trie = _trie()
    state = datrie.State(trie)
    state.walk('poo')
    it = datrie.Iterator(state)

    values = []
    while it.next():
        values.append(it.data())

    assert values == [2]
Beispiel #4
0
def test_next():
    trie = _trie()
    state = datrie.State(trie)
    it = datrie.Iterator(state)

    values = []
    while it.next():
        values.append(it.data())

    assert len(values) == 8
    assert values == [2, 3, 4, 5, 6, 7, 1, 8]
Beispiel #5
0
def test_next_non_root():
    trie = _trie()
    state = datrie.State(trie)
    state.walk('pr')
    it = datrie.Iterator(state)

    values = []
    while it.next():
        values.append(it.data())

    assert len(values) == 7
    assert values == [3, 4, 5, 6, 7, 1, 8]
Beispiel #6
0
 def remove_old_keys(self, hwm_limit):
     """
     Deletes and returns all keys that have HWMs less than hwm_limit.
     :return: list of keys that were deleted.
     """
     assert not self._deletion_hwms, \
         "Delete tracking incompatible with remove_old_keys()"
     _log.info("Removing keys that are older than %s", hwm_limit)
     old_keys = []
     state = datrie.State(self._hwms)
     state.walk(u"")
     it = datrie.Iterator(state)
     while it.next():
         value = it.data()
         if value < hwm_limit:
             old_keys.append(it.key())
     for old_key in old_keys:
         del self._hwms[old_key]
     _log.info("Deleted %s old keys", len(old_keys))
     return map(decode_key, old_keys)