[英]How to calculate the size of a BitSet in bytes?
I used a Java BitSet
to encode a message. 我使用Java BitSet
对消息进行编码。
My compressed file size comes out to 954kb, but when I do BitSet.cardinality()
, I get around 4mb. 我的压缩文件大小为954kb,但是当我执行BitSet.cardinality()
,我得到的大小约为4mb。 Can you explain this? 你能解释一下吗?
BitSet.cardinality()
returns the number of bits set to true
in the BitSet
. BitSet.cardinality()
返回BitSet
设置为true
的位数。 I think you are looking for BitSet.size()
. 我认为您正在寻找BitSet.size()
。 But keep in mind it will return the number of bits , not bytes . 但是请记住,它将返回位数 ,而不是字节数 。
Assuming after Huffman encoding you have approximately half of the bits set to true
, that means your BitSet
should have a size of around 4.000.000*2 = 8.000.000 bits in your BitSet
which in turn makes around 1.000.000 bytes which is rather close to the 954kb you see. 霍夫曼之后假设编码您有大约一半设为位的true
,这意味着你的BitSet
的大小应该在你的周围4.000.000 * 2 = 8.000.000位的BitSet
这反过来又使周围1,000,000字节,这是相当接近您看到的954kb。
This should explain your observation. 这应该可以解释您的观察。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.