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


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

Re: BitSet vs boolean[]

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: BitSet vs boolean[]
Date Fri, 18 Jul 2014 21:11:42 +0200
Lines 24
Message-ID <c2t9rfFg9d0U1@mid.individual.net> (permalink)
References <63ris9524feapq3fe288pv7lj1mdpoj444@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net UBGBL6salfzYZLJnbntiBgsWN+x9/KpoEWz9mwlfS9kKZpCAQ=
Cancel-Lock sha1:hBH/eTYon0UcvT0xZEwZ1Uw6RNs=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To <63ris9524feapq3fe288pv7lj1mdpoj444@4ax.com>
Xref csiph.com comp.lang.java.programmer:29119

Show key headers only | View raw


On 18.07.2014 20:51, Roedy Green wrote:
> In terms of minimising space, how big must a boolean array be before
> it pays to use a BitSet?

Well, a BitSet has these members
- long[]
- int
- boolean

If I'm not mistaken that yields sizeof(ref) + 8 * length + 4 + 4 = 
sizeof(ref) + 8 * (length + 1) bytes with length > 0 so at least 
sizeof(ref) + 16 bytes.  I'd say worst case this is 8 + 16 = 24 bytes. 
Sinze a BitSet grows dramatically slower (on average 8 times) than a 
byte array if you add items that should be the max size.

Of course, you can save even more memory by using a byte, short, int or 
long if you know the max set size is 8, 16, 32 or 64 bits and implement 
all the operations via bit logic.

Kind regards

	robert

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


Thread

BitSet vs boolean[] Roedy Green <see_website@mindprod.com.invalid> - 2014-07-18 11:51 -0700
  Re: BitSet vs boolean[] Robert Klemme <shortcutter@googlemail.com> - 2014-07-18 21:11 +0200

csiph-web