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


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

Re: BitSet vs boolean[]

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: BitSet vs boolean[]
Date 2014-07-18 21:11 +0200
Message-ID <c2t9rfFg9d0U1@mid.individual.net> (permalink)
References <63ris9524feapq3fe288pv7lj1mdpoj444@4ax.com>

Show all headers | 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