SlideShare a Scribd company logo
When writing a member function of the HAMT class, the member function can access resources
directly (eg, self._item) and/or call other member functions to get work done, depending on
preference and clarity.
Beginning with the hamt_hw.py file, find all the member functions with undefined bodies (I've
written pass in each). Finish writing these functions so that they work as described in their
comments. Do not change any existing code in the file except the definitions of the previously
undefined functions and the testing code at the bottom. When wrting the new functions, you may
add helper methods or new parameters with default values if you wish.
At the bottom of the supplied file is some indented code which is executed whenever you run the
supplied file directly. This is a good place to do your testing. Write your test cases here so that I
can see them. Leave all your testing code indented so that it only runs when __name__ ==
'__main__'.
HERE IS hamt_hw.py
# This implementation requires objects in the set be hashable.
# Resulting trie will have expected log height if hash is random.
# In this implementaiton the root node always has _item == None
from functools import reduce
class hamt:
DEG = 4 # Children per node (can be set to any power of 2)
BITS = 2 # Should be log2(DEG), bits needed to select child
MASK = 0b11 # Should be BITS one-bits
def __init__(self, item = None, children = None):
self._item = item
if children == None:
self._children = [None] * hamt.DEG # List of DEG Nones
else:
self._children = children
# returns copy of self node with child i set to node x
def _updatechild(self, i, x):
updatedchildlist = list(self._children) # copy self's child list
updatedchildlist[i] = x # update child i
return hamt(self._item, updatedchildlist) # build and return new node
# Returns reference to new root if change made, else None
def _add(self, item, hashbits):
if self._item == item:
# This node matches item. Return None to indicate no change.
return None
else:
# Continue search using hashbits to pick direction
child_num = hashbits & hamt.MASK
if self._children[child_num] == None:
# item not in trie. Add it as new leaf node.
return self._updatechild(child_num, hamt(item))
else:
# Ask appropriate child to add item, receive updated reference
shiftedhashbits = hashbits >> hamt.BITS
newchild = self._children[child_num]._add(item, shiftedhashbits)
if newchild == None:
return None
else:
return self._updatechild(child_num, newchild)
def add(self, item):
# Pass item and hashbits to private recursive helper
return self._add(item, hash(item))
# Returns True if trie has no items, else False. Rutime O(1).
def empty(self):
pass
# Returns True if item in trie, else False. Expected rutime O(log n).
def contains(self, item):
pass
# Returns number of items in trie. Runtime O(n).
def __len__(self):
pass
# Returns HAMT that is union of self and other. Expected rutime O(n log n).
def union(self, other):
pass
# Adds self's item string to acc list, then ask each child to do the same
def _str(self, acc):
if self._item != None: # Don't do anything in fake root node
acc.append(str(self._item))
for child in self._children:
if child != None:
child._str(acc)
# Build list of all items in trie, then join them with ", " in between
def __str__(self):
acc = []
self._str(acc)
return "{" + ", ".join(acc) + "}"
# The following is a trick to make this testing code be ignored
# when this file is being imported, but run when run directly
# https://codefather.tech/blog/if-name-main-python/
if __name__ == '__main__':
a = hamt()
b = a.add("B")
c = b.add("C")
d = c.add("D")
e = d.add("E")
f = e.add("F")
g = f.add("F")
print(a)
print(b)
print(c)
print(d)
print(e)
print(f)
When writing a member function of the HAMT class- the member function.pdf

More Related Content

Similar to When writing a member function of the HAMT class- the member function.pdf

Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdf
sravi07
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
sravi07
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
fantoosh1
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
ganisyedtrd
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
Ian5L3Allanm
 
cbse class 12 Python Functions2 for class 12 .pptx
cbse class 12 Python Functions2 for class 12 .pptxcbse class 12 Python Functions2 for class 12 .pptx
cbse class 12 Python Functions2 for class 12 .pptx
tcsonline1222
 
ex 2.pdf
ex 2.pdfex 2.pdf
ex 2.pdf
SridharCS7
 
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdfpython3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
info706022
 
UNIT- 2 PPDS R20.pptx
UNIT- 2 PPDS R20.pptxUNIT- 2 PPDS R20.pptx
UNIT- 2 PPDS R20.pptx
ssuser688516
 
レガシーコード改善ガイド
レガシーコード改善ガイドレガシーコード改善ガイド
レガシーコード改善ガイド
Maki Toshio
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdf
prasnt1
 
show code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdfshow code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdf
AlanSmDDyerl
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx
Adamq0DJonese
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
Blake0FxCampbelld
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
cgraciela1
 
