Search in sources :

Example 96 with ByteOrder

use of java.nio.ByteOrder in project cachecloud by sohutv.

the class MurmurHash method hash64A.

public static long hash64A(ByteBuffer buf, int seed) {
    ByteOrder byteOrder = buf.order();
    buf.order(ByteOrder.LITTLE_ENDIAN);
    long m = 0xc6a4a7935bd1e995L;
    int r = 47;
    long h = seed ^ (buf.remaining() * m);
    long k;
    while (buf.remaining() >= 8) {
        k = buf.getLong();
        k *= m;
        k ^= k >>> r;
        k *= m;
        h ^= k;
        h *= m;
    }
    if (buf.remaining() > 0) {
        ByteBuffer finish = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
        // for big-endian version, do this first:
        // finish.position(8-buf.remaining());
        finish.put(buf).rewind();
        h ^= finish.getLong();
        h *= m;
    }
    h ^= h >>> r;
    h *= m;
    h ^= h >>> r;
    buf.order(byteOrder);
    return h;
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer)

Example 97 with ByteOrder

use of java.nio.ByteOrder in project hs4j by killme2008.

the class AbstractIoBuffer method compact.

/**
 * {@inheritDoc}
 */
@Override
public final IoBuffer compact() {
    int remaining = remaining();
    int capacity = capacity();
    if (capacity == 0) {
        return this;
    }
    if (isAutoShrink() && remaining <= capacity >>> 2 && capacity > minimumCapacity) {
        int newCapacity = capacity;
        int minCapacity = Math.max(minimumCapacity, remaining << 1);
        for (; ; ) {
            if (newCapacity >>> 1 < minCapacity) {
                break;
            }
            newCapacity >>>= 1;
        }
        newCapacity = Math.max(minCapacity, newCapacity);
        if (newCapacity == capacity) {
            return this;
        }
        // Shrink and compact:
        // // Save the state.
        ByteOrder bo = order();
        // // Sanity check.
        if (remaining > newCapacity) {
            throw new IllegalStateException("The amount of the remaining bytes is greater than " + "the new capacity.");
        }
        // // Reallocate.
        ByteBuffer oldBuf = buf();
        ByteBuffer newBuf = getAllocator().allocateNioBuffer(newCapacity, isDirect());
        newBuf.put(oldBuf);
        buf(newBuf);
        // // Restore the state.
        buf().order(bo);
    } else {
        buf().compact();
    }
    mark = -1;
    return this;
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer)

Example 98 with ByteOrder

use of java.nio.ByteOrder in project hs4j by killme2008.

the class AbstractIoBuffer method shrink.

/**
 * {@inheritDoc}
 */
@Override
public final IoBuffer shrink() {
    if (!recapacityAllowed) {
        throw new IllegalStateException("Derived buffers and their parent can't be expanded.");
    }
    int position = position();
    int capacity = capacity();
    int limit = limit();
    if (capacity == limit) {
        return this;
    }
    int newCapacity = capacity;
    int minCapacity = Math.max(minimumCapacity, limit);
    for (; ; ) {
        if (newCapacity >>> 1 < minCapacity) {
            break;
        }
        newCapacity >>>= 1;
    }
    newCapacity = Math.max(minCapacity, newCapacity);
    if (newCapacity == capacity) {
        return this;
    }
    // Shrink and compact:
    // // Save the state.
    ByteOrder bo = order();
    // // Reallocate.
    ByteBuffer oldBuf = buf();
    ByteBuffer newBuf = getAllocator().allocateNioBuffer(newCapacity, isDirect());
    oldBuf.position(0);
    oldBuf.limit(limit);
    newBuf.put(oldBuf);
    buf(newBuf);
    // // Restore the state.
    buf().position(position);
    buf().limit(limit);
    buf().order(bo);
    mark = -1;
    return this;
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer)

Example 99 with ByteOrder

use of java.nio.ByteOrder in project Mycat-Server by MyCATApache.

the class Shard method hash.

/**
 * MurMurHash算法,是非加密HASH算法,性能很高,
 * 比传统的CRC32,MD5,SHA-1(这两个算法都是加密HASH算法,复杂度本身就很高,带来的性能上的损害也不可避免)
 * 等HASH算法要快很多,而且据说这个算法的碰撞率很低.
 * http://murmurhash.googlepages.com/
 */
private Long hash(String key) {
    ByteBuffer buf = ByteBuffer.wrap(key.getBytes());
    int seed = 0x1234ABCD;
    ByteOrder byteOrder = buf.order();
    buf.order(ByteOrder.LITTLE_ENDIAN);
    long m = 0xc6a4a7935bd1e995L;
    int r = 47;
    long h = seed ^ (buf.remaining() * m);
    long k;
    while (buf.remaining() >= 8) {
        k = buf.getLong();
        k *= m;
        k ^= k >>> r;
        k *= m;
        h ^= k;
        h *= m;
    }
    if (buf.remaining() > 0) {
        ByteBuffer finish = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
        // for big-endian version, do this first:
        // finish.position(8-buf.remaining());
        finish.put(buf).rewind();
        h ^= finish.getLong();
        h *= m;
    }
    h ^= h >>> r;
    h *= m;
    h ^= h >>> r;
    buf.order(byteOrder);
    return h;
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer)

Example 100 with ByteOrder

use of java.nio.ByteOrder in project bytecode-viewer by Konloch.

the class ValuesPanel method doubleTextFieldKeyReleased.

// GEN-LAST:event_floatTextFieldKeyReleased
private void doubleTextFieldKeyReleased(java.awt.event.KeyEvent evt) {
    // GEN-FIRST:event_doubleTextFieldKeyReleased
    if (evt.getKeyCode() == KeyEvent.VK_ENTER && isEditable()) {
        try {
            ByteOrder byteOrder = getByteOrder();
            double doubleValue = Double.parseDouble(doubleTextField.getText());
            byteBuffer.rewind();
            if (byteBuffer.order() != byteOrder) {
                byteBuffer.order(byteOrder);
            }
            byteBuffer.putDouble(doubleValue);
            modifyValues(8);
            updateValues();
        } catch (NumberFormatException ex) {
            showException(ex);
        }
    }
}
Also used : ByteOrder(java.nio.ByteOrder)

Aggregations

ByteOrder (java.nio.ByteOrder)111 ByteBuffer (java.nio.ByteBuffer)39 IOException (java.io.IOException)8 Test (org.junit.Test)7 QuickTest (com.hazelcast.test.annotation.QuickTest)5 DataInputStream (java.io.DataInputStream)5 FileInputStream (java.io.FileInputStream)5 UUID (java.util.UUID)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 HKL (ffx.crystal.HKL)3 DataOutputStream (java.io.DataOutputStream)3 EOFException (java.io.EOFException)3 FileOutputStream (java.io.FileOutputStream)3 ShortBuffer (java.nio.ShortBuffer)3 ArrayList (java.util.ArrayList)3 Element (org.jdom.Element)3 InvalidDumpFormatException (com.ibm.j9ddr.corereaders.InvalidDumpFormatException)2 Point (com.revolsys.geometry.model.Point)2 Crystal (ffx.crystal.Crystal)2 BigInteger (java.math.BigInteger)2