lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yonik Seeley <yo...@lucidimagination.com>
Subject Re: Integer2String Covnersation
Date Wed, 11 Mar 2009 14:04:45 GMT
On Wed, Mar 11, 2009 at 9:54 AM, Allahbaksh Mohammedali Asadullah
<Allahbaksh_Asadullah@infosys.com> wrote:
> Hi all,
> Can any one explain How function integer2String works.
>
>  public static int int2sortableStr(int val, char[] out, int offset) {
>
>    val += Integer.MIN_VALUE;

This maps MIN_VALUE to 0 and MAX_VALUE to 0xffffffff, making the bits
sort lexicographically the same as the full integer range.  It's the
same as flipping the sign bit.

>    out[offset++] = (char)(val >>> 24);
>    out[offset++] = (char)((val >>> 12) & 0x0fff);
>    out[offset++] = (char)(val & 0x0fff);

This chops up the bits to fit in char sized pieces to make a string,
avoiding invalid character ranges.

-Yonik
http://www.lucidimagination.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message