lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 惠达 王 <wanghuida...@yahoo.cn>
Subject I want to know that why transform numeric to string
Date Fri, 21 Sep 2012 09:54:05 GMT
hi all:
 I want to know that why transform numeric to string?

  public static int longToPrefixCoded(final long val, final int shift, final
BytesRef bytes) {

    if (shift>63 || shift<0)

      throw new IllegalArgumentException("Illegal shift value, must be
0..63");

    int hash, nChars = (63-shift)/7 + 1;

    bytes.offset = 0;

    bytes.length = nChars+1;

    if (bytes.bytes.length < bytes.length) {

      bytes.grow(NumericUtils.BUF_SIZE_LONG);//11

    }

    bytes.bytes[0] = (byte) (hash = (SHIFT_START_LONG + shift));

    long sortableBits = val ^ 0x8000000000000000L;

    sortableBits >>>= shift;

    while (nChars > 0) {

      // Store 7 bits per byte for compatibility

      // with UTF-8 encoding of terms

      bytes.bytes[nChars--] = (byte)(sortableBits & 0x7f);

      sortableBits >>>= 7;

    }

    // calculate hash

    for (int i = 1; i < bytes.length; i++) {

      hash = 31*hash + bytes.bytes[i];

    }

    return hash;

  }



王惠达 (PHP开发工程师, Sysdev Team)
-------------------------
分机:8836
QQ:429335915
mobile: 13795449454
E-mail: williamwang@anjuke.com
上海市浦东新区陆家嘴环路166号未来资产大厦10楼



Mime
View raw message