Do the following picSolutionHere is the solution for the .pdf
Do the following picSolutionHere is the solution for the .pdfDo the following picSolutionHere is the solution for the .pdf
Do the following picSolutionHere is the solution for the .pdf
dhavalbl38
 
Chapter 05.DS_StoreChapter 05arraybag.pyFile array.docx
Chapter 05.DS_StoreChapter 05arraybag.pyFile array.docxChapter 05.DS_StoreChapter 05arraybag.pyFile array.docx
Chapter 05.DS_StoreChapter 05arraybag.pyFile array.docx
tidwellveronique
 
Program Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docxProgram Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docx
sharold2
 
Program Specifications in c++ Develop an inventory management syste.docx
Program Specifications in c++    Develop an inventory management syste.docxProgram Specifications in c++    Develop an inventory management syste.docx
Program Specifications in c++ Develop an inventory management syste.docx
sharold2
 
Files that you must write and turn in Please do not turn in.pdf
Files that you must write and turn in Please do not turn in.pdfFiles that you must write and turn in Please do not turn in.pdf
Files that you must write and turn in Please do not turn in.pdf
actocomputer
 

Similar to When writing a member function of the HAMT class- the member function.pdf (20)

Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdf
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
 
cbse class 12 Python Functions2 for class 12 .pptx
cbse class 12 Python Functions2 for class 12 .pptxcbse class 12 Python Functions2 for class 12 .pptx
cbse class 12 Python Functions2 for class 12 .pptx
 
ex 2.pdf
ex 2.pdfex 2.pdf
ex 2.pdf
 
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdfpython3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
 
UNIT- 2 PPDS R20.pptx
UNIT- 2 PPDS R20.pptxUNIT- 2 PPDS R20.pptx
UNIT- 2 PPDS R20.pptx
 
レガシーコード改善ガイド
レガシーコード改善ガイドレガシーコード改善ガイド
レガシーコード改善ガイド
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdf
 
show code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdfshow code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdf
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
 
Do the following picSolutionHere is the solution for the .pdf
Do the following picSolutionHere is the solution for the .pdfDo the following picSolutionHere is the solution for the .pdf
Do the following picSolutionHere is the solution for the .pdf
 
Chapter 05.DS_StoreChapter 05arraybag.pyFile array.docx
Chapter 05.DS_StoreChapter 05arraybag.pyFile array.docxChapter 05.DS_StoreChapter 05arraybag.pyFile array.docx
Chapter 05.DS_StoreChapter 05arraybag.pyFile array.docx
 
Program Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docxProgram Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docx
 
Program Specifications in c++ Develop an inventory management syste.docx
Program Specifications in c++    Develop an inventory management syste.docxProgram Specifications in c++    Develop an inventory management syste.docx
Program Specifications in c++ Develop an inventory management syste.docx
 
Files that you must write and turn in Please do not turn in.pdf
Files that you must write and turn in Please do not turn in.pdfFiles that you must write and turn in Please do not turn in.pdf
Files that you must write and turn in Please do not turn in.pdf
 

More from aadyaenterprisesnoid

What sometimes makes implementation of activity-based costing difficul.pdf
What sometimes makes implementation of activity-based costing difficul.pdfWhat sometimes makes implementation of activity-based costing difficul.pdf
What sometimes makes implementation of activity-based costing difficul.pdf
aadyaenterprisesnoid
 
What type of loss of genetic diversity occurred in the situation descr.pdf
What type of loss of genetic diversity occurred in the situation descr.pdfWhat type of loss of genetic diversity occurred in the situation descr.pdf
What type of loss of genetic diversity occurred in the situation descr.pdf
aadyaenterprisesnoid
 
What would you expect to see in regions of the DNA where housekeeping (1).pdf
What would you expect to see in regions of the DNA where housekeeping (1).pdfWhat would you expect to see in regions of the DNA where housekeeping (1).pdf
What would you expect to see in regions of the DNA where housekeeping (1).pdf
aadyaenterprisesnoid
 
What wioutal be the site af L - heneth neid- How many Biochs will this.pdf
What wioutal be the site af L - heneth neid- How many Biochs will this.pdfWhat wioutal be the site af L - heneth neid- How many Biochs will this.pdf
What wioutal be the site af L - heneth neid- How many Biochs will this.pdf
aadyaenterprisesnoid
 
What type of systems focus providing information to financial executiv.pdf
What type of systems focus providing information to financial executiv.pdfWhat type of systems focus providing information to financial executiv.pdf
What type of systems focus providing information to financial executiv.pdf
aadyaenterprisesnoid
 
