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
    }
}

yes i have read trough most generic lessons at oracle, is just that this is the first time i use something like <K,V> i am used to <T>

Do you get any error messages?

Well i havnt test it it , hence not sure how to add a value to my hash table, my guess is

table[k] = new Entry(k,v);

but am not sure if this is the correct way to insert in my program.

Do you get any errors when you try to compile it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.