Java 类org.apache.lucene.util.BitUtil 实例源码

项目:elasticsearch_my    文件:GeoHashUtils.java   
/**
 * Encode to a geohash string at a given level from a morton long
 */
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();
}
项目:search    文件:HashDocSet.java   
/** Create a HashDocSet from a list of *unique* ids */  
public HashDocSet(int[] docs, int offset, int len, float inverseLoadFactor) {
  int tsize = Math.max(BitUtil.nextHighestPowerOfTwo(len), 1);
  if (tsize < len * inverseLoadFactor) {
    tsize <<= 1;
  }

  mask=tsize-1;

  table = new int[tsize];
  // (for now) better then: Arrays.fill(table, EMPTY);
  // https://issues.apache.org/jira/browse/SOLR-390
  for (int i=tsize-1; i>=0; i--) table[i]=EMPTY;

  int end = offset + len;
  for (int i=offset; i<end; i++) {
    put(docs[i]);
  }

  size = len;
}
项目:NYBC    文件:HashDocSet.java   
/** Create a HashDocSet from a list of *unique* ids */  
public HashDocSet(int[] docs, int offset, int len, float inverseLoadFactor) {
  int tsize = Math.max(BitUtil.nextHighestPowerOfTwo(len), 1);
  if (tsize < len * inverseLoadFactor) {
    tsize <<= 1;
  }

  mask=tsize-1;

  table = new int[tsize];
  // (for now) better then: Arrays.fill(table, EMPTY);
  // https://issues.apache.org/jira/browse/SOLR-390
  for (int i=tsize-1; i>=0; i--) table[i]=EMPTY;

  int end = offset + len;
  for (int i=offset; i<end; i++) {
    put(docs[i]);
  }

  size = len;
}
项目:search-core    文件:HashDocSet.java   
/** Create a HashDocSet from a list of *unique* ids */  
public HashDocSet(int[] docs, int offset, int len, float inverseLoadFactor) {
  int tsize = Math.max(BitUtil.nextHighestPowerOfTwo(len), 1);
  if (tsize < len * inverseLoadFactor) {
    tsize <<= 1;
  }

  mask=tsize-1;

  table = new int[tsize];
  // (for now) better then: Arrays.fill(table, EMPTY);
  // https://issues.apache.org/jira/browse/SOLR-390
  for (int i=tsize-1; i>=0; i--) table[i]=EMPTY;

  int end = offset + len;
  for (int i=offset; i<end; i++) {
    put(docs[i]);
  }

  size = len;
}
项目:read-open-source-code    文件:HashDocSet.java   
/** Create a HashDocSet from a list of *unique* ids */  
public HashDocSet(int[] docs, int offset, int len, float inverseLoadFactor) {
  int tsize = Math.max(BitUtil.nextHighestPowerOfTwo(len), 1);
  if (tsize < len * inverseLoadFactor) {
    tsize <<= 1;
  }

  mask=tsize-1;

  table = new int[tsize];
  // (for now) better then: Arrays.fill(table, EMPTY);
  // https://issues.apache.org/jira/browse/SOLR-390
  for (int i=tsize-1; i>=0; i--) table[i]=EMPTY;

  int end = offset + len;
  for (int i=offset; i<end; i++) {
    put(docs[i]);
  }

  size = len;
}
项目:read-open-source-code    文件:HashDocSet.java   
/** Create a HashDocSet from a list of *unique* ids */  
public HashDocSet(int[] docs, int offset, int len, float inverseLoadFactor) {
  int tsize = Math.max(BitUtil.nextHighestPowerOfTwo(len), 1);
  if (tsize < len * inverseLoadFactor) {
    tsize <<= 1;
  }

  mask=tsize-1;

  table = new int[tsize];
  // (for now) better then: Arrays.fill(table, EMPTY);
  // https://issues.apache.org/jira/browse/SOLR-390
  for (int i=tsize-1; i>=0; i--) table[i]=EMPTY;

  int end = offset + len;
  for (int i=offset; i<end; i++) {
    put(docs[i]);
  }

  size = len;
}
项目:elasticsearch_my    文件:GeoHashUtils.java   
/**
 * Encode to a morton long value from a given geohash string
 */
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);
}
项目:elasticsearch_my    文件:GeoHashUtils.java   
/**
 * 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)));
}
项目:elasticsearch_my    文件:GeoHashUtils.java   
/**
 * 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());
}
项目:elasticsearch_my    文件:StreamOutput.java   
/**
 * Writes a long in a variable-length format. Writes between one and ten bytes.
 * Values are remapped by sliding the sign bit into the lsb and then encoded as an unsigned number
 * e.g., 0 -;&gt; 0, -1 -;&gt; 1, 1 -;&gt; 2, ..., Long.MIN_VALUE -;&gt; -1, Long.MAX_VALUE -;&gt; -2
 * Numbers with small absolute value will have a small encoding
 * If the numbers are known to be non-negative, use {@link #writeVLong(long)}
 */
