Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1814

Re: Overflowing HashMap

From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.help
Subject Re: Overflowing HashMap
Date 2012-06-03 13:52 -0700
Organization albasani.net
Message-ID <jqgipp$5fa$1@news.albasani.net> (permalink)
References <0rrms7198ugnfvv3otifhdccfogib2a1vk@4ax.com> <jqg0h6$5hc$1@dont-email.me> <jqg4tj$hp$1@dont-email.me> <jqgckd$gn2$1@news.albasani.net> <iPPyr.56488$ax3.6389@newsfe05.iad>

Show all headers | View raw


Daniel Pitts wrote:
> Lew wrote:
>> P.S., 'TreeMap' has an interesting expression to handle the infamous
>> overflow bug for tree sorting/searching of which Josh Bloch has
>> red-facedly written:
>>
>> int mid = (lo + hi) >>> 1;
>>
>> ...
>
> Actually, this is fine if 0 <= lo <= hi <= Integer.MAX_VALUE, even if lo = hi
> = Integer.MAX_VALUE. The ">>>" handles it, since that is an "unsigned"
> operation. While lo+hi might be out of range for signed Integer, the 32bit
> twos-compliment signed value and the 32 bit unsigned value result in the same
> bit-pattern.

Yes, as I said, I found this an interesting way to handle it. In particular, 
it shows why there is the '>>>' operator and why one might wish to use it. It 
also highlights the importance of precision in reading code as well as writing 
it. It also is elegant.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Overflowing HashMap Roedy Green <see_website@mindprod.com.invalid> - 2012-06-03 07:39 -0700
  Re: Overflowing HashMap Patricia Shanahan <pats@acm.org> - 2012-06-03 08:08 -0700
    Re: Overflowing HashMap Roedy Green <see_website@mindprod.com.invalid> - 2012-06-03 19:59 -0700
      Re: Overflowing HashMap Gene Wirchenko <genew@ocis.net> - 2012-06-04 10:25 -0700
  Re: Overflowing HashMap Knute Johnson <nospam@knutejohnson.com> - 2012-06-03 08:40 -0700
    Re: Overflowing HashMap David Lamb <dalamb@cs.queensu.ca> - 2012-06-03 12:55 -0400
      Re: Overflowing HashMap Lew <noone@lewscanon.com> - 2012-06-03 12:06 -0700
        Re: Overflowing HashMap Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-06-03 13:30 -0700
          Re: Overflowing HashMap Lew <noone@lewscanon.com> - 2012-06-03 13:52 -0700
    Re: Overflowing HashMap Roedy Green <see_website@mindprod.com.invalid> - 2012-06-03 20:51 -0700
      Re: Overflowing HashMap Patricia Shanahan <pats@acm.org> - 2012-06-03 20:59 -0700
        Re: Overflowing HashMap Roedy Green <see_website@mindprod.com.invalid> - 2012-06-03 21:13 -0700

csiph-web