what type of ownership will be dissolved if one person becomes insolve.pdf
what type of ownership will be dissolved if one person becomes insolve.pdfwhat type of ownership will be dissolved if one person becomes insolve.pdf
what type of ownership will be dissolved if one person becomes insolve.pdf
aadyaenterprisesnoid
 
What was Jeffrey Skilling's opinion of Bethany McLean- a- That she was.pdf
What was Jeffrey Skilling's opinion of Bethany McLean- a- That she was.pdfWhat was Jeffrey Skilling's opinion of Bethany McLean- a- That she was.pdf
What was Jeffrey Skilling's opinion of Bethany McLean- a- That she was.pdf
aadyaenterprisesnoid
 
What structure is he pointing to here- The beige colored sheet that co.pdf
What structure is he pointing to here- The beige colored sheet that co.pdfWhat structure is he pointing to here- The beige colored sheet that co.pdf
What structure is he pointing to here- The beige colored sheet that co.pdf
aadyaenterprisesnoid
 
What would seasons be like on Uranus at a location close to the north.pdf
What would seasons be like on Uranus at a location close to the north.pdfWhat would seasons be like on Uranus at a location close to the north.pdf
What would seasons be like on Uranus at a location close to the north.pdf
aadyaenterprisesnoid
 
What types of management issues currently exist due to the Information.pdf
What types of management issues currently exist due to the Information.pdfWhat types of management issues currently exist due to the Information.pdf
What types of management issues currently exist due to the Information.pdf
aadyaenterprisesnoid
 
What type of muscle action is occurring from A to B assuming that the.pdf
What type of muscle action is occurring from A to B assuming that the.pdfWhat type of muscle action is occurring from A to B assuming that the.pdf
What type of muscle action is occurring from A to B assuming that the.pdf
aadyaenterprisesnoid
 
What type of unconformity lies between units A and D in cross section.pdf
What type of unconformity lies between units A and D in cross section.pdfWhat type of unconformity lies between units A and D in cross section.pdf
What type of unconformity lies between units A and D in cross section.pdf
aadyaenterprisesnoid
 
What was Lifard Co's cash flow from assets during 2022- Use Exhibit I-.pdf
What was Lifard Co's cash flow from assets during 2022- Use Exhibit I-.pdfWhat was Lifard Co's cash flow from assets during 2022- Use Exhibit I-.pdf
What was Lifard Co's cash flow from assets during 2022- Use Exhibit I-.pdf
aadyaenterprisesnoid
 
What use of the water should take precedent- Is the use of water to pr.pdf
What use of the water should take precedent- Is the use of water to pr.pdfWhat use of the water should take precedent- Is the use of water to pr.pdf
What use of the water should take precedent- Is the use of water to pr.pdf
aadyaenterprisesnoid
 
what type of histogram is this SEX-F Frequency.pdf
what type of histogram is this SEX-F Frequency.pdfwhat type of histogram is this SEX-F Frequency.pdf
what type of histogram is this SEX-F Frequency.pdf
aadyaenterprisesnoid
 
What type of front is located between letters E and F -Multiple Choice.pdf
What type of front is located between letters E and F -Multiple Choice.pdfWhat type of front is located between letters E and F -Multiple Choice.pdf
What type of front is located between letters E and F -Multiple Choice.pdf
aadyaenterprisesnoid
 
Where is the posterior (dorsal) root locited in the sequence of struct.pdf
Where is the posterior (dorsal) root locited in the sequence of struct.pdfWhere is the posterior (dorsal) root locited in the sequence of struct.pdf
Where is the posterior (dorsal) root locited in the sequence of struct.pdf
aadyaenterprisesnoid
 
What was Lizard Co-'s cash flow from assets during 2022- Use Exhibit I.pdf
What was Lizard Co-'s cash flow from assets during 2022- Use Exhibit I.pdfWhat was Lizard Co-'s cash flow from assets during 2022- Use Exhibit I.pdf
What was Lizard Co-'s cash flow from assets during 2022- Use Exhibit I.pdf
aadyaenterprisesnoid
 
