I need to create a hash map which will hold 528 bit binary data. How would the binary data be stored in the hashmap?
Example: 0000000001000000100000000… this is 25 bits. Similarly, I need to store 528 bits.
Do I need to convert this value into some byte array, or can I directly store the data in memory?
An example would be of great help.
Do not complicate your life.
Assuming
valueis ofStringtype, then if you:Store
keyasStringProbably easiest and most readable.
Additional:
To convert a key of type
byte[]toString, you can useBigIntegerclass, for example:Element
keyswill have a value:101101010101010101011010110101010010101.Store
keyasbyte[]Personally I would like to avoid this. Simple default hash function in this case hashes the reference to the array as key, but we want deep hash (all elements must be equal). Following will not work as described:
One way to
fixthis, is to put the array in the class or extend collection calledArrayListand rewrite the equals and hash method. It is not as trivial as it seems – you really need to know what you are doing.Store
keyasBitSetExtracting, adding or manipulating bits is not most efficient – it’s even rather slow. So this seems only good option if it impacts the memory size very noticeably and that’s a problem.
You can create a makeshift
BitSetclass converter like: