def fill_cache(self):
        print(
            "******************In fill cache method*******************************************"
        )
        cache = trie()
        with open(self._exact_file_path, "r") as fh:
            for line in fh:
                ret = line.split("->")
                sys.stdout.write(str(ret[0]))
                sys.stdout.write(" " + str(len(ret[0])))
                sys.stdout.write("\n")
                cache.insert(ret[0])

        return cache
Exemple #2
0
def resolve(unisrt, in_res_list):
    '''
    This function is supposed to find the UNIS resources determined by the input.
    The input should be a list of ip addresses obtained by user's traceroute.
    This function should query UNIS and resolve a list of resource.
    
    IP addresses -> ingress and egress L2 ports (we assume L2 ports are the essences
    of resource scheduling)
    '''
    ip_resolver = unisrt._resources["ipports"]._contents
    
    # use ipports to build forwarding table for each node
    # !!! apparently, shouldn't be done each time got invoked, too expensive !!!
    nodes = {}
    for i in ip_resolver:
        nodes.setdefault(i["attach"]["node"], {})[ToBin(i["ipaddress"])] = i["attach"]["port"]
    for key, value in nodes.iteritems():
        nodes[key] = trie(value)
    
    # resolve the egress port
    out_res_list = []
    for res in in_res_list:
        out_res_list.append(res)
        try:
            next_hop = in_res_list[in_res_list.index(res) + 1]["ref"]
        except IndexError:
            # the last item from input
            pass
        # !!! ATTENTION: ip_resolver is a list, and cannot be indexed by an ip yet
        # !!! needs fixing
        egress = nodes[ip_resolver[res]["attach"]["node"]].longest_prefix_value(next_hop)
        out_res_list.append(egress)
    
    for index in range(len(out_res_list)):
        try:
            # egress may already be in the form of lower level port
            out_res_list[index] = ip_resolver[out_res_list[index]]["attach"]["port"]
        except IndexError:
            continue
    return out_res_list
        
    '''
 def __init__(self):
     self._cache = trie()
     self._book_handler = None
     start_new_thread(self.__cache_updater, ())
Exemple #4
0
from trie import *

t = trie();

t.add("rob",("guy",1))
t.add("robert",("guy",2),True)
t.add("lockhart",("guy",3))
t.diff()
t.tokenize("robert lockhart")
t.tokenize("robert glorb lockhart")
dic={}
with open('config.csv', 'r') as file:
	csv_reader = reader(file)
	for row in csv_reader:
		if not row:
			continue
		dic[row[0]]=row[1]

dic["support"] = float(dic["support"])
dic["confidence"] = float(dic["confidence"])

sys.stdout = open(dic["output"], 'w')
singleitems = []
singlecnts = []
cnt=0
freq_trie=trie(1,"root")
with open(dic["input"], 'r') as file:
	csv_reader = file.read()
	csv_reader = csv_reader.split('\n')[:-1]
	no_transactions = len(csv_reader)
	for row in csv_reader:
		if not row:
			continue
		row = [str(x) for x in row.split(' ')]
		row.sort()
		freq_trie.insertNode(row,1)
		for i in range(len(row)):
			if row[i] not in singleitems:
				singleitems.append(row[i])
				singlecnts.append(int(1))
			else: