Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!newsfeed.straub-nv.de!news.albasani.net!.POSTED!not-for-mail From: Jan Burse Newsgroups: comp.lang.java.programmer Subject: Re: BitSet vs BigInteger (false Android doc) Date: Tue, 06 Sep 2011 22:41:31 +0200 Organization: albasani.net Lines: 33 Message-ID: References: <4e613b65$0$311$14726298@news.sunsite.dk> <_ZGdna1ucfWYH__TnZ2dnUVZ_oudnZ2d@earthlink.com> <4e655c24$0$308$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net rmaErA7JjZpjgNL7R4fFgttBEcRUc+j8s3zowXYngebxFlnpon78L74f12vWWp+5tRJkNncUu41pQ3WVN8WOkA== NNTP-Posting-Date: Tue, 6 Sep 2011 20:41:32 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="qFrk1i6pBCVWIpOxYidXJMce/72n9UmVS5sQTgXB2eIOGPkpfFT97Pvdb0UVbu/vEK2vYFnjC9KENJFtGT3eR6bR2VRPbf+7TKX0Ja9GyHSNJ8zF68kyRJd63jSOMzxk"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.1) Gecko/20110830 Firefox/6.0.1 SeaMonkey/2.3.1 In-Reply-To: Cancel-Lock: sha1:uLlG8JJD59r8Rwp/7ScDaR3IGho= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7636 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 to use BitSet if only positive bit patterns come into play and if it is possible to use inline modifications." 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(); BitSet bits = new BitSet(); tab.put(bits,"A"); bits.flip(3); The above will result in a slightly broken hashtable. Although 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(); 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. Best Regards