Should be an easy one.
I’m working on Scala trying to handle long sequences of binary data. That is long lists of 0’s and 1’s. What is the ‘best’ way to store/access this kind of data.
The important point here is memory optimisation, so I would like to avoid using an entire byte to store a boolean. Also access is somwhat important, so I would like to avoid paking them into bytes and then into arrays.
Is a BitMap a good idea? Is there such a class in scala?
if not, would it be best to use ByteArray? How would you implement this?
Any other ideas?
Thanks,
You can use java.util.BitSet (perhaps with a couple if clever explicits to make it more Scala-like).
If that is still too costly I would write a class that uses an array internally and pack the bits into ints or bytes.