コード例 #1
0
import re
from Trie import Trie

trie = Trie()

trie.add("hello")
print(trie.contains("hello")
trie.add("hello")
コード例 #2
0
    from time import time
    print("BST-SET")
    start_time = time()
    bst_set = BSTSet()
    for word in words:
        bst_set.add(word)

    for word in words:
        bst_set.contains(word)

    print('Total words: ', len(words))
    print('Unique words: ', bst_set.get_size())
    print('Contains word "they": ', bst_set.contains('they'))
    ## 耗时0.58秒左右
    print('Total time: {} seconds'.format(time() - start_time))

    print("Trie")
    start_time = time()
    trie = Trie()
    for word in words:
        trie.add(word)

    for word in words:
        trie.contains(word)

    print('Total words: ', len(words))
    print('Unique words: ', trie.get_size())
    print('Contains word "they": ', trie.contains('they'))
    ## 耗时0.58秒左右
    print('Total time: {} seconds'.format(time() - start_time))