Ok guys i have a few questions about implementing a gneric hash table using linear probing.
Ok first, i need to make an entry class Entry<K,V>
then An Entry <K,V> table array but since its gneric must initiatied elsewhere
my question is how does the class entry work , from what i understand it will be like some sort of node with 2 fields of type K and V but i dont know how i will insert using entry then entering it in the table. This is what i have written so far. Am having trouble understanding it correctly, and inserting to table.
package linearprobinghashtable;
/**
*
* @author alejandro
*/
public class LinearProbingHashTable<K,V>
{
private class Entry<K,V>
{
private K key; //maps value to hash table
private V value;//vlaue in the hash table
public Entry(K key, V value)
{
this.key = key;
this.value = value;
}
}
private int size;
private int numberofelements;
Entry<K,V> table[];
public LinearProbingHashTable(int size)//table with a defined size
{
this.size=size;
table = new LinearProbingHashTable.Entry[size];
}
public V insert(K key, V value)
{
if(key==null)
{
throw new NullPointerException("Null key!");
}
return insert(new Entry(key,value));
}
public V insert(Entry e)
{
if(e==null)
{
return null;
}
int startIndex = e.key.hashCode() % table.length;
int next;
int insertIndex = -1;
for(int i =startIndex;i<table.length;i++)
{
if(table[i]==null)
{
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
}
}