Offset 9967 a 4k3 prime pass n dataip v 1 dataip v 2

This preview shows page 64 - 71 out of 86 pages.

offset = 9,967 (a 4k+3 prime) pass < N? data[ip] == v 1 data[ip] = v 2 ; return true and end ip = (ip + offset) % N pass = pass + 1 return noE rror = false and end yes yes yes no no no data[ip]’s key == k no N is the size of the primary storage area array, data V 1 is null, V 2 is the dummy node
Image of page 64

Subscribe to view the full document.

65 Implementation Of the LQHashed Structure The operation methods are the Java equivalent of the operation flowcharts Methods are included to Generate a 4k+3 prime a given percent larger than a given integer Output all the nodes Perform Folding preprocessing on a String key A one parameter constructor is included Passed the maximum number of nodes Invokes the 4k+3 prime generator to size the array Create the dummy node, named deleted The client’s node definition class (e.g., Listing) must provide a getKey method
Image of page 65
66 4k+3 Prime Number Generator 1. public static int fourKPlus3( int n, int pct) 2. { boolean fkp3 = false ; 3. boolean aPrime = false ; 4. int prime, highDivisor, d; 5. double pctd = pct; 6. prime = ( int )(n * (1.0 + (pctd / 100.0))); 7. if (prime % 2 == 0) // if even make odd 8. prime = prime +1; 9. while (fkp3 == false ) // not a 4k+3 prime 10. { while (aPrime == false ) // not a prime 11. { highDivisor = ( int )(Math.sqrt(prime) + 0.5); 12. for (d = highDivisor; d > 1; d--) 13. { if (prime % d == 0) 14. break ; // not a prime 15. } 16. if (d != 1) // prime not found 17. prime = prime + 2; 18. else 19. aPrime = true ; 20. } // end of the prime search loop 21. if ((prime - 3) % 4 == 0) 22. fkp3 = true ; 23. else 24. { prime = prime + 2; 25. aPrime = false ; 26. } 27. } // end of 4k+3 prime search loop 28. return prime; 29. }
Image of page 66

Subscribe to view the full document.

67 Method To Output All The Nodes in the LQHashed Structure public void showAll() // deleted is the reference to the dummy node { for ( int i = 0; i < N; i++) if (data[i] != null && data[i] != deleted ) data[i].toSring(); } // end showAll method
Image of page 67