public void writeZLong(long i) throws IOException {
    // zig-zag encoding cf. https://developers.google.com/protocol-buffers/docs/encoding?hl=en
    long value = BitUtil.zigZagEncode(i);
    while ((value & 0xFFFFFFFFFFFFFF80L) != 0L) {
        writeByte((byte)((value & 0x7F) | 0x80));
        value >>>= 7;
    }
    writeByte((byte) (value & 0x7F));
}
项目:elasticsearch_my    文件:StreamInput.java   
public long readZLong() throws IOException {
    long accumulator = 0L;
    int i = 0;
    long currentByte;
    while (((currentByte = readByte()) & 0x80L) != 0) {
        accumulator |= (currentByte & 0x7F) << i;
        i += 7;
        if (i > 63) {
            throw new IOException("variable-length stream is too long");
        }
    }
    return BitUtil.zigZagDecode(accumulator | (currentByte << i));
}
项目:lams    文件:BitVector.java   
/** For testing */
public final int getRecomputedCount() {
  int c = 0;
  int end = bits.length;
  for (int i = 0; i < end; i++) {
    c += BitUtil.bitCount(bits[i]);  // sum bits per byte
  }
  return c;
}
项目:my-first-github    文件:OpenBitSet.java   
/** 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;
}
项目:my-first-github    文件:OpenBitSet.java   
/** Returns the popcount or cardinality of "a and not b"
 * or "intersection(a, not(b))".
 * Neither set is modified.
 */
public static long andNotCount(OpenBitSet a, OpenBitSet b) {
  long tot = BitUtil.pop_andnot(a.bits, b.bits, 0, Math.min(a.wlen, b.wlen));
  if (a.wlen > b.wlen) {
    tot += BitUtil.pop_array(a.bits, b.wlen, a.wlen-b.wlen);
  }
  return tot;
}
项目:my-first-github    文件:OpenBitSet.java   
/** Returns the popcount or cardinality of the exclusive-or of the two sets.
* Neither set is modified.
*/
public static long xorCount(OpenBitSet a, OpenBitSet b) {
  long tot = BitUtil.pop_xor(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;
}
项目:search    文件:BitVector.java   
/** For testing */
public final int getRecomputedCount() {
  int c = 0;
  int end = bits.length;
  for (int i = 0; i < end; i++) {
    c += BitUtil.bitCount(bits[i]);  // sum bits per byte
  }
  return c;
}
项目:search    文件:VersionInfo.java   
public VersionInfo(UpdateLog ulog, int nBuckets) {
  this.ulog = ulog;
  IndexSchema schema = ulog.uhandler.core.getLatestSchema(); 
  versionField = getAndCheckVersionField(schema);
  idField = schema.getUniqueKeyField();
  buckets = new VersionBucket[ BitUtil.nextHighestPowerOfTwo(nBuckets) ];
  for (int i=0; i<buckets.length; i++) {
    buckets[i] = new VersionBucket();
  }
}
项目:NYBC    文件:VersionInfo.java   
public VersionInfo(UpdateLog ulog, int nBuckets) {
  this.ulog = ulog;
  SolrCore core = ulog.uhandler.core;
  versionField = getAndCheckVersionField(core.getSchema());
  idField = core.getSchema().getUniqueKeyField();
  buckets = new VersionBucket[ BitUtil.nextHighestPowerOfTwo(nBuckets) ];
  for (int i=0; i<buckets.length; i++) {
    buckets[i] = new VersionBucket();
  }
}
项目:search-core    文件:VersionInfo.java   
public VersionInfo(UpdateLog ulog, int nBuckets) {
  this.ulog = ulog;
  SolrCore core = ulog.uhandler.core;
  versionField = getAndCheckVersionField(core.getSchema());
  idField = core.getSchema().getUniqueKeyField();
  buckets = new VersionBucket[ BitUtil.nextHighestPowerOfTwo(nBuckets) ];
  for (int i=0; i<buckets.length; i++) {
    buckets[i] = new VersionBucket();
  }
}
项目:read-open-source-code    文件:BitVector.java   
/** For testing */
public final int getRecomputedCount() {
  int c = 0;
  int end = bits.length;
  for (int i = 0; i < end; i++) {
    c += BitUtil.bitCount(bits[i]);  // sum bits per byte
  }
  return c;
}
项目:read-open-source-code    文件:VersionInfo.java   
public VersionInfo(UpdateLog ulog, int nBuckets) {
  this.ulog = ulog;
  IndexSchema schema = ulog.uhandler.core.getLatestSchema(); 
  versionField = getAndCheckVersionField(schema);
  idField = schema.getUniqueKeyField();
  buckets = new VersionBucket[ BitUtil.nextHighestPowerOfTwo(nBuckets) ];
  for (int i=0; i<buckets.length; i++) {
    buckets[i] = new VersionBucket();
  }
}
项目:read-open-source-code    文件:BitVector.java   
/** For testing */
public final int getRecomputedCount() {
  int c = 0;
  int end = bits.length;
  for (int i = 0; i < end; i++) {
    c += BitUtil.bitCount(bits[i]);  // sum bits per byte
  }
  return c;
}
项目:read-open-source-code    文件:BitVector.java   
/** For testing */
public final int getRecomputedCount() {
  int c = 0;
  int end = bits.length;
  for (int i = 0; i < end; i++) {
    c += BitUtil.bitCount(bits[i]);  // sum bits per byte
  }
  return c;
}
项目:read-open-source-code    文件:VersionInfo.java   
public VersionInfo(UpdateLog ulog, int nBuckets) {
  this.ulog = ulog;
  IndexSchema schema = ulog.uhandler.core.getLatestSchema(); 
  versionField = getAndCheckVersionField(schema);
  idField = schema.getUniqueKeyField();
  buckets = new VersionBucket[ BitUtil.nextHighestPowerOfTwo(nBuckets) ];
  for (int i=0; i<buckets.length; i++) {
    buckets[i] = new VersionBucket();
  }
}
项目:Maskana-Gestor-de-Conocimiento    文件:BitVector.java   
/** For testing */
public final int getRecomputedCount() {
  int c = 0;
  int end = bits.length;
  for (int i = 0; i < end; i++) {
    c += BitUtil.bitCount(bits[i]);  // sum bits per byte
  }
  return c;
}
项目:elasticsearch_my    文件:GeoPoint.java   
public GeoPoint resetFromGeoHash(long geohashLong) {
    final int level = (int)(12 - (geohashLong&15));
    return this.resetFromIndexHash(BitUtil.flipFlop((geohashLong >>> 4) << ((level * 5) + 2)));
}
项目:elasticsearch_my    文件:GeoHashUtils.java   
/**
 * Encode lon/lat to the geohash based long format (lon/lat interleaved, 4 least significant bits = level)
 */
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;
}
项目:elasticsearch_my    文件:GeoHashUtils.java   
/**
 * 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;
}
项目:Elasticsearch    文件:GeoPoint.java   
public GeoPoint resetFromGeoHash(long geohashLong) {
    final int level = (int)(12 - (geohashLong&15));
    return this.resetFromIndexHash(BitUtil.flipFlop((geohashLong >>> 4) << ((level * 5) + 2)));
}
项目:my-first-github    文件:OpenBitSet.java   
/** @return the number of set bits */
public long cardinality() {
  return BitUtil.pop_array(bits,0,wlen);
}
项目:my-first-github    文件:OpenBitSet.java   
/** Returns the popcount or cardinality of the intersection of the two sets.
  * Neither set is modified.
  */
 public static long intersectionCount(OpenBitSet a, OpenBitSet b) {
   return BitUtil.pop_intersect(a.bits, b.bits, 0, Math.min(a.wlen, b.wlen));
}
项目:my-first-github    文件:OpenBitSetIterator.java   
private void shift() {
  if ((int)word ==0) {wordShift +=32; word = word >>>32; }
  if ((word & 0x0000FFFF) == 0) { wordShift +=16; word >>>=16; }
  if ((word & 0x000000FF) == 0) { wordShift +=8; word >>>=8; }
  indexArray = BitUtil.bitList((byte) word);
}
项目:lams    文件:DataInput.java   
/**
 * Read a {@link BitUtil#zigZagDecode(int) zig-zag}-encoded
 * {@link #readVInt() variable-length} integer.
 * @see DataOutput#writeZInt(int)
 */
