Trusted by 2+ million users,
1000+ happy students everyday
Showing pages 1 to 1 of 2 pages
import java.util.*;public class IntListMethodsTest {// Compute a simple XOR checksum of the indices of the nodes hanging fromn.private static long checksum(int n) {int check = 0;while(n != 0) {check = check ^ n;n = IntList.getNext(n);}return check;}// Run the test and return the measured total running time.public static int test(int seed, int rounds, int size, boolean verbose) {int[] data = new int[size];Random rng = new Random(seed);IntList.initialize(size + 5);int totalTime = 0;long startTime, endTime;for(int i = 0; i < rounds; i++) {for(int j = 0; j < size; j++) {data[j] = rng.nextInt(2 * size + 1) - size;}int lock = rng.nextInt();int k = rng.nextInt(6) + 2;int n = IntList.allocate(data);if(verbose) { System.out.println("Original: " +IntList.toString(n)); }startTime = System.currentTimeMillis();n = IntListMethods.removeIfDivisible(n, k);endTime = System.currentTimeMillis();totalTime += (int)(endTime - startTime);if(verbose) { System.out.println("After removeIf(" + k + "): " +IntList.toString(n)); }int m = n, idx = 0;while(m != 0) {while(data[idx] % k == 0) { idx++; }if(IntList.getKey(m) != data[idx]) {System.out.println("ERROR: removeIf " + IntList.getKey(m)+ " " + data[idx] );return 9999999;}idx++;m = IntList.getNext(m);}Arrays.sort(data);long check1 = checksum(n);IntList.lockKeys(lock);startTime = System.currentTimeMillis();n = IntListMethods.sort(n);endTime = System.currentTimeMillis();totalTime += (int)(endTime - startTime);IntList.unlockKeys(lock);long check2 = checksum(n);
Desklib Logo
You are reading a preview
Upload your documents to download or

Become a Desklib member to get access