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 insertindex:
global directory
global bucketnumber
tid index
hashkey hashfuntioninttid
hashprefix inthashkeydirectory.globaldepth:
bucket directory.directoryrecordshashprefixvalue
bucket.index.appendindex
bucket.emptyspaces intbucketemptyspaces
ifbucketemptyspaces :
tempoparymemory bucket.index
bucket.emptyspaces bucketcapacity
bucket.index
if directoryglobaldepth bucket.localdepth:
# NUMBER OF LINKED BUCKETS
numberoflinks directoryglobaldepth bucket.localdepth
bucket.localdepth bucket.localdepth
numberofmodifylinks numberoflinks
newbucket Bucketlocaldepth bucket.localdepth, index emptyspaces bucketcapacity, id bucketnumber
for directoryrecord in directory.directoryrecords:
ifdirectoryrecord.value bucket:
ifnumberofmodifylinks :
numberofmodifylinks numberofmodifylinks
else:
directoryrecord.value newbucket
bucketnumber bucketnumber
for i in rangelentempoparymemory:
inserttempoparymemoryi
elif directoryglobaldepth bucket.localdepth:
newdirectorylen lendirectorydirectoryrecords
newdirectoryrecords
for directoryrecordnumber in rangenewdirectorylen:
newdirectoryrecords.appendDirectoryRecordhashprefixdirectoryrecordnumber,bucketBucketlocaldepthindexemptyspacesbucketcapacity,idbucketnumber
bucketnumber bucketnumber
newdirectory Directoryglobaldepthdirectory.globaldepthdirectoryrecordsnewdirectoryrecords
# REHASING
for directoryrecord in directory.directoryrecords:
haskeyhashfuntiondirectoryrecord.hashprefix
haskeyhashfuntiondirectoryrecord.hashprefix
newindex inthaskeydirectory.globaldepth:
newindex inthaskeydirectory.globaldepth:
newdirectory.directoryrecordsnewindexvalue directoryrecord.value
newdirectory.directoryrecordsnewindexvalue directoryrecord.value
directory newdirectory
for i in rangelentempoparymemory:
inserttempoparymemoryilock We have provided you with the code for extendible hashing. Run the code with various
usecases so you can demonstrate the ownership of the code. Provide code reflections in fol
lowing forms:
a Evidence of running the code with various usecases eg changing the number
of buckets, reading data from external files, simulating data generation, etc.
b Modification of the code to obtain different behaviour eg 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 thirdparty 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:bformatkey
class Bucket: self.id id self.index indexclass Directory: self.globaldepth globaldepth,class DirectoryRecord: self.hashprefix hashprefix Hyper Parameters
: bucketcapacity
bucketnumber
globaldepth
: # Initialization of buckets
bucket Bucketlocaldepth emptyspaces bucketcapacity, index id
bucket Bucketlocaldepth emptyspaces bucketcapacity, index id
# Initialization of directory
directoryrecords list
directoryrecords.appendDirectoryRecordhashprefix bucket bucket
directoryrecords.appendDirectoryRecordhashprefix bucket bucket
directory
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
