SlideShare a Scribd company logo
1 of 6
Download to read offline
The hashtable you'll be making will use Strings as the keys and Object as the values. Similar to
linked lists, by storing Object as values, you can store any kind of object in the hashtable.
package Dictionary;
import java.util.ArrayList;
import java.util.Hashtable;
import List.ListInterface;
import List.MyLinkedList;
public class MyHashtable implements DictionaryInterface {
protected int tableSize;
protected int size;
// The LinkedList is of type Entry
protected MyLinkedList[] table;
public MyHashtable(int tableSize) {
table = new MyLinkedList[tableSize];
this.tableSize = tableSize;
}
public int biggestBucket()
{
int biggestBucket = 0;
for(int i = 0; i < table.length; i++) {
// Loop through the table looking for non-null locations.
if (table[i] != null) {
// If you find a non-null location, compare the bucket size against the largest
// bucket size found so far. If the current bucket size is bigger, set biggestBucket
// to this new size.
MyLinkedList bucket = table[i];
if (biggestBucket < bucket.size())
biggestBucket = bucket.size();
}
}
return biggestBucket; // Return the size of the biggest bucket found.
}
// Returns the average bucket length. Gives a sense of how many collisions are happening
overall.
public float averageBucket() {
float bucketCount = 0; // Number of buckets (non-null table locations)
float bucketSizeSum = 0; // Sum of the size of all buckets
for(int i = 0; i < table.length; i++) {
// Loop through the table
if (table[i] != null) {
// For a non-null location, increment the bucketCount and add to the bucketSizeSum
MyLinkedList bucket = table[i];
bucketSizeSum += bucket.size();
bucketCount++;
}
}
// Divide bucketSizeSum by the number of buckets to get an average bucket length.
return bucketSizeSum/bucketCount;
}
public String toString()
{
String s = "";
for(int tableIndex = 0; tableIndex < tableSize; tableIndex++) {
if (table[tableIndex] != null) {
MyLinkedList bucket = table[tableIndex];
for(int listIndex = 0; listIndex < bucket.size(); listIndex++) {
Entry e = (Entry)bucket.get(listIndex);
s = s + "key: " + e.key + ", value: " + e.value + "n";
}
}
}
return s;
}
protected class Entry
{
String key;
Object value;
Entry(String key, Object value) {
this.key = key;
this.value = value;
}
}
// Implement these methods
public boolean isEmpty() {return true;} // returns true if the Dictionary is empty, false otherwise.
public int size(){return -1;} //Returns the number of key/value pairs stored in the dictionary.
// Adds a value stored under the given key. If the key has already been stored in the Dictionary,
// replaces the value associated with the key and returns the old value. If the key isn't in the
dictionary
// returns null.
public Object put(String key, Object value){
// 1. Compute an array index given the key
// 2. If that location in the table is null,
// that means nothing has been previously stored using a key with this hash code.
// a. Create a new MyLinkedList to be the bucket.
// b. Add the new Entry for the key/value pair to the list.
// c. Set this location in the array equal to the new bucket (list).
// d. Increment the size (the number of unique keys you have stored).
// 3. If the location in the table isn't null,
// that means keys with this colliding hash code have been previously stored.
// 3a, a value exists for the key
// a. Linearly search through the bucket (the list) stored at this array
// location comparing the key for each entry with the key passed into put().
// If you get a match, this means this key as been previously stored.
// Save the old value in the Entry (so you can return it) and replace it with the new value.
// (use the code below)
// Entry oldValue = new Entry(key, e.value);
// e.value = value;
// NOTE: this is technically not correct as you would need to create a deep copy of the entry,
// however, that is outside the realm of this assignment. The code above will be
// enough to complete the assignment
// return old value here
// return oldValue.value;
// 3b, a value does not exist for the key
// b. If you don't find the key in the bucket,
// then just add a new Entry (with the key and value) to the beginning of the list.
// Increment the size.
return null;
}
public Object get(String key){
// 1. Compute an array index given the key
// 2. If that location in the table is null,
// that means nothing has been stored using a key with this hash code.
// So we can return null.
// 4. Linearly search through the bucket (the list),
// comparing the key for each entry with the key passed into get().
// Extracting each element in
// the Linked List
// If you find a match, return the value.
return null;
} // Retrieves the value stored with the key.
public void remove(String key){
// 1. Compute an array index given the key
// 2. If that location in the table is null, then this key has definitely not been used to store a value.
// 3. If the location in the table has a bucket,
// we need to linearly search it to see if it contains an Entry with the key.
// If you find an Entry in the bucket (linked list) with the key:
// a. Remove this Entry from the bucket.
// b. Decrement size (the number of unique keys stored in the hashtable).
} // Deletes the key/value pair stored with the given key.
public void clear(){} // Empties the dictionary.
public String[] getKeys(){
// 1. Create a String[] with a size equal to the number of unique keys in the hashtable
// 2. Iterate through the hashtable array.
// For each table location that isn't null
// a. Iterate though the bucket (linked list)
// getting the key out of each Entry and storing it in
// the array of strings you created in step 1.
// 3. Return the String[]
return null;
}
}

