Using BitSet in Scala

I would like to know what is the use of BitSet memory in Scala. For example, if I do this:

  var bitArray:BitSet=new BitSet(10)
  bitArray.add(0)
  bitArray.add(2)
  bitArray.add(4)
  bitArray.add(6)
  bitArray.add(8)

How does this compare to an array containing even numbers 0,2,4,6,8?

How to write a number in binary format:

  var bitArray:BitSet=new BitSet(32)
  bitArray.add(5)
  bitArray.add(3)
  bitArray.add(2)
  bitArray.add(1)
  bitArray.add(0)

How does this compare to number 47?

I ask about memory usage. But as a more open question, if you know what are the advantages / disadvantages or the use of BitSet (WR for other common data types).

Thank,

+5
source share
1 answer

You can see the implementation of BitSet in Scala 2.8 here: scala.collection.mutable.BitSet .

Longs. , . , 64, , . 8 .

, 8 , , BitSet. "" - , , .

, BitSet, .

8 , , 64.

Ints, , 5 * 4 = 20 . n n * 4 .

, (maximumNumberStore/8) (countOfNumbersStored * 4).

+16

All Articles