Search in sources :

Example 1 with BitUtil

use of com.graphhopper.util.BitUtil in project graphhopper by graphhopper.

the class UnsafeDataAccessTest method testNativeOrder.

@Test
public void testNativeOrder() {
    BitUtil bitUtil = BitUtil.get(ByteOrder.nativeOrder());
    long address = UnsafeDataAccess.UNSAFE.allocateMemory(8);
    long val = 123123123123L * 123L;
    byte[] bytes = new byte[8];
    bitUtil.fromLong(bytes, val);
    if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
        for (int i = 7; i >= 0; i--) {
            UnsafeDataAccess.UNSAFE.putByte(address + i, bytes[i]);
        }
    } else {
        // not tested:
        for (int i = 0; i < 8; i++) {
            UnsafeDataAccess.UNSAFE.putByte(address + i, bytes[i]);
        }
    }
    long tmp = UnsafeDataAccess.UNSAFE.getLong(address);
    assertEquals(val, tmp);
    UnsafeDataAccess.UNSAFE.freeMemory(address);
}
Also used : BitUtil(com.graphhopper.util.BitUtil) Test(org.junit.Test)

Example 2 with BitUtil

use of com.graphhopper.util.BitUtil in project graphhopper by graphhopper.

the class EncodingManagerTest method testFullBitMask.

public void testFullBitMask() {
    BitUtil bitUtil = BitUtil.LITTLE;
    EncodingManager manager = new EncodingManager("car,foot");
    AbstractFlagEncoder carr = (AbstractFlagEncoder) manager.getEncoder("car");
    assertTrue(bitUtil.toBitString(carr.getNodeBitMask()).endsWith("00000000001111111"));
    AbstractFlagEncoder foot = (AbstractFlagEncoder) manager.getEncoder("foot");
    assertTrue(bitUtil.toBitString(foot.getNodeBitMask()).endsWith("00011111110000000"));
}
Also used : BitUtil(com.graphhopper.util.BitUtil)

Aggregations

BitUtil (com.graphhopper.util.BitUtil)2 Test (org.junit.Test)1