/** * Read a {@link BitUtil#zigZagDecode(long) zig-zag}-encoded * {@link #readVLong() variable-length} integer. Reads between one and ten * bytes. * @see DataOutput#writeZLong(long) */ public long readZLong() throws IOException { return BitUtil.zigZagDecode(readVLong(true)); }
/** * Write a {@link BitUtil#zigZagEncode(int) zig-zag}-encoded * {@link #writeVInt(int) variable-length} integer. This is typically useful * to write small signed ints and is equivalent to calling * <code>writeVInt(BitUtil.zigZagEncode(i))</code>. * @see DataInput#readZInt() */ public final void writeZInt(int i) throws IOException { writeVInt(BitUtil.zigZagEncode(i)); }
/** * Returns the popcount or cardinality of "a and not b" or * "intersection(a, not(b))". Neither set is modified. */ public static long andNotCount(FixedBitSet a, FixedBitSet b) { // Depends on the ghost bits being clear! long tot = BitUtil.pop_andnot(a.bits, b.bits, 0, Math.min(a.numWords, b.numWords)); if (a.numWords > b.numWords) { tot += BitUtil.pop_array(a.bits, b.numWords, a.numWords - b.numWords); } return tot; }
/** * Returns the popcount or cardinality of the union of the two sets. Neither * set is modified. */ public static long unionCount(FixedBitSet a, FixedBitSet b) { // Depends on the ghost bits being clear! long tot = BitUtil.pop_union(a.bits, b.bits, 0, Math.min(a.numWords, b.numWords)); if (a.numWords < b.numWords) { tot += BitUtil.pop_array(b.bits, a.numWords, b.numWords - a.numWords); } else if (a.numWords > b.numWords) { tot += BitUtil.pop_array(a.bits, b.numWords, a.numWords - b.numWords); } return tot; }
/** * Computes the bounding box coordinates from a given geohash * * @param geohash Geohash of the defined cell * @return GeoRect rectangle defining the bounding box */ public static Rectangle bbox(final String geohash) { // bottom left is the coordinate GeoPoint bottomLeft = GeoPoint.fromGeohash(geohash); int len = Math.min(12, geohash.length()); long ghLong = longEncode(geohash, len); // shift away the level ghLong >>>= 4; // deinterleave long lon = BitUtil.deinterleave(ghLong >>> 1); long lat = BitUtil.deinterleave(ghLong); if (lat < MAX_LAT_BITS) { // add 1 to lat and lon to get topRight GeoPoint topRight = GeoPoint.fromGeohash(BitUtil.interleave((int)(lat + 1), (int)(lon + 1)) << 4 | len); return new Rectangle(bottomLeft.lat(), topRight.lat(), bottomLeft.lon(), topRight.lon()); } else { // We cannot go north of north pole, so just using 90 degrees instead of calculating it using // add 1 to lon to get lon of topRight, we are going to use 90 for lat GeoPoint topRight = GeoPoint.fromGeohash(BitUtil.interleave((int)lat, (int)(lon + 1)) << 4 | len); return new Rectangle(bottomLeft.lat(), MAX_LAT_INCL, bottomLeft.lon(), topRight.lon()); } }
/** * Convert from a morton encoded long from a geohash encoded long */ public static long fromMorton(long morton, int level) { long mFlipped = BitUtil.flipFlop(morton); mFlipped >>>= (((GeoHashUtils.PRECISION - level) * 5) + MORTON_OFFSET); return (mFlipped << 4) | level; }
/** decode latitude value from morton encoded geo point */ public static final double decodeLatitude(final long hash) { return unscaleLat(BitUtil.deinterleave(hash >>> 1)); }
protected Node(final Polygon polygon, final int index, final int vertexIndex) { this.idx = index; this.vrtxIdx = vertexIndex; this.polygon = polygon; this.y = encodeLatitude(polygon.getPolyLat(vrtxIdx)); this.x = encodeLongitude(polygon.getPolyLon(vrtxIdx)); this.morton = BitUtil.interleave(x ^ 0x80000000, y ^ 0x80000000); this.previous = null; this.next = null; this.previousZ = null; this.nextZ = null; }
/** * Returns the popcount or cardinality of the intersection of the two sets. * Neither set is modified. */ public static long intersectionCount(FixedBitSet a, FixedBitSet b) { // Depends on the ghost bits being clear! return BitUtil.pop_intersect(a.bits, b.bits, 0, Math.min(a.numWords, b.numWords)); }
/** Returns number of set bits. NOTE: this visits every * long in the backing bits array, and the result is not * internally cached! */ @Override public int cardinality() { // Depends on the ghost bits being clear! return (int) BitUtil.pop_array(bits, 0, numWords); }
private static int computeBlockSizeBitsFor(long bytes) { long powerOfTwo = BitUtil.nextHighestPowerOfTwo(bytes / MAX_BLOCKS_BEFORE_BLOCK_EXPANSION); if (powerOfTwo == 0) { return DEFAULT_MIN_BITS_PER_BLOCK; } int blockBits = Long.numberOfTrailingZeros(powerOfTwo); blockBits = Math.min(blockBits, DEFAULT_MAX_BITS_PER_BLOCK); blockBits = Math.max(blockBits, DEFAULT_MIN_BITS_PER_BLOCK); return blockBits; }
/** Returns the popcount or cardinality of the union of the two sets. * Neither set is modified. */ public static long unionCount(OpenBitSet a, OpenBitSet b) { long tot = BitUtil.pop_union(a.bits, b.bits, 0, Math.min(a.wlen, b.wlen)); if (a.wlen < b.wlen) { tot += BitUtil.pop_array(b.bits, a.wlen, b.wlen-a.wlen); } else if (a.wlen > b.wlen) { tot += BitUtil.pop_array(a.bits, b.wlen, a.wlen-b.wlen); } return tot; }
/** * Computes the bounding box coordinates from a given geohash * * @param geohash Geohash of the defined cell * @return GeoRect rectangle defining the bounding box */ public static Rectangle bbox(final String geohash) { // bottom left is the coordinate GeoPoint bottomLeft = GeoPoint.fromGeohash(geohash); long ghLong = longEncode(geohash); // shift away the level ghLong >>>= 4; // deinterleave and add 1 to lat and lon to get topRight long lat = BitUtil.deinterleave(ghLong >>> 1) + 1; long lon = BitUtil.deinterleave(ghLong) + 1; GeoPoint topRight = GeoPoint.fromGeohash(BitUtil.interleave((int)lon, (int)lat) << 4 | geohash.length()); return new Rectangle(bottomLeft.lat(), topRight.lat(), bottomLeft.lon(), topRight.lon()); }
/** * Encode to a morton long value from a given geohash long value */ 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))); }
/** decode longitude value from morton encoded geo point */ public static final double decodeLongitude(final long hash) { return unscaleLon(BitUtil.deinterleave(hash)); }
public static final Long mortonHash(final double lon, final double lat) { return BitUtil.interleave(scaleLon(lon), scaleLat(lat)); }
/** * Returns the popcount or cardinality of the intersection of the two sets. * Neither set is modified. */ public static long intersectionCount(FixedBitSet a, FixedBitSet b) { // Depends on the ghost bits being clear! return BitUtil.pop_intersect(a.bits, b.bits, 0, Math.min(a.numWords, b.numWords)); }
/** Returns number of set bits. NOTE: this visits every * long in the backing bits array, and the result is not * internally cached! */ public long cardinality() { // Depends on the ghost bits being clear! return BitUtil.pop_array(bits, 0, numWords); }
/** * * @param size The minimum number of elements this set should be able to hold without rehashing * (i.e. the slots are guaranteed not to change) * @param emptyVal The integer value to use for EMPTY */ public SentinelIntSet(int size, int emptyVal) { this.emptyVal = emptyVal; int tsize = Math.max(org.apache.lucene.util.BitUtil.nextHighestPowerOfTwo(size), 1); rehashCount = tsize - (tsize>>2); if (size >= rehashCount) { // should be able to hold "size" w/o re-hashing tsize <<= 1; rehashCount = tsize - (tsize>>2); } keys = new int[tsize]; if (emptyVal != 0) clear(); }
private int relativeDocBase(int block, int relativeChunk) { final int expected = avgChunkDocs[block] * relativeChunk; final long delta = zigZagDecode(docBasesDeltas[block].get(relativeChunk)); return expected + (int) delta; }