Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class TrieNode:
def __init__(self):
self.children = {}
self.data = {}
self.isEndOfUrl = False
class Trie:
def __init__(self):
self.root = self.getNode()
def getNode(self):
# Returns new trie node (initialized to NULLs)
return TrieNode()
def insert(self, url, timestamp, payload):
urlSplit = url.split('/')
pCrawl = self.root
# for level in urlSplit:
for i in range(1, len(urlSplit)):
# if current character is not present
level = urlSplit[i]
if len(level) == 0: continue
if pCrawl.children.__contains__(level):
pCrawl = pCrawl.children[level];
else:
pCrawl.children[level] = TrieNode()
pCrawl = pCrawl.children[level]
pCrawl.data[timestamp] = payload;
pCrawl.isEndOfUrl = True
def extract(self, startTimestamp , endTimeStamp):
print()
# extract tree based on given timestamp
# pCrawl = self.root
# for child in pCrawl.children:
# print(child)
def comparison(self, tree1, tree2):
print()
# compare two trees
def main():
keys = ['/spotlight/impact/2014-11-24-master/naturalists.html', '/']
# Trie object
t = Trie()
# Construct trie
for key in keys:
t.insert(key)
# Search for different keys
print("{} ---- {}".format("/spotlight/impact/2014-11-24-master/naturalists.html", [t.search("/spotlight/impact/2014-11-24-master/naturalists.html")]))
print("{} ---- {}".format("/", [t.search("/")]))
if __name__ == '__main__':
main()