예제 #1
0
    int oneStep(int j) {
      int n = key.length;
      int r = rng.next() & 0x7FFFFFFF;
      int jinc = (r & 7);
      j += jinc - 3;
      if (j >= n) j -= n;
      if (j < 0) j += n;

      int l = n / 4 + j;
      if (l >= n) l -= n;

      String k = key[j];
      String x = map.get(k);

      if (x == null) {
        ++nagets;
        if (r < pctins) {
          map.put(k, key[l]);
          ++nputs;
          int csz = nputs - nremoves;
          if (csz > maxsz) maxsz = csz;
        }
      } else {
        if (k == x) ++npgets;
        if (r < pctrem) {
          map.remove(k);
          ++nremoves;
          j += ((r >>> 8) & 7) + n / 2;
          if (j >= n) j -= n;
        }
      }
      return j;
    }
예제 #2
0
 static void randomWords(Object[] ws, int origin, int size) {
   for (int i = origin; i < size; ++i) {
     int k = 0;
     int len = 2 + (srng.next() & 0xf);
     char[] c = new char[len * 4 + 1];
     for (int j = 1; j < len; ++j) {
       int r = srng.next();
       c[k++] = (char) (' ' + (r & 0x7f));
       r >>>= 8;
       c[k++] = (char) (' ' + (r & 0x7f));
       r >>>= 8;
       c[k++] = (char) (' ' + (r & 0x7f));
       r >>>= 8;
       c[k++] = (char) (' ' + (r & 0x7f));
     }
     c[k++] = (char) ((i & 31) | 1); // never == to any testword
     ws[i] = new String(c);
   }
 }
예제 #3
0
 static void initInts(Object[] key, Object[] absent, int size) {
   for (int i = 0; i < size; ++i) key[i] = Integer.valueOf(i);
   Map m = newMap();
   int k = 0;
   while (k < size) {
     int r = srng.next();
     if (r < 0 || r >= size) {
       Integer ir = Integer.valueOf(r);
       if (m.put(ir, ir) == null) absent[k++] = ir;
     }
   }
 }