Example #1
0
 public static long hash64Internal(long val, long seed) {
   long h64 = seed + PRIME64_5;
   h64 += 8; // add length (8 bytes) to hash value
   long k1 = val * PRIME64_2;
   k1 = Long.rotateLeft(k1, 31);
   k1 *= PRIME64_1;
   h64 ^= k1;
   h64 = Long.rotateLeft(h64, 27) * PRIME64_1 + PRIME64_4;
   return applyFinalHashComputation(h64);
 }
Example #2
0
 public boolean isBitSet(int bit) {
   long bitMask = Long.rotateLeft(1, bit);
   long result = this.bitMaskValue & bitMask;
   if (result != 0) {
     return true;
   }
   return false;
 }
Example #3
0
 /**
  * The long unique id is generated as follow:
  *
  * <p>On the first 32 bits we put an integer value incremented at each call and that is reset to 0
  * when the it reaches the max integer range.
  *
  * <p>On the last 32 bits the most significant part of the current timestamp in milliseconds.
  *
  * @return the next unique id in this JVM
  */
 public static synchronized long next() {
   if (count == Integer.MAX_VALUE) {
     count = 0;
   }
   long ms = System.currentTimeMillis();
   long id = (int) ms;
   id = Long.rotateLeft(id, COUNT_OFFSET);
   return id + count++;
 }
Example #4
0
 public void unsetBit(int bit) {
   long bitMask = Long.rotateLeft(1, bit);
   bitMaskValue ^= bitMask;
 }
Example #5
0
  private Murmur3Hash<Long> create128BitMurmur3Hash(byte[] bytes, int seed) {
    long h1 = seed;
    long h2 = seed;
    long c1 = 0x87c37b91114253d5L;
    long c2 = 0x4cf5ad432745937fL;
    int len = 0;

    long k1 = 0;
    long k2 = 0;

    ByteBuffer buffer = ByteBuffer.wrap(bytes);

    while (buffer.remaining() >= 16) {
      k1 = buffer.getLong();
      k2 = buffer.getLong();
      len += 16;

      k1 = Long.rotateLeft(k1, 31);
      k1 *= c2;
      h1 ^= k1;

      h1 = Long.rotateLeft(h1, 27);
      h1 += h2;
      h1 = h1 * 5 + 0x52dce729;

      k2 *= c2;
      k2 = Long.rotateLeft(k2, 33);
      k2 *= c1;
      h2 ^= k2;

      h2 = Long.rotateLeft(h2, 31);
      h2 += h1;
      h2 = h2 * 5 + 0x38495ab5;
    }

    len += buffer.remaining();
    switch (buffer.remaining()) {
      case 15:
        k2 ^= (long) toInt(buffer.get(14)) << 48;
        // $FALL-THROUGH$
      case 14:
        k2 ^= (long) toInt(buffer.get(13)) << 40;
        // $FALL-THROUGH$
      case 13:
        k2 ^= (long) toInt(buffer.get(12)) << 32;
        // $FALL-THROUGH$
      case 12:
        k2 ^= (long) toInt(buffer.get(11)) << 24;
        // $FALL-THROUGH$
      case 11:
        k2 ^= (long) toInt(buffer.get(10)) << 16;
        // $FALL-THROUGH$
      case 10:
        k2 ^= (long) toInt(buffer.get(9)) << 8;
        // $FALL-THROUGH$
      case 9:
        k2 ^= (long) toInt(buffer.get(8)) << 0;
        k2 *= c2;
        k2 = Long.rotateLeft(k2, 33);
        k2 *= c1;
        h2 ^= k2;
        // $FALL-THROUGH$
      case 8:
        k1 ^= (long) toInt(buffer.get(7)) << 56;
        // $FALL-THROUGH$
      case 7:
        k1 ^= (long) toInt(buffer.get(6)) << 48;
        // $FALL-THROUGH$
      case 6:
        k1 ^= (long) toInt(buffer.get(5)) << 40;
        // $FALL-THROUGH$
      case 5:
        k1 ^= (long) toInt(buffer.get(4)) << 32;
        // $FALL-THROUGH$
      case 4:
        k1 ^= (long) toInt(buffer.get(3)) << 24;
        // $FALL-THROUGH$
      case 3:
        k1 ^= (long) toInt(buffer.get(2)) << 16;
        // $FALL-THROUGH$
      case 2:
        k1 ^= (long) toInt(buffer.get(1)) << 8;
        // $FALL-THROUGH$
      case 1:
        k1 ^= (long) toInt(buffer.get(0)) << 0;
        k1 *= c1;
        k1 = Long.rotateLeft(k1, 31);
        k1 *= c2;
        h1 ^= k1;
        // $FALL-THROUGH$
      default:
    }

    h1 ^= len;
    h2 ^= len;

    h1 += h2;
    h2 += h1;

    h1 ^= h1 >>> 33;
    h1 *= 0xff51afd7ed558ccdL;
    h1 ^= h1 >>> 33;
    h1 *= 0xc4ceb9fe1a85ec53L;
    h1 ^= h1 >>> 33;

    h2 ^= h2 >>> 33;
    h2 *= 0xff51afd7ed558ccdL;
    h2 ^= h2 >>> 33;
    h2 *= 0xc4ceb9fe1a85ec53L;
    h2 ^= h2 >>> 33;

    h1 += h2;
    h2 += h1;

    return new Murmur3Hash<Long>(h1, h2);
  }