What was the relative concentration of Solution X (high- medium or low.pdf
What was the relative concentration of Solution X (high- medium or low.pdfWhat was the relative concentration of Solution X (high- medium or low.pdf
What was the relative concentration of Solution X (high- medium or low.pdf
aadyaenterprisesnoid
 
What type of relationship is implemented between the following two ent (1).pdf
What type of relationship is implemented between the following two ent (1).pdfWhat type of relationship is implemented between the following two ent (1).pdf
What type of relationship is implemented between the following two ent (1).pdf
aadyaenterprisesnoid
 

More from aadyaenterprisesnoid (20)

What sometimes makes implementation of activity-based costing difficul.pdf
What sometimes makes implementation of activity-based costing difficul.pdfWhat sometimes makes implementation of activity-based costing difficul.pdf
What sometimes makes implementation of activity-based costing difficul.pdf
 
What type of loss of genetic diversity occurred in the situation descr.pdf
What type of loss of genetic diversity occurred in the situation descr.pdfWhat type of loss of genetic diversity occurred in the situation descr.pdf
What type of loss of genetic diversity occurred in the situation descr.pdf
 
What would you expect to see in regions of the DNA where housekeeping (1).pdf
What would you expect to see in regions of the DNA where housekeeping (1).pdfWhat would you expect to see in regions of the DNA where housekeeping (1).pdf
What would you expect to see in regions of the DNA where housekeeping (1).pdf
 
What wioutal be the site af L - heneth neid- How many Biochs will this.pdf
What wioutal be the site af L - heneth neid- How many Biochs will this.pdfWhat wioutal be the site af L - heneth neid- How many Biochs will this.pdf
What wioutal be the site af L - heneth neid- How many Biochs will this.pdf
 
What type of systems focus providing information to financial executiv.pdf
What type of systems focus providing information to financial executiv.pdfWhat type of systems focus providing information to financial executiv.pdf
What type of systems focus providing information to financial executiv.pdf
 
what type of ownership will be dissolved if one person becomes insolve.pdf
what type of ownership will be dissolved if one person becomes insolve.pdfwhat type of ownership will be dissolved if one person becomes insolve.pdf
what type of ownership will be dissolved if one person becomes insolve.pdf
 
What was Jeffrey Skilling's opinion of Bethany McLean- a- That she was.pdf
What was Jeffrey Skilling's opinion of Bethany McLean- a- That she was.pdfWhat was Jeffrey Skilling's opinion of Bethany McLean- a- That she was.pdf
What was Jeffrey Skilling's opinion of Bethany McLean- a- That she was.pdf
 
What structure is he pointing to here- The beige colored sheet that co.pdf
What structure is he pointing to here- The beige colored sheet that co.pdfWhat structure is he pointing to here- The beige colored sheet that co.pdf
What structure is he pointing to here- The beige colored sheet that co.pdf
 
What would seasons be like on Uranus at a location close to the north.pdf
What would seasons be like on Uranus at a location close to the north.pdfWhat would seasons be like on Uranus at a location close to the north.pdf
What would seasons be like on Uranus at a location close to the north.pdf
 
What types of management issues currently exist due to the Information.pdf
What types of management issues currently exist due to the Information.pdfWhat types of management issues currently exist due to the Information.pdf
What types of management issues currently exist due to the Information.pdf
 
What type of muscle action is occurring from A to B assuming that the.pdf
What type of muscle action is occurring from A to B assuming that the.pdfWhat type of muscle action is occurring from A to B assuming that the.pdf
What type of muscle action is occurring from A to B assuming that the.pdf
 
What type of unconformity lies between units A and D in cross section.pdf
What type of unconformity lies between units A and D in cross section.pdfWhat type of unconformity lies between units A and D in cross section.pdf
What type of unconformity lies between units A and D in cross section.pdf
 
What was Lifard Co's cash flow from assets during 2022- Use Exhibit I-.pdf
What was Lifard Co's cash flow from assets during 2022- Use Exhibit I-.pdfWhat was Lifard Co's cash flow from assets during 2022- Use Exhibit I-.pdf
What was Lifard Co's cash flow from assets during 2022- Use Exhibit I-.pdf
 
What use of the water should take precedent- Is the use of water to pr.pdf
What use of the water should take precedent- Is the use of water to pr.pdfWhat use of the water should take precedent- Is the use of water to pr.pdf
What use of the water should take precedent- Is the use of water to pr.pdf
 
what type of histogram is this SEX-F Frequency.pdf
what type of histogram is this SEX-F Frequency.pdfwhat type of histogram is this SEX-F Frequency.pdf
what type of histogram is this SEX-F Frequency.pdf
 
What type of front is located between letters E and F -Multiple Choice.pdf
What type of front is located between letters E and F -Multiple Choice.pdfWhat type of front is located between letters E and F -Multiple Choice.pdf
What type of front is located between letters E and F -Multiple Choice.pdf
 
Where is the posterior (dorsal) root locited in the sequence of struct.pdf
Where is the posterior (dorsal) root locited in the sequence of struct.pdfWhere is the posterior (dorsal) root locited in the sequence of struct.pdf
Where is the posterior (dorsal) root locited in the sequence of struct.pdf
 
What was Lizard Co-'s cash flow from assets during 2022- Use Exhibit I.pdf
What was Lizard Co-'s cash flow from assets during 2022- Use Exhibit I.pdfWhat was Lizard Co-'s cash flow from assets during 2022- Use Exhibit I.pdf
What was Lizard Co-'s cash flow from assets during 2022- Use Exhibit I.pdf
 
What was the relative concentration of Solution X (high- medium or low.pdf
What was the relative concentration of Solution X (high- medium or low.pdfWhat was the relative concentration of Solution X (high- medium or low.pdf
What was the relative concentration of Solution X (high- medium or low.pdf
 
What type of relationship is implemented between the following two ent (1).pdf
What type of relationship is implemented between the following two ent (1).pdfWhat type of relationship is implemented between the following two ent (1).pdf
What type of relationship is implemented between the following two ent (1).pdf
 

Recently uploaded

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 

Recently uploaded (20)

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 

When writing a member function of the HAMT class- the member function.pdf

  • 1. When writing a member function of the HAMT class, the member function can access resources directly (eg, self._item) and/or call other member functions to get work done, depending on preference and clarity. Beginning with the hamt_hw.py file, find all the member functions with undefined bodies (I've written pass in each). Finish writing these functions so that they work as described in their comments. Do not change any existing code in the file except the definitions of the previously undefined functions and the testing code at the bottom. When wrting the new functions, you may add helper methods or new parameters with default values if you wish. At the bottom of the supplied file is some indented code which is executed whenever you run the supplied file directly. This is a good place to do your testing. Write your test cases here so that I can see them. Leave all your testing code indented so that it only runs when __name__ == '__main__'. HERE IS hamt_hw.py # This implementation requires objects in the set be hashable. # Resulting trie will have expected log height if hash is random. # In this implementaiton the root node always has _item == None from functools import reduce class hamt: DEG = 4 # Children per node (can be set to any power of 2) BITS = 2 # Should be log2(DEG), bits needed to select child MASK = 0b11 # Should be BITS one-bits def __init__(self, item = None, children = None): self._item = item if children == None: self._children = [None] * hamt.DEG # List of DEG Nones else: self._children = children # returns copy of self node with child i set to node x
  • 2. def _updatechild(self, i, x): updatedchildlist = list(self._children) # copy self's child list updatedchildlist[i] = x # update child i return hamt(self._item, updatedchildlist) # build and return new node # Returns reference to new root if change made, else None def _add(self, item, hashbits): if self._item == item: # This node matches item. Return None to indicate no change. return None else: # Continue search using hashbits to pick direction child_num = hashbits & hamt.MASK if self._children[child_num] == None: # item not in trie. Add it as new leaf node. return self._updatechild(child_num, hamt(item)) else: # Ask appropriate child to add item, receive updated reference shiftedhashbits = hashbits >> hamt.BITS newchild = self._children[child_num]._add(item, shiftedhashbits) if newchild == None: return None else: return self._updatechild(child_num, newchild)
  • 3. def add(self, item): # Pass item and hashbits to private recursive helper return self._add(item, hash(item)) # Returns True if trie has no items, else False. Rutime O(1). def empty(self): pass # Returns True if item in trie, else False. Expected rutime O(log n). def contains(self, item): pass # Returns number of items in trie. Runtime O(n). def __len__(self): pass # Returns HAMT that is union of self and other. Expected rutime O(n log n). def union(self, other): pass # Adds self's item string to acc list, then ask each child to do the same def _str(self, acc): if self._item != None: # Don't do anything in fake root node acc.append(str(self._item)) for child in self._children: if child != None: child._str(acc) # Build list of all items in trie, then join them with ", " in between
  • 4. def __str__(self): acc = [] self._str(acc) return "{" + ", ".join(acc) + "}" # The following is a trick to make this testing code be ignored # when this file is being imported, but run when run directly # https://codefather.tech/blog/if-name-main-python/ if __name__ == '__main__': a = hamt() b = a.add("B") c = b.add("C") d = c.add("D") e = d.add("E") f = e.add("F") g = f.add("F") print(a) print(b) print(c) print(d) print(e) print(f)