- Initialize count to θ, capacity to the argument, loadFactor to the respective DEFAULT values, * collisiontlandler to t
Posted: Thu Jul 14, 2022 2:11 pm
Hashtable.java
- Initialize count to θ, capacity to the argument, loadFactor to the respective DEFAULT values, * collisiontlandler to the collisionHdler argument, create the three arrays " for keys, values, and the isActive boolean array. public ArrayHashTable(int capacity, collisionHandler ⟨K⟩ collisionHdler) \{ | 11 ABimplement this method. Initialize count to θ, capacity and loadFactor to the respective argument values, collisiontandler to the collisiontdler argument, create the three arrays for keys, values, and the isactive boolean array. public ArrayHashTable(int capacity, double loadFactor, collisionHandler \&K collisionHdler) \{ I / Eoonglement this method. \} f∗∗ * Returns the number of elements in the hash table. public int getsize() \{ * For each key in the key array, if that cell is active (true) in * the activearray, get the index by calling the hash function, use the collisionHandler * probe method to get the new index (it nay be different from the original hash if * a collision occurred). Enter the key in the new keyArray, value in the new valueArray, * and set the new activeArray to true. Finally, assign the current keyArray, valueArray, - and activeArray to the new arrays. * 1
- Calculates and returns the load factor of the hash table. - This is the ratio of the number of elements stored in the hashtable - divided by the total capacity of the hashtable. −1 private double calcloadfactor () \{ /1 i.implesint tris cesthod - Insert the provided key value pair into the hashtable. If the key exists in - the table, the stored value is overwritten with the new value passed in. - Please use the provided gethash method to get the hash for the array index. * Steps: check is current load is > loadfactor. If true, call resizeArray. - Then see if key is in the table by calling getindex. If key exists, overwrite value - in the valueArray. If key does not exist, get the index by calling the hash function (gethash). - Then call resolveCollision to see if a collision occurs and if so, that methos will use the - collision handler to resolve it. Then enter the key in the keyarray using the index returned from - resolveCollision, enter the value in the valueArray, and set the isactiveArray to true. Finally, - increment the count. 1 public void put( K key, v value) \{ I 11 inplement this method. 3 jon - Returns the value associated with the key if it exists in the hashtable. - Get the index by calling the hash function, then check if key exists by calling getindex. - Return the value in the valuearray if key is in the table.
- Returns the value associated with the key if it exists in the hashtable. - Get the index by calling the hash function, then check if key exists by calling getindex. " Return the value in the valueArray if key is in the table. - Returns null if the key is not in the table. -/ public V getvalue( K target) \{ indeplement, this, method I return null; I Removes the key-value pair specified by the targetiky from the hashtable and returns the value. - The method gets the hash on the targetikey, then checks if the key is in the table by calling getindex. - Then, if targetkey is in the table, get the value associated with the targetkey from the valuedrray, - then set the activearray to false as this cell is now open, decrement the count, and return the value. - Cthrows ElementWotFoundException if the target does not exist in the table. public V remove( K targetKey)throws ElementwotFoundException \{ /f : Implement this method / Returns a KeyIterator for the keys in this HashTable. public IteratoreK > keyIterator() | return new KeyIteratorkK (keyArray, count); \} public int getcapacity() return capacity; \} public double getLoadFactor() .
public K[] getKeyArray public double getloadFactor( public K[] getkeyArray()\{ public V[] getvalueArray()\{ public boolean[] getisactiveArray()\{ |return isActiveArray; public Collisiontandler ⟨K⟩ getcollisiontandler()] |return collisionhandler; structures >0 ArrayHashTable,java > \& AfrayHashTable ⟨k,V>>$ getCollsionHandler0 ] - Coment out statements as needed. Use the debugger to see * what your code is doing by stepping in, out, and over methods * and statements, and checking the variables pane to see the state * of your table and its variables. -1 Run | Debug public static void main(String[] args) throws Exception \{ I // Init the type of collision handler: linear or quadratic. // CollisionHandler ⟨ String ⟩ collisionHdler = new LinearCollisionHandler \langle\rangle() ; CollisionHandler ⟨ string〉 collisionHdler = new QuadraticcollisionHandler ⟨(); AcrayHashTablesstring, String> table = new AcrayHashTablecstring, String (collisionHdler); table.put(key: "fatimeh", value: "efanB*k"); // test the get method after the put method was called:
- Initialize count to θ, capacity to the argument, loadFactor to the respective DEFAULT values, * collisiontlandler to the collisionHdler argument, create the three arrays " for keys, values, and the isActive boolean array. public ArrayHashTable(int capacity, collisionHandler ⟨K⟩ collisionHdler) \{ | 11 ABimplement this method. Initialize count to θ, capacity and loadFactor to the respective argument values, collisiontandler to the collisiontdler argument, create the three arrays for keys, values, and the isactive boolean array. public ArrayHashTable(int capacity, double loadFactor, collisionHandler \&K collisionHdler) \{ I / Eoonglement this method. \} f∗∗ * Returns the number of elements in the hash table. public int getsize() \{ * For each key in the key array, if that cell is active (true) in * the activearray, get the index by calling the hash function, use the collisionHandler * probe method to get the new index (it nay be different from the original hash if * a collision occurred). Enter the key in the new keyArray, value in the new valueArray, * and set the new activeArray to true. Finally, assign the current keyArray, valueArray, - and activeArray to the new arrays. * 1
- Calculates and returns the load factor of the hash table. - This is the ratio of the number of elements stored in the hashtable - divided by the total capacity of the hashtable. −1 private double calcloadfactor () \{ /1 i.implesint tris cesthod - Insert the provided key value pair into the hashtable. If the key exists in - the table, the stored value is overwritten with the new value passed in. - Please use the provided gethash method to get the hash for the array index. * Steps: check is current load is > loadfactor. If true, call resizeArray. - Then see if key is in the table by calling getindex. If key exists, overwrite value - in the valueArray. If key does not exist, get the index by calling the hash function (gethash). - Then call resolveCollision to see if a collision occurs and if so, that methos will use the - collision handler to resolve it. Then enter the key in the keyarray using the index returned from - resolveCollision, enter the value in the valueArray, and set the isactiveArray to true. Finally, - increment the count. 1 public void put( K key, v value) \{ I 11 inplement this method. 3 jon - Returns the value associated with the key if it exists in the hashtable. - Get the index by calling the hash function, then check if key exists by calling getindex. - Return the value in the valuearray if key is in the table.
- Returns the value associated with the key if it exists in the hashtable. - Get the index by calling the hash function, then check if key exists by calling getindex. " Return the value in the valueArray if key is in the table. - Returns null if the key is not in the table. -/ public V getvalue( K target) \{ indeplement, this, method I return null; I Removes the key-value pair specified by the targetiky from the hashtable and returns the value. - The method gets the hash on the targetikey, then checks if the key is in the table by calling getindex. - Then, if targetkey is in the table, get the value associated with the targetkey from the valuedrray, - then set the activearray to false as this cell is now open, decrement the count, and return the value. - Cthrows ElementWotFoundException if the target does not exist in the table. public V remove( K targetKey)throws ElementwotFoundException \{ /f : Implement this method / Returns a KeyIterator for the keys in this HashTable. public IteratoreK > keyIterator() | return new KeyIteratorkK (keyArray, count); \} public int getcapacity() return capacity; \} public double getLoadFactor() .
public K[] getKeyArray public double getloadFactor( public K[] getkeyArray()\{ public V[] getvalueArray()\{ public boolean[] getisactiveArray()\{ |return isActiveArray; public Collisiontandler ⟨K⟩ getcollisiontandler()] |return collisionhandler; structures >0 ArrayHashTable,java > \& AfrayHashTable ⟨k,V>>$ getCollsionHandler0 ] - Coment out statements as needed. Use the debugger to see * what your code is doing by stepping in, out, and over methods * and statements, and checking the variables pane to see the state * of your table and its variables. -1 Run | Debug public static void main(String[] args) throws Exception \{ I // Init the type of collision handler: linear or quadratic. // CollisionHandler ⟨ String ⟩ collisionHdler = new LinearCollisionHandler \langle\rangle() ; CollisionHandler ⟨ string〉 collisionHdler = new QuadraticcollisionHandler ⟨(); AcrayHashTablesstring, String> table = new AcrayHashTablecstring, String (collisionHdler); table.put(key: "fatimeh", value: "efanB*k"); // test the get method after the put method was called: