@Test
 public void testGetMinimumMaximumTreeSet() {
   final SortedSet<Long> set = new TreeSet<>();
   long min = Long.MAX_VALUE;
   long max = Long.MIN_VALUE;
   Random rnd = new Random();
   for (int i = 0; i < BENCHMARK_SIZE; i++) {
     final long key = rnd.nextLong();
     set.add(key);
     if (key > max) {
       max = key;
     }
     if (key < min) {
       min = key;
     }
   }
   Assert.assertEquals(min, set.first().longValue());
   Assert.assertEquals(max, set.last().longValue());
   System.out.print(
       "Memory used: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
 }
 @Test
 public void testGetMinimumMaximum2() {
   final LongSkipList list = new LongSkipList();
   long min = Long.MAX_VALUE;
   long max = Long.MIN_VALUE;
   Random rnd = new Random();
   for (int i = 0; i < BENCHMARK_SIZE; i++) {
     final long key = rnd.nextLong();
     list.add(key);
     if (key > max) {
       max = key;
     }
     if (key < min) {
       min = key;
     }
   }
   Assert.assertEquals(min, list.getMinimum().longValue());
   Assert.assertEquals(max, list.getMaximum().longValue());
   System.out.print(
       "Memory used: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
 }
Exemple #3
0
 /**
  * @return level of a node using quasi-random heuristics in consideration that certain divisors
  *     are distributed quite uniformly amongst successive natural numbers.
  */
 protected int generateQuasiRandomLevel() {
   int level = 1;
   int seed = this.seed + 1;
   if ((seed & 0x3ff) == 0) {
     seed = rnd.nextInt();
   }
   seed &= 0x7fffffff;
   this.seed = seed;
   for (; ; ) {
     final int factor = LEVEL_FACTORS[level - 1];
     if (seed % factor != 1) break;
     seed /= factor;
     ++level;
   }
   return level;
 }
Exemple #4
0
 SkipListBase() {
   rnd = new Random();
   seed = rnd.nextInt() & 0x7fffffff;
 }