public int readZInt() throws IOException {
  return BitUtil.zigZagDecode(readVInt());
}
项目:lams    文件:DataInput.java   
/**
 * 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));
}
项目:lams    文件:DataOutput.java   
/**
 * 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));
}
项目:lams    文件:DataOutput.java   
/**
 * Write a {@link BitUtil#zigZagEncode(long) zig-zag}-encoded
 * {@link #writeVLong(long) variable-length} long. Writes between one and ten
 * bytes. This is typically useful to write small signed ints.
 * @see DataInput#readZLong()
 */
public final void writeZLong(long i) throws IOException {
  writeNegativeVLong(BitUtil.zigZagEncode(i));
}
项目:search    文件:DataInput.java   
/**
 * Read a {@link BitUtil#zigZagDecode(int) zig-zag}-encoded
 * {@link #readVInt() variable-length} integer.
 * @see DataOutput#writeZInt(int)
 */
public int readZInt() throws IOException {
  return BitUtil.zigZagDecode(readVInt());
}
项目:search    文件:DataInput.java   
/**
 * 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));
}
项目:search    文件:DataOutput.java   
/**
 * 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));
}
项目:search    文件:DataOutput.java   
/**
 * Write a {@link BitUtil#zigZagEncode(long) zig-zag}-encoded
 * {@link #writeVLong(long) variable-length} long. Writes between one and ten
 * bytes. This is typically useful to write small signed ints.
 * @see DataInput#readZLong()
 */
public final void writeZLong(long i) throws IOException {
  writeNegativeVLong(BitUtil.zigZagEncode(i));
}