C++用于流压缩算法的快速位数组类
实现流压缩算法,通常需要一个超快的 FIFO 位容器类,具有以下功能:
AddBits(UINT n, UINT nBits); // Add lower nBits bits of n
GetBitCount(); // Get the number of bits currently stored
GetBits(BYTE* n, UINT nBits); // Extract n Bits, and remove them
位的数量限制为相对较小的大小(“数据包”大小或更多)。
我正在寻找一个实现此功能的小型 C++ 类。
是的,我可以写一个(并且知道如何做),但可能有人已经写了......
注意:我不想为此而将 boost/whatever-big-lib 添加到我的项目中。
Implementing streaming compression algorithms, one usually need a super-fast FIFO bit container class with the following functions:
AddBits(UINT n, UINT nBits); // Add lower nBits bits of n
GetBitCount(); // Get the number of bits currently stored
GetBits(BYTE* n, UINT nBits); // Extract n Bits, and remove them
The number of bits is bounded to a relatively small size (the 'packet' size or a bit more).
I'm looking for a small C++ class which implement this functionality.
Yes, I can write one (and know how to do it), but probably someone wrote it already...
Note: I don't want to add boost / whatever-big-lib to my project just for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我总是想一次读取 16 位或更少的数据时,我在嵌入式系统中使用的一种方法是保留 32 位长,用于保存当前的部分 16 位字和下一个完整字。然后代码是这样的:
这可能很容易适应与 64 位 long long 一起使用,并允许一次最多提取 32 位。
One approach I've used in embedded systems, when I always wanted to read 16 bits or less at a time, was to keep a 32-bit long which holds the current partial 16-bit word, and the next whole one. Then the code was something like:
That could probably be readily adapted for use with a 64-bit long long and allow for withdrawal of up to 32 bits at a time.
我知道你不想,但你可以使用 增强动态位集并使用供应商/消费者语义在其之上提供 FIFO 功能。
我也不想使用 boost,但这确实没什么大不了的。您无需对库执行任何操作。您只需要在构建系统上提供可用的 boost 并包含正确的包含文件即可。
I know you don't want to, but you could use a boost dynamic bitset and provide the FIFO capability on top of it using supplier/consumer semantics.
I didn't want to use boost either, but it's really not a big deal. You don't have to do anything with libraries. You just need to have boost available on your build system and include the right include files.