Example usage for org.apache.lucene.util BitUtil flipFlop

List of usage examples for org.apache.lucene.util BitUtil flipFlop

Introduction

In this page you can find the example usage for org.apache.lucene.util BitUtil flipFlop.

Prototype

public static final long flipFlop(final long b) 

Source Link

Document

flip flops odd with even bits

Usage

From source file:org.codelibs.elasticsearch.common.geo.GeoHashUtils.java

License:Apache License

/**
 * Encode lon/lat to the geohash based long format (lon/lat interleaved, 4 least significant bits = level)
 *///from w w w  .ja va  2s  .c  om
public static final long longEncode(final double lon, final double lat, final int level) {
    // shift to appropriate level
    final short msf = (short) (((12 - level) * 5) + MORTON_OFFSET);
    return ((BitUtil.flipFlop(GeoPointField.encodeLatLon(lat, lon)) >>> msf) << 4) | level;
}

From source file:org.codelibs.elasticsearch.common.geo.GeoHashUtils.java

License:Apache License

/**
 * Convert from a morton encoded long from a geohash encoded long
 *///from   w  ww .  ja  va 2 s .  c  o  m
public static long fromMorton(long morton, int level) {
    long mFlipped = BitUtil.flipFlop(morton);
    mFlipped >>>= (((GeoHashUtils.PRECISION - level) * 5) + MORTON_OFFSET);
    return (mFlipped << 4) | level;
}

From source file:org.codelibs.elasticsearch.common.geo.GeoHashUtils.java

License:Apache License

/**
 * Encode to a geohash string at a given level from a morton long
 *///from   w  w w  . j  av a 2  s.  c  o m
public static final String stringEncodeFromMortonLong(long hashedVal, final int level) {
    // bit twiddle to geohash (since geohash is a swapped (lon/lat) encoding)
    hashedVal = BitUtil.flipFlop(hashedVal);

    StringBuilder geoHash = new StringBuilder();
    short precision = 0;
    final short msf = (GeoPointField.BITS << 1) - 5;
    long mask = 31L << msf;
    do {
        geoHash.append(BASE_32[(int) ((mask & hashedVal) >>> (msf - (precision * 5)))]);
        // next 5 bits
        mask >>>= 5;
    } while (++precision < level);
    return geoHash.toString();
}

From source file:org.codelibs.elasticsearch.common.geo.GeoHashUtils.java

License:Apache License

/**
 * Encode to a morton long value from a given geohash string
 *///from   w  w  w.  j av  a  2  s  . c  om
public static final long mortonEncode(final String hash) {
    int level = 11;
    long b;
    long l = 0L;
    for (char c : hash.toCharArray()) {
        b = (BASE_32_STRING.indexOf(c));
        l |= (b << ((level-- * 5) + MORTON_OFFSET));
    }
    return BitUtil.flipFlop(l);
}

From source file:org.codelibs.elasticsearch.common.geo.GeoHashUtils.java

License:Apache License

/**
 * Encode to a morton long value from a given geohash long value
 */// w ww. j av a 2 s .  c  o m
public static final long mortonEncode(final long geoHashLong) {
    final int level = (int) (geoHashLong & 15);
    final short odd = (short) (level & 1);

    return BitUtil.flipFlop(((geoHashLong >>> 4) << odd) << (((12 - level) * 5) + (MORTON_OFFSET - odd)));
}

From source file:org.codelibs.elasticsearch.common.geo.GeoPoint.java

License:Apache License

public GeoPoint resetFromGeoHash(long geohashLong) {
    final int level = (int) (12 - (geohashLong & 15));
    return this.resetFromIndexHash(BitUtil.flipFlop((geohashLong >>> 4) << ((level * 5) + 2)));
}

From source file:org.elasticsearch.common.geo.GeoHashUtils.java

License:Apache License

/**
 * Encode to a morton long value from a given geohash string
 *///w w w  . j  a  v  a 2 s.c o m
public static final long mortonEncode(final String hash) {
    int level = 11;
    long b;
    long l = 0L;
    for (char c : hash.toCharArray()) {
        b = (long) (BASE_32_STRING.indexOf(c));
        l |= (b << ((level-- * 5) + MORTON_OFFSET));
    }
    return BitUtil.flipFlop(l);
}