Example #6
0
  private static long hash64bytes(long start, long bEnd, long seed) {
    long len = bEnd - start;
    long h64;
    long p = start;

    // for long strings (greater than 32 bytes)
    if (len >= 32) {
      final long limit = bEnd - 32;
      long v1 = seed + PRIME64_1 + PRIME64_2;
      long v2 = seed + PRIME64_2;
      long v3 = seed + 0;
      long v4 = seed - PRIME64_1;

      do {
        v1 += PlatformDependent.getLong(p) * PRIME64_2;
        p = p + 8;
        v1 = Long.rotateLeft(v1, 31);
        v1 *= PRIME64_1;

        v2 += PlatformDependent.getLong(p) * PRIME64_2;
        p = p + 8;
        v2 = Long.rotateLeft(v2, 31);
        v2 *= PRIME64_1;

        v3 += PlatformDependent.getLong(p) * PRIME64_2;
        p = p + 8;
        v3 = Long.rotateLeft(v3, 31);
        v3 *= PRIME64_1;

        v4 += PlatformDependent.getLong(p) * PRIME64_2;
        p = p + 8;
        v4 = Long.rotateLeft(v4, 31);
        v4 *= PRIME64_1;
      } while (p <= limit);

      h64 =
          Long.rotateLeft(v1, 1)
              + Long.rotateLeft(v2, 7)
              + Long.rotateLeft(v3, 12)
              + Long.rotateLeft(v4, 18);

      v1 *= PRIME64_2;
      v1 = Long.rotateLeft(v1, 31);
      v1 *= PRIME64_1;
      h64 ^= v1;

      h64 = h64 * PRIME64_1 + PRIME64_4;

      v2 *= PRIME64_2;
      v2 = Long.rotateLeft(v2, 31);
      v2 *= PRIME64_1;
      h64 ^= v2;

      h64 = h64 * PRIME64_1 + PRIME64_4;

      v3 *= PRIME64_2;
      v3 = Long.rotateLeft(v3, 31);
      v3 *= PRIME64_1;
      h64 ^= v3;

      h64 = h64 * PRIME64_1 + PRIME64_4;

      v4 *= PRIME64_2;
      v4 = Long.rotateLeft(v4, 31);
      v4 *= PRIME64_1;
      h64 ^= v4;

      h64 = h64 * PRIME64_1 + PRIME64_4;
    } else {
      h64 = seed + PRIME64_5;
    }

    h64 += len;

    while (p + 8 <= bEnd) {
      long k1 = PlatformDependent.getLong(p);
      k1 *= PRIME64_2;
      k1 = Long.rotateLeft(k1, 31);
      k1 *= PRIME64_1;
      h64 ^= k1;
      h64 = Long.rotateLeft(h64, 27) * PRIME64_1 + PRIME64_4;
      p += 8;
    }

    if (p + 4 <= bEnd) {
      // IMPORTANT: we are expecting a long from these 4 bytes. Which means it is always positive
      long finalInt = getIntLittleEndian(p);
      h64 ^= finalInt * PRIME64_1;
      h64 = Long.rotateLeft(h64, 23) * PRIME64_2 + PRIME64_3;
      p += 4;
    }
    while (p < bEnd) {
      h64 ^= ((long) (PlatformDependent.getByte(p) & 0x00ff)) * PRIME64_5;
      h64 = Long.rotateLeft(h64, 11) * PRIME64_1;
      p++;
    }

    return applyFinalHashComputation(h64);
  }
Example #7
0
 public static long shiftCircular(final long bits, final int shift) {
   return Long.rotateLeft(bits, shift);
   // return bits >>> shift | bits << Long.SIZE - shift;
 }
 /* (non-Javadoc)
  * @see org.jboss.as.model.AbstractModelElement#elementHash()
  */
 @Override
 public long elementHash() {
   long cksum = ref.hashCode() & 0xffffffffL;
   cksum = Long.rotateLeft(cksum, 1) ^ portOffset & 0xffffffffL;
   return cksum;
 }