from MP_records import records import string import random as rd import time import csv import codecs def polynomial_hash(word): p=11111 m=(10**9)+9 hashh=0 for i in range(len(word)): hashh+=ord(word[i])*(p**i) hashh=hashh%m return hashh def hash_to_index(hashh,length): #print(hashh) #if len(str(hashh))>4: #hashh=int(str(hashh)[3:]) while hashh>length: hashh=hashh%(length) return hashh def ll_insert(table,name,phone,index): if table[index]==None: entry={"name":name,"phone":phone,"next":None} table[index]=entry return table else: entry={"name":name,"phone":phone,"next":None} if table[index]["phone"]==phone: table[index]["name"]=name return table if table[index]["next"]==None: table[index]["next"]=entry return table else: nexxt=table[index]["next"] if nexxt["phone"]==phone: nexxt["name"]=name return table while nexxt["next"]!=None: nexxt=nexxt["next"] if nexxt["phone"]==phone: nexxt["name"]=name return table nexxt["next"]=entry return table def ht_insert(table,name,phone): index=hash_to_index(polynomial_hash(name), len(table)) ll_insert(table,name,phone,index) return table def ht_find(table, name): index=hash_to_index(polynomial_hash(name), len(table)) if table[index]!=None: if table[index]["name"]==name: return table[index]["phone"] elif table[index]["next"]!=None: if table[index]["next"]["name"]==name: return table[index]["next"]["phone"] else: nexxt=table[index]["next"] while nexxt["next"]!=None: nexxt=nexxt["next"] if nexxt["name"]==name: return nexxt["phone"] return None def ht_delete(table,name): index=hash_to_index(polynomial_hash(name), len(table)) if len(table)>0: if table[index]["name"]==name: if table[index]["next"]!=None: table[index]=table[index]["next"] return table else: table[index]=None return table elif table[index]["next"]!=None: if table[index]["next"]["name"]==name: if table[index]["next"]["next"]!=None: table[index]["next"]=table[index]["next"]["next"] return table else: table[index]["next"]=None return table elif table[index]["next"]["next"]!=None: nexxt1=table[index]["next"] nexxt2=nexxt1["next"] if nexxt2["name"]==name: if nexxt2["next"]!=None: nexxt1["next"]=nexxt2["next"] return table else: nexxt1["next"]=None return table while nexxt2["next"]!=None: nexxt1=nexxt2 nexxt2=nexxt1["next"] if nexxt2["name"]==name: if nexxt2["next"]!=None: nexxt1["next"]=nexxt2["next"] return table else: nexxt1["next"]=None return table def bad_sort(names,phones): names1=[] phones1=[] while len(names)>0: min_=names[0].encode() ph=phones[0] for i in range(len(names)): nm=names[i].encode() if nm0: for i in range (0,N-n): j=i while j+n(names[j+n].encode()): t=names[j] t1=phones[j] names[j]=names[j+n] phones[j]=phones[j+n] names[j+n]=t phones[j+n]=t1 j=i else: j+=n n=n//2 return names,phones def ht_listall(table): names=[] phones=[] pointer=0 while pointer