How can Implement a perfect hashed data structure using the four basic operations?

Could I do something like this or do I need to break up my code into two different classes and then test the methods from another class’s main method:

public class PerfectHashed{

int ticketNumber; // keyfield
String PurchaserName; 

input(){
// key values ranges between 2000 to 100, 000 
System.out.print("Please enter a ticket number between 2000 to 100,000: " ); 
// to hold there answer.
number= nextInt(); 
*
}
 // Then would need the four basic operations in my application:  

 
// the insert direct hashed algorithm 
    pseudoKey = preProcessing(targetKey); 
  ip = pseudoKey; // direct hashing function 
 
// insert the new node
data[ip]= newNode.deepCopy(); 

  // the fetch algorithm 
 // access the primary storage area 

 pseudoKey = preprocessing(targetKey); 
ip = pseudoKey; // direct hashing function 
if(null[ip] = = null)
 { return null; } 
else{return   data[ip].deepCopy(); 
}
 
  // the delete direct hashed algorithm 


 // access the primary storage area 
 pseudoKey = preprocessing(targetKey); 
ip = pseudoKey; // direct hashing function 

if(null[ip] = = null)
 { return false; } 
else 
  { data[ip]=null;                      
      return true; }
} 
 
// the update direct hashed algorithm 
if(delete(targetKey) == false)
    return false; 
 else 
 {insert(newNode) return true; }    

@SamuelCalifornia, @Paul_Wilkins

Do you think you could help me? Here is my latest update in code that I went back and tried to correct.

import java.util.Scanner; 

public class StadiumTickets
{

     int ticketNumber; // keyfield

     String purchaserName; 


  public void input()
  {

     Scanner input= new Scanner(System.in);

      // key values ranges between 2000 to 100,000 


      System.out.print("Please enter a ticket number between 2000 to 100,000: "); 

      // a variable to hold the answer

       ticketNumber= input.nextInt(); 
    

        // error checking to make sure the user doesn't enter a key outside of the lower or upper ranges

       if(ticketNumber < 2000 && ticketNumber > 100000) 
        System.out.println("This number is not a valid entry to input into the structure.");
     }

  public StadiumTickets(int ticketNumber, String purchaserName)
  {
     
       this.ticketNumber= ticketNumber; 
       this.purchaserName= purchaserName; 
   } 


 
   public StadiumTickets deepCopy()
   { 

      StadiumTickets clone= new StadiumTickets(ticketNumber, purchaserName); 
       return clone; 
   }  
}



public class PerfectHash
{

  private StadiumTickets[] data; 
  

  public boolean insert(StadiumTickets newStadiumTicket)
  {
      // the direct insert hashed algorithm 

       pseudoKey = preProcessing(targetKey); 
       ip = pseudoKey; // direct hashing function 

       // insert the new node
        data[ip] = newStadiumTicket.deepCopy(); 
  }
  
  public StadiumTickets fetch(String targetKey)
  {
   
    // the fetch algorithm 
    // access the primary storage area 

     pseudoKey = preprocessing(targetKey); 
     ip = pseudoKey; // direct hashing function 
    if(data[ip]== null)
     { return null; 

     } 
     else
     {
        return data[ip].deepCopy(); 
     }
   } 

   public boolean delete(String targetKey)
   { 
      // the delete direct hashed algorithm 

      // access the primary storage area 
         pseudoKey = preprocessing(targetKey); 
       ip = pseudoKey; // direct hashing function 

      if(data[ip]== null)
      { 
         return false; 
       } 
      else 
      { 
        data[ip]= null;                      
        return true; 
      }
    } 
    public boolean update(String targetKey, StadiumTickets newStadiumTicket)
    {
        // the update direct hashed algorithm 

       if(delete(targetKey) == false)
           return false; 
       else 
        {
           insert(newStadiumTicket) 
             return true;
         }
     }
   
}

Do you have any tests to help ensure that the code remains working as expected while investigations occur?

@Paul_Wilkins,
I just compile and run while I code the application. I know the StadiumTickets class compiles fine, but the second class need some work. but I can’t figure how to implement the four merhods. I know that’s pseudocode, but where I can expand all four methods to produce workable methods that I can then test in the PerfectHash’s main method?

Oh sorry @sealsd, I’ve just realised that it’s Java that you’re dealing with there, and not JavaScript.

I wish you all the best in regard to finding further assistance from someone with your Java code there.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.