Question: why am I getting error on: temporary = hash _ table [ second _ index ] ; and how to fix it ? package spiderman;
why am I getting error on: temporaryhashtablesecondindex; and how to fix it
package spiderman;
public class creatingHT
to create the hash table, you need to first perform the hash function
Hash Function:
public static int hashCode ClusterNode temporary, int size
int numdime temporary.getDimennum;
int i numdime size;
return i;
ReHash Function:
to rehash, you need two tables: one which is prev and one which is current
private static void reHash ClusterNode prev, ClusterNode current
int newsize current.length; you need a new size inorder to rehash your hash table.
for int a ; a prev.length; ago through the LL of ClusterNode
ClusterNode prevpointer preva; pointer
while prevpointer null
ClusterNode currentpointer prevpointer;
prevpointer prevpointer.getNext; go to the next node
int b hashCodecurrentpointer, newsize; creating new index which uses the Hash Function, we can use this and create a new hash table.
ClusterNode temporary currentb;
currentb currentpointer;
currentbsetNexttemporary;
public static ClusterNode createHashTableString in
create a tracker to check how many nodes there are in a Hash Table
int tracker ;
StdIn.setFilein; the in is the dimension.in which we are taking in
Step :
DimensionInputFile name is passed through the command line as args
Read from the DimensionsInputFile with the format:
The first line with three numbers:
i a int: number of dimensions in the graph
ii b int: the initial size of the cluster table prior to rehashing
iii. c double: the capacitythreshold used to rehash the cluster table
int a StdIn.readInt;
int b StdIn.readInt;
double c StdIn.readDouble;
StdIn.readLine;
ClusterNode hashtable new ClusterNodeb;
while StdIn.isEmpty
if tracker c
ClusterNode current new ClusterNodeb;
b b;
c c;
call the rehash method to rehash everything copied from the current to the new table.
reHashhashtable, current;
hashtable current;
int numdime StdIn.readInt;
int canonevents StdIn.readInt;
int dimenweight StdIn.readInt;
ClusterNode Node new ClusterNodenumdime, canonevents, dimenweight, null;
int i hashCodeNode b;
ClusterNode temporary hashtablei;
hashtablei Node;
hashtableisetNexttemporary;
tracker tracker;
System.out.println;
StdIn.readLine;
int length hashtable.length;
for int indexes ; indexes hashtable.length; indexes
adding the first two nodes of the hash table and adding it at the end of the table which we have.
you need two indexes to do this. one for each node.
int firstindex indexes ;
int secondindex indexes ;
if firstindex you need to check for num's
firstindex length firstindex;
if secondindex
secondindex length secondindex;
ClusterNode temporary hashtablefirstindex;
ClusterNode firstnode new ClusterNodetemporarygetDimennum temporary.getCanonevents temporary.getDimenweight null ;
temporary hashtablesecondindex;
ClusterNode secondnode new ClusterNodetemporarygetDimennum temporary.getCanonevents temporary.getDimenweight null ;
to add the nodes, you have to traverse through the LL in the hashtable.
ClusterNode pointer hashtableindexes;
while pointer.getNext null check if the list is not empty
pointer pointer.getNext;
go to the end of the LL
pointer.setNextfirstnode;
pointer pointer.getNext;
pointer.setNextsecondnode;
return hashtable;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
