Began implementation of TestInterpolationSearch#runIntSearch

This commit is contained in:
Jonathan Turner 2024-03-21 12:54:17 -04:00
parent d31dbbb4d8
commit b97fb17561

View File

@ -6,12 +6,13 @@ public class TestInterpolationSearch {
/** Holds the list of 1024 unique values used to search through */ /** Holds the list of 1024 unique values used to search through */
public int[] values; public int[] values;
/** Holds the size of the table to generate */
public int tableSize;
/** /**
* Generates a list of 1024 random, non-repeating, integers and assigns them to the values field. * Generates a list of 1024 random, non-repeating, integers and assigns them to the values field.
*/ */
public void RandomDistinct() { public void randomDistinct() {
/* Used to track what ints have been used */ /* Used to track what ints have been used */
HashSet<Integer> isUsed = new HashSet<>(); HashSet<Integer> isUsed = new HashSet<>();
int[] newList = new int[1024]; int[] newList = new int[1024];
@ -34,4 +35,17 @@ public class TestInterpolationSearch {
Arrays.sort(newList); Arrays.sort(newList);
this.values = newList; this.values = newList;
} }
public void runIntSearch() {
int totalDivisions;
Random rand = new Random();
System.out.println(" Key\t\tFound\t\tIndex\t\tDivisions");
System.out.println("----------------------------------------------");
for (int i = 0; i < this.tableSize; i++) {
int key = rand.nextInt(9999) + 1;
InterpolationSearch results = new InterpolationSearch(this.values, key);
System.out.println(" " + key + "\t\t" + results.isFound() + "\t\t" + results.getIndex() + "\t\t" + results.getDivisions());
}
}
} }