Question: This is the code provided in the InsertionAlgorithm block: def insert ( index ) : global directory global bucket _ number t _ id =

This is the code provided in the InsertionAlgorithm block:
def insert(index):
global directory
global bucket_number
t_id = index[0]
hash_key = hash_funtion(int(t_id))
hash_prefix = int(hash_key[-directory.global_depth[0]:],2)
bucket = directory.directory_records[hash_prefix].value
bucket.index.append(index)
bucket.empty_spaces = int(bucket.empty_spaces)-1
if(bucket.empty_spaces 0):
tempopary_memory = bucket.index
bucket.empty_spaces = bucket_capacity
bucket.index =[]
if (directory.global_depth[0]> bucket.local_depth):
# NUMBER OF LINKED BUCKETS
number_of_links =2**(directory.global_depth[0]- bucket.local_depth)
bucket.local_depth = bucket.local_depth +1
number_of_modify_links = number_of_links/2
new_bucket = Bucket(local_depth = bucket.local_depth, index=[], empty_spaces = bucket_capacity, id = bucket_number)
for directory_record in directory.directory_records:
if(directory_record.value == bucket):
if(number_of_modify_links !=0):
number_of_modify_links = number_of_modify_links -1
else:
directory_record.value = new_bucket
bucket_number = bucket_number +1
for i in range(len(tempopary_memory)):
insert(tempopary_memory[i])
elif (directory.global_depth[0]== bucket.local_depth):
new_directory_len =2* len(directory.directory_records)
new_directory_records =[]
for directory_record_number in range(new_directory_len):
new_directory_records.append(DirectoryRecord(hash_prefix=directory_record_number,bucket=Bucket(local_depth=1,index=[],empty_spaces=bucket_capacity,id=bucket_number)))
bucket_number = bucket_number +1
new_directory = Directory(global_depth=directory.global_depth[0]+1,directory_records=new_directory_records)
# REHASING
for directory_record in directory.directory_records:
haskey1='0'+hash_funtion(directory_record.hash_prefix)
haskey2='1'+hash_funtion(directory_record.hash_prefix)
new_index1= int(haskey1[-directory.global_depth[0]:],2)
new_index2= int(haskey2[-directory.global_depth[0]:],2)
new_directory.directory_records[new_index1].value = directory_record.value
new_directory.directory_records[new_index2].value = directory_record.value
directory= new_directory
for i in range(len(tempopary_memory)):
insert(tempopary_memory[i],lock)(2) We have provided you with the code for extendible hashing. Run the code with various
use-cases so you can demonstrate the ownership of the code. Provide code reflections in fol-
lowing forms:
a) Evidence of running the code with various use-cases - e.g., changing the number
of buckets, reading data from external files, simulating data generation, etc.
-b) Modification of the code to obtain different behaviour - e.g., use of dictionaries
instead of lists, refactoring code into various functions or classes, etc.
-c) Detail comments of various lines of the code explaining which part of the algorithm
it is executing, this can be in form of detailed inline comments or adding paragraph
cells in the juypter notebook.
This is a third-party code, we welcome you to do a complete overhaul of the code or write
the code from scratch.
Your tutor will ask you various questions about the code and its inner working, you should
be able to explain it. return '{\theta:16b}'.format(key)
class Bucket: self.id = id self.index = indexclass Directory: self.global_depth = global_depth,class DirectoryRecord: self.hash_prefix = hash_prefix Hyper Parameters
[18]: bucket_capacity =3
bucket_number =4
global_depth =2
[19]: # Initialization of buckets
bucket1= Bucket(local_depth =1, empty_spaces = bucket_capacity, index =[], id =1)
bucket 2= Bucket(local_depth =1, empty_spaces = bucket_capacity, index =[], id =2)
# Initialization of directory
directory_records = list()
directory_records.append(DirectoryRecord(hash_prefix =, bucket = bucket1))
directory_records.append(DirectoryRecord(hash_prefix =1, bucket = bucket2))
directory
This is the code provided in the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!