private static int asInteger()

in src/main/java/org/apache/datasketches/hash/MurmurHash3Adaptor.java [340:394]


  private static int asInteger(final long[] data, final int n) {
    int t;
    int cnt = 0;
    long seed = 0;
    if (n < 2) {
      throw new SketchesArgumentException("Given value of n must be &gt; 1.");
    }
    if (n > (1 << 30)) {
      while (++cnt < 10000) {
        final long[] h = MurmurHash3.hash(data, seed);
        t = (int) (h[0] & INT_MASK);
        if (t < n) {
          return t;
        }
        t = (int) ((h[0] >>> 33));
        if (t < n) {
          return t;
        }
        t = (int) (h[1] & INT_MASK);
        if (t < n) {
          return t;
        }
        t = (int) ((h[1] >>> 33));
        if (t < n) {
          return t;
        }
        seed += PRIME;
      } // end while
      throw new SketchesStateException(
          "Internal Error: Failed to find integer &lt; n within 10000 iterations.");
    }
    final long mask = ceilingIntPowerOf2(n) - 1;
    while (++cnt < 10000) {
      final long[] h = MurmurHash3.hash(data, seed);
      t = (int) (h[0] & mask);
      if (t < n) {
        return t;
      }
      t = (int) ((h[0] >>> 33) & mask);
      if (t < n) {
        return t;
      }
      t = (int) (h[1] & mask);
      if (t < n) {
        return t;
      }
      t = (int) ((h[1] >>> 33) & mask);
      if (t < n) {
        return t;
      }
      seed += PRIME;
    } // end while
    throw new SketchesStateException(
        "Internal Error: Failed to find integer &lt; n within 10000 iterations.");
  }