def read_f_into_Hash_table(file, h_func): insertions = 0 words = Hash.HashTable((400000), alpha_value, 0) forHash = io.open(file, 'r+', encoding="UTF-8") for line in forHash: a = line.split() #Direguards "words" in file that do not begin witch characters from the alphabet if (a[0] >= 'A' and a[0] <= 'Z') or (a[0] >= 'a' and a[0] <= 'z'): insertions += 1 words.insert(a[0], a[1:len(a)], h_func) return words
def read_f_into_Hash_table(file, h_func): insertions = 0 words = Hash.HashTable((400000), alpha_value) ## why did you choose 400000 instead of any other value? forHash = io.open(file, 'r+', encoding="UTF-8") ## why not just save the file as UTF-8? for line in forHash: a = line.split() #Direguards "words" in file that do not begin witch characters from the alphabet if (a[0] >= 'A' and a[0] <= 'Z') or (a[0] >= 'a' and a[0] <= 'z'): ## you can use a is char instead of the line above insertions += 1 words.insert(a[0], a[1:len(a)], h_func) print("load factor :", len(words.table) * .75) return words
''' Created on Oct 2, 2014 @author: Calvin ''' import red_black_set_mod import Hash keys = Hash.generateKeys(10000, 2000000000) #case (i)... table_one = Hash.HashTable(100000) #case (ii)... table_two = Hash.HashTable(1000) #red black BST rb_tree = red_black_set_mod.RedBlackTree() #a) the inserts table_one.insert(keys) print "inserted 10,000 elements into table_one with 0 comparisons\n" table_two.insert(keys) print "inserted 10,000 elements into table_two with 0 comparisons\n" totalCount = 0 for key in keys: node, count = rb_tree.add(key) totalCount += count print "inserted 10,000 elements into rb_tree with {0} comparisons\n".format( str(totalCount)) #b) the deletes