More Related Content

Similar to The hashtable youll be making will use Strings as the keys and Obje.pdf

Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfseoagam1
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxcgraciela1
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfinfo430661
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
 
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfclearvisioneyecareno
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdffootstatus
 
Describe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfDescribe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfdeepak596396
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfJamesPXNNewmanp
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxSHIVA101531
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfkingsandqueens3
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxalanfhall8953
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfallystraders
 
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfNote- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfAugstore
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfStewart29UReesa
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfstopgolook
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
 
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docxhoney725342
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfbabitasingh698417
 
Once you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxOnce you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxfarrahkur54
 

Similar to The hashtable youll be making will use Strings as the keys and Obje.pdf (20)

Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdf
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
 
Describe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfDescribe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdf
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docx
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdf
 
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfNote- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdf
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
 
Once you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxOnce you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docx
 

More from vicky309441

Topic Assembly Programming, Floating Point Operation (addition, sub.pdf
Topic Assembly Programming, Floating Point Operation (addition, sub.pdfTopic Assembly Programming, Floating Point Operation (addition, sub.pdf
Topic Assembly Programming, Floating Point Operation (addition, sub.pdfvicky309441
 
topic carrying capacity Will technological advancement enable us t.pdf
topic carrying capacity Will technological advancement enable us t.pdftopic carrying capacity Will technological advancement enable us t.pdf
topic carrying capacity Will technological advancement enable us t.pdfvicky309441
 
Tony decided to visit his parent in San Diego during the long weeken.pdf
Tony decided to visit his parent in San Diego during the long weeken.pdfTony decided to visit his parent in San Diego during the long weeken.pdf
Tony decided to visit his parent in San Diego during the long weeken.pdfvicky309441
 
Todo lo siguiente es cierto sobre la celulosa EXCEPTO (seleccione t.pdf
Todo lo siguiente es cierto sobre la celulosa EXCEPTO (seleccione t.pdfTodo lo siguiente es cierto sobre la celulosa EXCEPTO (seleccione t.pdf
Todo lo siguiente es cierto sobre la celulosa EXCEPTO (seleccione t.pdfvicky309441
 
Todas las siguientes afirmaciones sobre el riesgo son correctas EXCE.pdf
Todas las siguientes afirmaciones sobre el riesgo son correctas EXCE.pdfTodas las siguientes afirmaciones sobre el riesgo son correctas EXCE.pdf
Todas las siguientes afirmaciones sobre el riesgo son correctas EXCE.pdfvicky309441
 
Todas las siguientes son funciones del hipot�lamo, EXCEPTO pensami.pdf
Todas las siguientes son funciones del hipot�lamo, EXCEPTO pensami.pdfTodas las siguientes son funciones del hipot�lamo, EXCEPTO pensami.pdf
Todas las siguientes son funciones del hipot�lamo, EXCEPTO pensami.pdfvicky309441
 
Tipik bir pazar sepetinin fiyat 1960ta yaklak 20 dolardan 2012nin .pdf
Tipik bir pazar sepetinin fiyat 1960ta yaklak 20 dolardan 2012nin .pdfTipik bir pazar sepetinin fiyat 1960ta yaklak 20 dolardan 2012nin .pdf
Tipik bir pazar sepetinin fiyat 1960ta yaklak 20 dolardan 2012nin .pdfvicky309441
 
TiVo es una grabadora de video personaldigital (PVR o DVR) para tel.pdf
TiVo es una grabadora de video personaldigital (PVR o DVR) para tel.pdfTiVo es una grabadora de video personaldigital (PVR o DVR) para tel.pdf
TiVo es una grabadora de video personaldigital (PVR o DVR) para tel.pdfvicky309441
 
TNT International Company Context TNT International is a high-tech c.pdf
TNT International Company Context TNT International is a high-tech c.pdfTNT International Company Context TNT International is a high-tech c.pdf
TNT International Company Context TNT International is a high-tech c.pdfvicky309441
 
Tiene un nuevo trabajo para el Departamento de Defensa y llega 30 mi.pdf
Tiene un nuevo trabajo para el Departamento de Defensa y llega 30 mi.pdfTiene un nuevo trabajo para el Departamento de Defensa y llega 30 mi.pdf
Tiene un nuevo trabajo para el Departamento de Defensa y llega 30 mi.pdfvicky309441
 
Tiffany is a cash basis taxpayer whose records show the following.pdf
Tiffany is a cash basis taxpayer whose records show the following.pdfTiffany is a cash basis taxpayer whose records show the following.pdf
Tiffany is a cash basis taxpayer whose records show the following.pdfvicky309441
 
This is the subject of Business Ethics and Corporate Social Responsi.pdf
This is the subject of Business Ethics and Corporate Social Responsi.pdfThis is the subject of Business Ethics and Corporate Social Responsi.pdf
This is the subject of Business Ethics and Corporate Social Responsi.pdfvicky309441
 
There is considerable evidence that Coronavirus 19 arose in nonhuman.pdf
There is considerable evidence that Coronavirus 19 arose in nonhuman.pdfThere is considerable evidence that Coronavirus 19 arose in nonhuman.pdf
There is considerable evidence that Coronavirus 19 arose in nonhuman.pdfvicky309441
 
There are two fundamental reasons for a manager to obtain and unders.pdf
There are two fundamental reasons for a manager to obtain and unders.pdfThere are two fundamental reasons for a manager to obtain and unders.pdf
There are two fundamental reasons for a manager to obtain and unders.pdfvicky309441
 
These points should be integrated into your Analysis (1) Company�s.pdf
These points should be integrated into your Analysis  (1) Company�s.pdfThese points should be integrated into your Analysis  (1) Company�s.pdf
These points should be integrated into your Analysis (1) Company�s.pdfvicky309441
 
The project idea is about identifying specific a opportunity or prob.pdf
The project idea is about identifying specific a opportunity or prob.pdfThe project idea is about identifying specific a opportunity or prob.pdf
The project idea is about identifying specific a opportunity or prob.pdfvicky309441
 
The systematic risks that are impacted by the firm�s operations an.pdf
The systematic risks that are impacted by the firm�s operations an.pdfThe systematic risks that are impacted by the firm�s operations an.pdf
The systematic risks that are impacted by the firm�s operations an.pdfvicky309441
 
The substances which are recognized by the immune system as being fo.pdf
The substances which are recognized by the immune system as being fo.pdfThe substances which are recognized by the immune system as being fo.pdf
The substances which are recognized by the immune system as being fo.pdfvicky309441
 
The Solar System SP23. Credibility and ReliabilityIn todays inter.pdf
The Solar System SP23. Credibility and ReliabilityIn todays inter.pdfThe Solar System SP23. Credibility and ReliabilityIn todays inter.pdf
The Solar System SP23. Credibility and ReliabilityIn todays inter.pdfvicky309441
 
The SEC amended its NYSE standards so that listed companies must m.pdf
The SEC amended its NYSE standards so that listed companies must m.pdfThe SEC amended its NYSE standards so that listed companies must m.pdf
The SEC amended its NYSE standards so that listed companies must m.pdfvicky309441
 

More from vicky309441 (20)

Topic Assembly Programming, Floating Point Operation (addition, sub.pdf
Topic Assembly Programming, Floating Point Operation (addition, sub.pdfTopic Assembly Programming, Floating Point Operation (addition, sub.pdf
Topic Assembly Programming, Floating Point Operation (addition, sub.pdf
 
topic carrying capacity Will technological advancement enable us t.pdf
topic carrying capacity Will technological advancement enable us t.pdftopic carrying capacity Will technological advancement enable us t.pdf
topic carrying capacity Will technological advancement enable us t.pdf
 
Tony decided to visit his parent in San Diego during the long weeken.pdf
Tony decided to visit his parent in San Diego during the long weeken.pdfTony decided to visit his parent in San Diego during the long weeken.pdf
Tony decided to visit his parent in San Diego during the long weeken.pdf
 
Todo lo siguiente es cierto sobre la celulosa EXCEPTO (seleccione t.pdf
Todo lo siguiente es cierto sobre la celulosa EXCEPTO (seleccione t.pdfTodo lo siguiente es cierto sobre la celulosa EXCEPTO (seleccione t.pdf
Todo lo siguiente es cierto sobre la celulosa EXCEPTO (seleccione t.pdf
 
Todas las siguientes afirmaciones sobre el riesgo son correctas EXCE.pdf
Todas las siguientes afirmaciones sobre el riesgo son correctas EXCE.pdfTodas las siguientes afirmaciones sobre el riesgo son correctas EXCE.pdf
Todas las siguientes afirmaciones sobre el riesgo son correctas EXCE.pdf
 
Todas las siguientes son funciones del hipot�lamo, EXCEPTO pensami.pdf
Todas las siguientes son funciones del hipot�lamo, EXCEPTO pensami.pdfTodas las siguientes son funciones del hipot�lamo, EXCEPTO pensami.pdf
Todas las siguientes son funciones del hipot�lamo, EXCEPTO pensami.pdf
 
Tipik bir pazar sepetinin fiyat 1960ta yaklak 20 dolardan 2012nin .pdf
Tipik bir pazar sepetinin fiyat 1960ta yaklak 20 dolardan 2012nin .pdfTipik bir pazar sepetinin fiyat 1960ta yaklak 20 dolardan 2012nin .pdf
Tipik bir pazar sepetinin fiyat 1960ta yaklak 20 dolardan 2012nin .pdf
 
TiVo es una grabadora de video personaldigital (PVR o DVR) para tel.pdf
TiVo es una grabadora de video personaldigital (PVR o DVR) para tel.pdfTiVo es una grabadora de video personaldigital (PVR o DVR) para tel.pdf
TiVo es una grabadora de video personaldigital (PVR o DVR) para tel.pdf
 
TNT International Company Context TNT International is a high-tech c.pdf
TNT International Company Context TNT International is a high-tech c.pdfTNT International Company Context TNT International is a high-tech c.pdf
TNT International Company Context TNT International is a high-tech c.pdf
 
Tiene un nuevo trabajo para el Departamento de Defensa y llega 30 mi.pdf
Tiene un nuevo trabajo para el Departamento de Defensa y llega 30 mi.pdfTiene un nuevo trabajo para el Departamento de Defensa y llega 30 mi.pdf
Tiene un nuevo trabajo para el Departamento de Defensa y llega 30 mi.pdf
 
Tiffany is a cash basis taxpayer whose records show the following.pdf
Tiffany is a cash basis taxpayer whose records show the following.pdfTiffany is a cash basis taxpayer whose records show the following.pdf
Tiffany is a cash basis taxpayer whose records show the following.pdf
 
This is the subject of Business Ethics and Corporate Social Responsi.pdf
This is the subject of Business Ethics and Corporate Social Responsi.pdfThis is the subject of Business Ethics and Corporate Social Responsi.pdf
This is the subject of Business Ethics and Corporate Social Responsi.pdf
 
There is considerable evidence that Coronavirus 19 arose in nonhuman.pdf
There is considerable evidence that Coronavirus 19 arose in nonhuman.pdfThere is considerable evidence that Coronavirus 19 arose in nonhuman.pdf
There is considerable evidence that Coronavirus 19 arose in nonhuman.pdf
 
There are two fundamental reasons for a manager to obtain and unders.pdf
There are two fundamental reasons for a manager to obtain and unders.pdfThere are two fundamental reasons for a manager to obtain and unders.pdf
There are two fundamental reasons for a manager to obtain and unders.pdf
 
These points should be integrated into your Analysis (1) Company�s.pdf
These points should be integrated into your Analysis  (1) Company�s.pdfThese points should be integrated into your Analysis  (1) Company�s.pdf
These points should be integrated into your Analysis (1) Company�s.pdf
 
The project idea is about identifying specific a opportunity or prob.pdf
The project idea is about identifying specific a opportunity or prob.pdfThe project idea is about identifying specific a opportunity or prob.pdf
The project idea is about identifying specific a opportunity or prob.pdf
 
The systematic risks that are impacted by the firm�s operations an.pdf
The systematic risks that are impacted by the firm�s operations an.pdfThe systematic risks that are impacted by the firm�s operations an.pdf
The systematic risks that are impacted by the firm�s operations an.pdf
 
The substances which are recognized by the immune system as being fo.pdf
The substances which are recognized by the immune system as being fo.pdfThe substances which are recognized by the immune system as being fo.pdf
The substances which are recognized by the immune system as being fo.pdf
 
The Solar System SP23. Credibility and ReliabilityIn todays inter.pdf
The Solar System SP23. Credibility and ReliabilityIn todays inter.pdfThe Solar System SP23. Credibility and ReliabilityIn todays inter.pdf
The Solar System SP23. Credibility and ReliabilityIn todays inter.pdf
 
The SEC amended its NYSE standards so that listed companies must m.pdf
The SEC amended its NYSE standards so that listed companies must m.pdfThe SEC amended its NYSE standards so that listed companies must m.pdf
The SEC amended its NYSE standards so that listed companies must m.pdf
 

Recently uploaded

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 

Recently uploaded (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 

The hashtable youll be making will use Strings as the keys and Obje.pdf

  • 1. The hashtable you'll be making will use Strings as the keys and Object as the values. Similar to linked lists, by storing Object as values, you can store any kind of object in the hashtable. package Dictionary; import java.util.ArrayList; import java.util.Hashtable; import List.ListInterface; import List.MyLinkedList; public class MyHashtable implements DictionaryInterface { protected int tableSize; protected int size; // The LinkedList is of type Entry protected MyLinkedList[] table; public MyHashtable(int tableSize) { table = new MyLinkedList[tableSize]; this.tableSize = tableSize; } public int biggestBucket() { int biggestBucket = 0; for(int i = 0; i < table.length; i++) { // Loop through the table looking for non-null locations. if (table[i] != null) { // If you find a non-null location, compare the bucket size against the largest // bucket size found so far. If the current bucket size is bigger, set biggestBucket // to this new size. MyLinkedList bucket = table[i]; if (biggestBucket < bucket.size()) biggestBucket = bucket.size();
  • 2. } } return biggestBucket; // Return the size of the biggest bucket found. } // Returns the average bucket length. Gives a sense of how many collisions are happening overall. public float averageBucket() { float bucketCount = 0; // Number of buckets (non-null table locations) float bucketSizeSum = 0; // Sum of the size of all buckets for(int i = 0; i < table.length; i++) { // Loop through the table if (table[i] != null) { // For a non-null location, increment the bucketCount and add to the bucketSizeSum MyLinkedList bucket = table[i]; bucketSizeSum += bucket.size(); bucketCount++; } } // Divide bucketSizeSum by the number of buckets to get an average bucket length. return bucketSizeSum/bucketCount; } public String toString() { String s = ""; for(int tableIndex = 0; tableIndex < tableSize; tableIndex++) { if (table[tableIndex] != null) { MyLinkedList bucket = table[tableIndex]; for(int listIndex = 0; listIndex < bucket.size(); listIndex++) { Entry e = (Entry)bucket.get(listIndex); s = s + "key: " + e.key + ", value: " + e.value + "n"; } } }
  • 3. return s; } protected class Entry { String key; Object value; Entry(String key, Object value) { this.key = key; this.value = value; } } // Implement these methods public boolean isEmpty() {return true;} // returns true if the Dictionary is empty, false otherwise. public int size(){return -1;} //Returns the number of key/value pairs stored in the dictionary. // Adds a value stored under the given key. If the key has already been stored in the Dictionary, // replaces the value associated with the key and returns the old value. If the key isn't in the dictionary // returns null. public Object put(String key, Object value){ // 1. Compute an array index given the key // 2. If that location in the table is null, // that means nothing has been previously stored using a key with this hash code. // a. Create a new MyLinkedList to be the bucket. // b. Add the new Entry for the key/value pair to the list. // c. Set this location in the array equal to the new bucket (list). // d. Increment the size (the number of unique keys you have stored).
  • 4. // 3. If the location in the table isn't null, // that means keys with this colliding hash code have been previously stored. // 3a, a value exists for the key // a. Linearly search through the bucket (the list) stored at this array // location comparing the key for each entry with the key passed into put(). // If you get a match, this means this key as been previously stored. // Save the old value in the Entry (so you can return it) and replace it with the new value. // (use the code below) // Entry oldValue = new Entry(key, e.value); // e.value = value; // NOTE: this is technically not correct as you would need to create a deep copy of the entry, // however, that is outside the realm of this assignment. The code above will be // enough to complete the assignment // return old value here // return oldValue.value; // 3b, a value does not exist for the key // b. If you don't find the key in the bucket, // then just add a new Entry (with the key and value) to the beginning of the list. // Increment the size. return null; } public Object get(String key){ // 1. Compute an array index given the key // 2. If that location in the table is null,
  • 5. // that means nothing has been stored using a key with this hash code. // So we can return null. // 4. Linearly search through the bucket (the list), // comparing the key for each entry with the key passed into get(). // Extracting each element in // the Linked List // If you find a match, return the value. return null; } // Retrieves the value stored with the key. public void remove(String key){ // 1. Compute an array index given the key // 2. If that location in the table is null, then this key has definitely not been used to store a value. // 3. If the location in the table has a bucket, // we need to linearly search it to see if it contains an Entry with the key. // If you find an Entry in the bucket (linked list) with the key: // a. Remove this Entry from the bucket. // b. Decrement size (the number of unique keys stored in the hashtable). } // Deletes the key/value pair stored with the given key. public void clear(){} // Empties the dictionary. public String[] getKeys(){ // 1. Create a String[] with a size equal to the number of unique keys in the hashtable // 2. Iterate through the hashtable array.
  • 6. // For each table location that isn't null // a. Iterate though the bucket (linked list) // getting the key out of each Entry and storing it in // the array of strings you created in step 1. // 3. Return the String[] return null; } }