SlideShare a Scribd company logo
1 of 11
Download to read offline
using the code below write the public V add(K key, V value); that adds a new entry into
hashtable if the table (hashTable[index] != null) && (hashTable[index] != AVAILABLE
if the key is the same as keyindex inside the hash replace the old value with the new value
if the key is different from the keyindex go to the next index and count for collisions until will
you find a null space inside the hashtable index
import java.util.Iterator;
public interface DictionaryInterface
{
/** Adds a new entry to this dictionary. If the given search key already
exists in the dictionary, replaces the corresponding value.
@param key An object search key of the new entry.
@param value An object associated with the search key.
@return Either null if the new entry was added to the dictionary
or the value that was associated with key if that value
was replaced. */
public V add(K key, V value);
/** Removes a specific entry from this dictionary.
@param key An object search key of the entry to be removed.
@return Either the value that was associated with the search key
or null if no such object exists. */
public V remove(K key);
/** Retrieves from this dictionary the value associated with a given
search key.
@param key An object search key of the entry to be retrieved.
@return Either the value that is associated with the search key
or null if no such object exists. */
public V getValue(K key);
/** Sees whether a specific entry is in this dictionary.
@param key An object search key of the desired entry.
@return True if key is associated with an entry in the dictionary. */
public boolean contains(K key);
/** Creates an iterator that traverses all search keys in this dictionary.
@return An iterator that provides sequential access to the search
keys in the dictionary. */
public Iterator getKeyIterator();
/** Creates an iterator that traverses all values in this dictionary.
@return An iterator that provides sequential access to the values
in this dictionary. */
public Iterator getValueIterator();
/** Sees whether this dictionary is empty.
@return True if the dictionary is empty. */
public boolean isEmpty();
/** Gets the size of this dictionary.
@return The number of entries (key-value pairs) currently
in the dictionary. */
public int getSize();
/** Removes all entries from this dictionary. */
public void clear();
} // end DictionaryInterface
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* A class that implements the ADT dictionary by using hashing and
* linear probing to resolve collisions.
* The dictionary is unsorted and has distinct search key.
Search keys and associated values are not null.
*/
public class HashedDictionary implements DictionaryInterface
{
// The dictionary:
private int numberOfEntries;
private static final int DEFAULT_CAPACITY = 5; // Must be prime
private static final int MAX_CAPACITY = 10000;
// The hash table:
private Entry[] hashTable;
private int tableSize; // Must be prime
private static final int MAX_SIZE = 2 * MAX_CAPACITY;
private boolean integrityOK = false;
private static final double MAX_LOAD_FACTOR = 0.5; // Fraction of
// hash table that can be filled
private int collisionCount;
protected final Entry AVAILABLE = new Entry<>(null, null);
// Counter to keep track of collisions
public HashedDictionary()
{
this(DEFAULT_CAPACITY); // Call next constructor
} // end default constructor
public HashedDictionary(int initialCapacity)
{
initialCapacity = checkCapacity(initialCapacity);
numberOfEntries = 0; // Dictionary is empty
// Set up hash table:
// Initial size of hash table is same as initialCapacity if it is prime;
// otherwise increase it until it is prime size
tableSize = getNextPrime(initialCapacity);
checkSize(tableSize); // Check that size is not too large
// The cast is safe because the new array contains null entries
@SuppressWarnings("unchecked")
Entry[] temp = (Entry[])new Entry[tableSize];
hashTable = temp;
integrityOK = true;
collisionCount = 0;
} // end constructor
/* Implementations of methods in DictionaryInterface are here. . . .*/
public V add(K key, V value)
{//CODE IMPLEMENTATION
}//end of add
public boolean isEmpty()
{
return this.numberOfEntries == 0;
}//end isEmpty
public Iterator getValueIterator()
{
throw new NoSuchElementException("Value Iterator Not Implemented");
}//end valueIterator
public void clear()
{
checkIntegrity();
for (int index = 0; index < this.hashTable.length; index++)
{
hashTable[index] = null;
}//end of for
this.numberOfEntries = 0;
}//end clear
public Iterator getKeyIterator()
{
return new KeyIterator();
}//end iterator
public boolean contains(K key)
{
return getValue(key) != null;
}//end contains
public int getSize()
{
return this.numberOfEntries;
}//end getSize
public V remove(K key) {
checkIntegrity();
int index = getHashIndex(key);
while (hashTable[index] != null) {
if (hashTable[index].getKey().equals(key)) {
V value = hashTable[index].getValue();
hashTable[index].setValue(null);
hashTable[index] = AVAILABLE;
numberOfEntries--;
return value;
}
index = (index + 1) % hashTable.length;
}
// If the key is not found, return null
return null;
}
public V getValue(K key)
{
checkIntegrity();
V result = null;
int index = getHashIndex(key);
if ((hashTable[index] != null) && (hashTable[index] != AVAILABLE))
result = hashTable[index].getValue(); // Key found; get value
// Else key not found; return null
return result;
} // end getValue
/* END of Implementations of dictionary methods are here^. . . . */
/* Implementations of private methods are here. . . . */
//precondition: checkIntegrity has been called
private void enlargeHashTable()
{
Entry[] oldTable = hashTable;
int oldSize = hashTable.length;
int newSize = getNextPrime(oldSize + oldSize);
checkSize(newSize);
//The cast is safe because the new array contains null entries
@SuppressWarnings("unchecked")
Entry[] temp = (Entry[]) new Entry[newSize];
hashTable = temp;
numberOfEntries = 0;//reset number of dictionary entries, since it will be incremented by add
during rehash
//rehash dictionary entries from old array to the new and bigger array;
//skip elements that contain null or available
for(int index = 0; index < oldSize; index++)
{
if((oldTable[index] != null) && (oldTable[index] != AVAILABLE))
{
add(oldTable[index].getKey(), oldTable[index].getValue());
}
}// end for
}//end enlargeHashTable
private int getHashIndex(K key)
{
int hashIndex = key.hashCode() % hashTable.length;
if(hashIndex < 0)
{
hashIndex = hashIndex + hashTable.length;
}
return hashIndex;
}//end getHashIndex
private void checkIntegrity()
{
if(!integrityOK)
{
throw new SecurityException("objecy is currupt");
}
}//end checkIntegrity
private boolean isHashTableTooFull()
{
if((numberOfEntries / hashTable.length) >= MAX_LOAD_FACTOR)
{
return true;
}
else
{
return false;
}
}//end isHashTableTooFull
private int checkSize(int size)
{
if(size >= MAX_SIZE){throw new IllegalStateException("Dictionary has become too large.");}
else{return size;}
}//end checksize
private int checkCapacity(int cap)
{
if(cap < DEFAULT_CAPACITY)
{
cap = DEFAULT_CAPACITY;
}
else if (cap > MAX_CAPACITY)
{
throw new IllegalStateException("Attempt to create a dictionary " + "whose capacity is larger
than " + MAX_CAPACITY);
}
return cap;
}//end checkcap
private int getNextPrime(int integer)
{
// if even, add 1 to make od
if (integer % 2 == 0)
{
integer++;
} // end if
// test odd integers
while (!isPrime(integer))
{
integer = integer + 2;
} // end while
return integer;
}//end getnextprime
private boolean isPrime(int integer)
{
boolean result;
boolean done = false;
// 1 and even numbers are not prime
if ( (integer == 1) || (integer % 2 == 0) )
{
result = false;
}
// 2 and 3 are prime
else if ( (integer == 2) || (integer == 3) )
{
result = true;
}
else // integer is odd and >= 5
{
assert (integer % 2 != 0) && (integer >= 5);
// a prime is odd and not divisible by every odd integer up to its square root
result = true; // assume prime
for (int divisor = 3; !done && (divisor * divisor <= integer); divisor = divisor + 2)
{
if (integer % divisor == 0)
{
result = false; // divisible; not prime
done = true;
} // end if
} // end for
} // end if
return result;
} // end isPrime
/* END of Implementations of private methods are here^. . . . */
protected final class Entry
{
private K key;
private V value;
private Entry(K searchKey, V dataValue)
{
key = searchKey;
value = dataValue;
}//end contructor
private K getKey()
{
return key;
}//end getKey
private V getValue()
{
return value;
}//end value
private void setValue(V newValue)
{
value = newValue;
}//end setValue
} // end Entry
private class KeyIterator implements Iterator
{
private int currentIndex; // Current position in hash table
private int numberLeft; // Number of entries left in iteration
private KeyIterator()
{
currentIndex = 0;
numberLeft = numberOfEntries;
} // end default constructor
public boolean hasNext()
{
return numberLeft > 0;
} // end hasNext
public void remove()
{
throw new UnsupportedOperationException();
} // end remove
public K next()
{
K result = null;
if (hasNext())
{
// Skip table locations that do not contain a current entry
while ( (hashTable[currentIndex] == null) ||
(hashTable[currentIndex] == AVAILABLE) )
{
currentIndex++;
} // end while
result = hashTable[currentIndex].getKey();
numberLeft--;
currentIndex++;
}
else
throw new NoSuchElementException();
return result;
} // end next
} // end KeyIterator
//collision method
public int getCollisionCount() {
return collisionCount;
}//end collisionCount
} // end HashedDictionary

More Related Content

Similar to using the code below write the public V add(K key, V value); that ad.pdf

Program 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdfProgram 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdfezzi552
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfaksahnan
 
Describe a data structure to represent sets of elements (each element.pdf
Describe a data structure to represent sets of elements (each element.pdfDescribe a data structure to represent sets of elements (each element.pdf
Describe a data structure to represent sets of elements (each element.pdfrajeshjain2109
 
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
 
This file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfThis file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfdeepaksatrker
 
This project will implement a simple usernamepassword lookup system.pdf
This project will implement a simple usernamepassword lookup system.pdfThis project will implement a simple usernamepassword lookup system.pdf
This project will implement a simple usernamepassword lookup system.pdfezhilvizhiyan
 
this file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.pdfthis file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.pdfflashfashioncasualwe
 
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
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxcurwenmichaela
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxStewartt0kJohnstonh
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 
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
 
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxandreecapon
 
all i need is these two filesCreate VectorContainer.hppCreat.docx
all i need is these two filesCreate VectorContainer.hppCreat.docxall i need is these two filesCreate VectorContainer.hppCreat.docx
all i need is these two filesCreate VectorContainer.hppCreat.docxjack60216
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdffantasiatheoutofthef
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdffmac5
 

Similar to using the code below write the public V add(K key, V value); that ad.pdf (20)

Program 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdfProgram 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdf
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
Describe a data structure to represent sets of elements (each element.pdf
Describe a data structure to represent sets of elements (each element.pdfDescribe a data structure to represent sets of elements (each element.pdf
Describe a data structure to represent sets of elements (each element.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).pdf
 
This file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfThis file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdf
 
This project will implement a simple usernamepassword lookup system.pdf
This project will implement a simple usernamepassword lookup system.pdfThis project will implement a simple usernamepassword lookup system.pdf
This project will implement a simple usernamepassword lookup system.pdf
 
this file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.pdfthis file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.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
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
 
AutoComplete
AutoCompleteAutoComplete
AutoComplete
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.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
 
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
 
all i need is these two filesCreate VectorContainer.hppCreat.docx
all i need is these two filesCreate VectorContainer.hppCreat.docxall i need is these two filesCreate VectorContainer.hppCreat.docx
all i need is these two filesCreate VectorContainer.hppCreat.docx
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
 

More from amirthagiftsmadurai

value if lifo for its inverntory. the inventory on12312020 was $70.pdf
value if lifo for its inverntory. the inventory on12312020 was $70.pdfvalue if lifo for its inverntory. the inventory on12312020 was $70.pdf
value if lifo for its inverntory. the inventory on12312020 was $70.pdfamirthagiftsmadurai
 
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdf
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdfUtilizando los datos comerciales del Observatorio de Complejidad Eco.pdf
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdfamirthagiftsmadurai
 
Usted es accionista del 5 de Company XYZ, Inc. La compa��a planea .pdf
Usted es accionista del 5  de Company XYZ, Inc. La compa��a planea .pdfUsted es accionista del 5  de Company XYZ, Inc. La compa��a planea .pdf
Usted es accionista del 5 de Company XYZ, Inc. La compa��a planea .pdfamirthagiftsmadurai
 
Using this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdfUsing this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdfamirthagiftsmadurai
 
using the the periodic method what is the journal entryusing th.pdf
using the the periodic method what is the journal entryusing th.pdfusing the the periodic method what is the journal entryusing th.pdf
using the the periodic method what is the journal entryusing th.pdfamirthagiftsmadurai
 
Using the properties of Regular languages, mention which properties .pdf
Using the properties of Regular languages, mention which properties .pdfUsing the properties of Regular languages, mention which properties .pdf
Using the properties of Regular languages, mention which properties .pdfamirthagiftsmadurai
 
Using the information displayed on the table below, calculate the Un.pdf
Using the information displayed on the table below, calculate the Un.pdfUsing the information displayed on the table below, calculate the Un.pdf
Using the information displayed on the table below, calculate the Un.pdfamirthagiftsmadurai
 
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfUsing the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfamirthagiftsmadurai
 
Using the accidentdata dataset how to conduct a comprehensive EDA .pdf
Using the accidentdata dataset  how to conduct a comprehensive EDA .pdfUsing the accidentdata dataset  how to conduct a comprehensive EDA .pdf
Using the accidentdata dataset how to conduct a comprehensive EDA .pdfamirthagiftsmadurai
 
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdfVuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdfamirthagiftsmadurai
 
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdfVuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdfamirthagiftsmadurai
 
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdfWe aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdfamirthagiftsmadurai
 
Verdadero o falso 7. Los errores son errores no intencionales. .pdf
Verdadero o falso 7. Los errores son errores no intencionales. .pdfVerdadero o falso 7. Los errores son errores no intencionales. .pdf
Verdadero o falso 7. Los errores son errores no intencionales. .pdfamirthagiftsmadurai
 
Verdadero o falso todas las especies, independientemente de los tax.pdf
Verdadero o falso todas las especies, independientemente de los tax.pdfVerdadero o falso todas las especies, independientemente de los tax.pdf
Verdadero o falso todas las especies, independientemente de los tax.pdfamirthagiftsmadurai
 
Warren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdfWarren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdfamirthagiftsmadurai
 
Watch Podcast SpanxWrite a response to the podcast using the cor.pdf
Watch Podcast SpanxWrite a response to the podcast using the cor.pdfWatch Podcast SpanxWrite a response to the podcast using the cor.pdf
Watch Podcast SpanxWrite a response to the podcast using the cor.pdfamirthagiftsmadurai
 
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdfVincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdfamirthagiftsmadurai
 
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdfWanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdfamirthagiftsmadurai
 
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdfW1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdfamirthagiftsmadurai
 
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdfVerdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdfamirthagiftsmadurai
 

More from amirthagiftsmadurai (20)

value if lifo for its inverntory. the inventory on12312020 was $70.pdf
value if lifo for its inverntory. the inventory on12312020 was $70.pdfvalue if lifo for its inverntory. the inventory on12312020 was $70.pdf
value if lifo for its inverntory. the inventory on12312020 was $70.pdf
 
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdf
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdfUtilizando los datos comerciales del Observatorio de Complejidad Eco.pdf
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdf
 
Usted es accionista del 5 de Company XYZ, Inc. La compa��a planea .pdf
Usted es accionista del 5  de Company XYZ, Inc. La compa��a planea .pdfUsted es accionista del 5  de Company XYZ, Inc. La compa��a planea .pdf
Usted es accionista del 5 de Company XYZ, Inc. La compa��a planea .pdf
 
Using this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdfUsing this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdf
 
using the the periodic method what is the journal entryusing th.pdf
using the the periodic method what is the journal entryusing th.pdfusing the the periodic method what is the journal entryusing th.pdf
using the the periodic method what is the journal entryusing th.pdf
 
Using the properties of Regular languages, mention which properties .pdf
Using the properties of Regular languages, mention which properties .pdfUsing the properties of Regular languages, mention which properties .pdf
Using the properties of Regular languages, mention which properties .pdf
 
Using the information displayed on the table below, calculate the Un.pdf
Using the information displayed on the table below, calculate the Un.pdfUsing the information displayed on the table below, calculate the Un.pdf
Using the information displayed on the table below, calculate the Un.pdf
 
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfUsing the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
 
Using the accidentdata dataset how to conduct a comprehensive EDA .pdf
Using the accidentdata dataset  how to conduct a comprehensive EDA .pdfUsing the accidentdata dataset  how to conduct a comprehensive EDA .pdf
Using the accidentdata dataset how to conduct a comprehensive EDA .pdf
 
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdfVuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
 
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdfVuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
 
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdfWe aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
 
Verdadero o falso 7. Los errores son errores no intencionales. .pdf
Verdadero o falso 7. Los errores son errores no intencionales. .pdfVerdadero o falso 7. Los errores son errores no intencionales. .pdf
Verdadero o falso 7. Los errores son errores no intencionales. .pdf
 
Verdadero o falso todas las especies, independientemente de los tax.pdf
Verdadero o falso todas las especies, independientemente de los tax.pdfVerdadero o falso todas las especies, independientemente de los tax.pdf
Verdadero o falso todas las especies, independientemente de los tax.pdf
 
Warren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdfWarren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdf
 
Watch Podcast SpanxWrite a response to the podcast using the cor.pdf
Watch Podcast SpanxWrite a response to the podcast using the cor.pdfWatch Podcast SpanxWrite a response to the podcast using the cor.pdf
Watch Podcast SpanxWrite a response to the podcast using the cor.pdf
 
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdfVincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
 
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdfWanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
 
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdfW1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
 
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdfVerdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
 

Recently uploaded

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

using the code below write the public V add(K key, V value); that ad.pdf

  • 1. using the code below write the public V add(K key, V value); that adds a new entry into hashtable if the table (hashTable[index] != null) && (hashTable[index] != AVAILABLE if the key is the same as keyindex inside the hash replace the old value with the new value if the key is different from the keyindex go to the next index and count for collisions until will you find a null space inside the hashtable index import java.util.Iterator; public interface DictionaryInterface { /** Adds a new entry to this dictionary. If the given search key already exists in the dictionary, replaces the corresponding value. @param key An object search key of the new entry. @param value An object associated with the search key. @return Either null if the new entry was added to the dictionary or the value that was associated with key if that value was replaced. */ public V add(K key, V value); /** Removes a specific entry from this dictionary. @param key An object search key of the entry to be removed. @return Either the value that was associated with the search key or null if no such object exists. */ public V remove(K key); /** Retrieves from this dictionary the value associated with a given search key. @param key An object search key of the entry to be retrieved. @return Either the value that is associated with the search key or null if no such object exists. */ public V getValue(K key); /** Sees whether a specific entry is in this dictionary. @param key An object search key of the desired entry. @return True if key is associated with an entry in the dictionary. */ public boolean contains(K key);
  • 2. /** Creates an iterator that traverses all search keys in this dictionary. @return An iterator that provides sequential access to the search keys in the dictionary. */ public Iterator getKeyIterator(); /** Creates an iterator that traverses all values in this dictionary. @return An iterator that provides sequential access to the values in this dictionary. */ public Iterator getValueIterator(); /** Sees whether this dictionary is empty. @return True if the dictionary is empty. */ public boolean isEmpty(); /** Gets the size of this dictionary. @return The number of entries (key-value pairs) currently in the dictionary. */ public int getSize(); /** Removes all entries from this dictionary. */ public void clear(); } // end DictionaryInterface import java.util.Iterator; import java.util.NoSuchElementException; /** * A class that implements the ADT dictionary by using hashing and * linear probing to resolve collisions. * The dictionary is unsorted and has distinct search key. Search keys and associated values are not null. */ public class HashedDictionary implements DictionaryInterface { // The dictionary: private int numberOfEntries; private static final int DEFAULT_CAPACITY = 5; // Must be prime private static final int MAX_CAPACITY = 10000; // The hash table: private Entry[] hashTable; private int tableSize; // Must be prime
  • 3. private static final int MAX_SIZE = 2 * MAX_CAPACITY; private boolean integrityOK = false; private static final double MAX_LOAD_FACTOR = 0.5; // Fraction of // hash table that can be filled private int collisionCount; protected final Entry AVAILABLE = new Entry<>(null, null); // Counter to keep track of collisions public HashedDictionary() { this(DEFAULT_CAPACITY); // Call next constructor } // end default constructor public HashedDictionary(int initialCapacity) { initialCapacity = checkCapacity(initialCapacity); numberOfEntries = 0; // Dictionary is empty // Set up hash table: // Initial size of hash table is same as initialCapacity if it is prime; // otherwise increase it until it is prime size tableSize = getNextPrime(initialCapacity); checkSize(tableSize); // Check that size is not too large // The cast is safe because the new array contains null entries @SuppressWarnings("unchecked") Entry[] temp = (Entry[])new Entry[tableSize]; hashTable = temp; integrityOK = true; collisionCount = 0; } // end constructor /* Implementations of methods in DictionaryInterface are here. . . .*/
  • 4. public V add(K key, V value) {//CODE IMPLEMENTATION }//end of add public boolean isEmpty() { return this.numberOfEntries == 0; }//end isEmpty public Iterator getValueIterator() { throw new NoSuchElementException("Value Iterator Not Implemented"); }//end valueIterator public void clear() { checkIntegrity(); for (int index = 0; index < this.hashTable.length; index++) { hashTable[index] = null; }//end of for this.numberOfEntries = 0; }//end clear public Iterator getKeyIterator() { return new KeyIterator(); }//end iterator public boolean contains(K key) { return getValue(key) != null; }//end contains public int getSize() {
  • 5. return this.numberOfEntries; }//end getSize public V remove(K key) { checkIntegrity(); int index = getHashIndex(key); while (hashTable[index] != null) { if (hashTable[index].getKey().equals(key)) { V value = hashTable[index].getValue(); hashTable[index].setValue(null); hashTable[index] = AVAILABLE; numberOfEntries--; return value; } index = (index + 1) % hashTable.length; } // If the key is not found, return null return null; } public V getValue(K key) { checkIntegrity(); V result = null; int index = getHashIndex(key); if ((hashTable[index] != null) && (hashTable[index] != AVAILABLE)) result = hashTable[index].getValue(); // Key found; get value // Else key not found; return null return result; } // end getValue /* END of Implementations of dictionary methods are here^. . . . */
  • 6. /* Implementations of private methods are here. . . . */ //precondition: checkIntegrity has been called private void enlargeHashTable() { Entry[] oldTable = hashTable; int oldSize = hashTable.length; int newSize = getNextPrime(oldSize + oldSize); checkSize(newSize); //The cast is safe because the new array contains null entries @SuppressWarnings("unchecked") Entry[] temp = (Entry[]) new Entry[newSize]; hashTable = temp; numberOfEntries = 0;//reset number of dictionary entries, since it will be incremented by add during rehash //rehash dictionary entries from old array to the new and bigger array; //skip elements that contain null or available for(int index = 0; index < oldSize; index++) { if((oldTable[index] != null) && (oldTable[index] != AVAILABLE)) { add(oldTable[index].getKey(), oldTable[index].getValue()); } }// end for }//end enlargeHashTable private int getHashIndex(K key) { int hashIndex = key.hashCode() % hashTable.length; if(hashIndex < 0) { hashIndex = hashIndex + hashTable.length;
  • 7. } return hashIndex; }//end getHashIndex private void checkIntegrity() { if(!integrityOK) { throw new SecurityException("objecy is currupt"); } }//end checkIntegrity private boolean isHashTableTooFull() { if((numberOfEntries / hashTable.length) >= MAX_LOAD_FACTOR) { return true; } else { return false; } }//end isHashTableTooFull private int checkSize(int size) { if(size >= MAX_SIZE){throw new IllegalStateException("Dictionary has become too large.");} else{return size;} }//end checksize
  • 8. private int checkCapacity(int cap) { if(cap < DEFAULT_CAPACITY) { cap = DEFAULT_CAPACITY; } else if (cap > MAX_CAPACITY) { throw new IllegalStateException("Attempt to create a dictionary " + "whose capacity is larger than " + MAX_CAPACITY); } return cap; }//end checkcap private int getNextPrime(int integer) { // if even, add 1 to make od if (integer % 2 == 0) { integer++; } // end if // test odd integers while (!isPrime(integer)) { integer = integer + 2; } // end while return integer; }//end getnextprime
  • 9. private boolean isPrime(int integer) { boolean result; boolean done = false; // 1 and even numbers are not prime if ( (integer == 1) || (integer % 2 == 0) ) { result = false; } // 2 and 3 are prime else if ( (integer == 2) || (integer == 3) ) { result = true; } else // integer is odd and >= 5 { assert (integer % 2 != 0) && (integer >= 5); // a prime is odd and not divisible by every odd integer up to its square root result = true; // assume prime for (int divisor = 3; !done && (divisor * divisor <= integer); divisor = divisor + 2) { if (integer % divisor == 0) { result = false; // divisible; not prime done = true; } // end if } // end for } // end if return result; } // end isPrime /* END of Implementations of private methods are here^. . . . */ protected final class Entry {
  • 10. private K key; private V value; private Entry(K searchKey, V dataValue) { key = searchKey; value = dataValue; }//end contructor private K getKey() { return key; }//end getKey private V getValue() { return value; }//end value private void setValue(V newValue) { value = newValue; }//end setValue } // end Entry private class KeyIterator implements Iterator { private int currentIndex; // Current position in hash table private int numberLeft; // Number of entries left in iteration private KeyIterator() { currentIndex = 0; numberLeft = numberOfEntries; } // end default constructor public boolean hasNext() { return numberLeft > 0; } // end hasNext
  • 11. public void remove() { throw new UnsupportedOperationException(); } // end remove public K next() { K result = null; if (hasNext()) { // Skip table locations that do not contain a current entry while ( (hashTable[currentIndex] == null) || (hashTable[currentIndex] == AVAILABLE) ) { currentIndex++; } // end while result = hashTable[currentIndex].getKey(); numberLeft--; currentIndex++; } else throw new NoSuchElementException(); return result; } // end next } // end KeyIterator //collision method public int getCollisionCount() { return collisionCount; }//end collisionCount } // end HashedDictionary