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


Groups > comp.lang.java.programmer > #7638

Re: BitSet vs BigInteger (false Android doc)

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: BitSet vs BigInteger (false Android doc)
Date 2011-09-06 14:51 -0700
Organization http://groups.google.com
Message-ID <b19a0af2-c9a5-4367-bfc4-ae16c95fee6d@glegroupsg2000goo.googlegroups.com> (permalink)
References (7 earlier) <j3u3me$k4s$1@news.albasani.net> <4e655c24$0$308$14726298@news.sunsite.dk> <j44ga5$970$1@news.albasani.net> <pbmdnZtHEfnnxPvTnZ2dnUVZ_uWdnZ2d@earthlink.com> <j460hs$u3p$1@news.albasani.net>

Show all headers | View raw


Jan Burse wrote:
> Patricia Shanahan schrieb:
>> conversions. The combination of the comment in question and reading the
>> code shows that they did not take that path. Instead, they always
>> convert for bit manipulation and advise use of BitSet instead.
> 
> The Android comment can be corrected as follows:
>     "It is adviced [sic] to use BitSet if only positive bit patterns
>      come into play and if it is possible to use inline modifications."

The Android comment is not incorrect to begin with.

> But the comment should maybe also include a warning, that using
> objects with inline modifications can lead to more programming
> errors. Reasons are for example that the objects are now mutable
> and thus various side effects can occur. Here is an example:
> 
>      Hashtable tab = new Hashtable();

'Hashtable'?  Really?

>      BitSet bits = new BitSet();
>      tab.put(bits,"A");
>      bits.flip(3);
> 
> The above will result in a slightly broken hashtable. Although

This is an example of the general principle that a mutable key in a 'Map' can mess things up, if you change the key while the 'Map' holds it.  It hardly requires a warning in every mutable class's Javadocs.

> the entries in a hashtable do store the hash once it is computed.
> But the following code will not work as expected:
> 
>      Enumerated en=tab.keys();

'Enumerated'?  Really?

>      while (en.hasMoreElements()) {
>         BitSet bits=en.nextElement();
>         System.out.println("key="+bits+", value="+tab.get(bits));
>      }
> 
> But I guess you all know about these dangers.

Anyone familiar with the dangers of mutable keys in a 'Map' knows at least something about these dangers.

-- 
Lew

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


Thread

BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-02 21:48 +0200
  Re: BitSet vs BigInteger (false Android doc) Arne Vajhøj <arne@vajhoej.dk> - 2011-09-02 16:23 -0400
    Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-02 13:34 -0700
      Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-02 22:51 +0200
        Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-02 18:58 -0700
          Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-03 20:15 +0200
            Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-03 12:37 -0700
              Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-03 22:46 +0200
                Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-03 16:32 -0700
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-04 02:58 +0200
                Re: BitSet vs BigInteger (false Android doc) Arne Vajhøj <arne@vajhoej.dk> - 2011-09-05 19:32 -0400
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 08:58 +0200
                Re: BitSet vs BigInteger (false Android doc) Lew <lewbloch@gmail.com> - 2011-09-06 00:41 -0700
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 11:57 +0200
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 12:12 +0200
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 12:44 +0200
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 12:02 +0200
                Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-06 13:38 -0700
                Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-06 10:33 -0700
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 22:28 +0200
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 22:41 +0200
                Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-06 14:34 -0700
                Re: BitSet vs BigInteger (false Android doc) Lew <lewbloch@gmail.com> - 2011-09-06 14:51 -0700
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-07 00:33 +0200
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-07 00:40 +0200
            Re: BitSet vs BigInteger (false Android doc) Arne Vajhøj <arne@vajhoej.dk> - 2011-09-05 19:26 -0400
      Re: BitSet vs BigInteger (false Android doc) Robert Klemme <shortcutter@googlemail.com> - 2011-09-03 17:01 +0200
    Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-02 22:49 +0200
      Re: BitSet vs BigInteger (false Android doc) Gene Wirchenko <genew@ocis.net> - 2011-09-02 14:48 -0700
  Re: BitSet vs BigInteger (false Android doc) Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-03 13:54 -0400

csiph-web