模位集算法
假设我有 2 个位集
bitset<1024>; test, current;
我该如何用 test
对 current
取模并将其输出到另一个 bitset<1024>
中?请注意,test
可以是任何形式,而不仅仅是 2 的幂?
寻找完整代码或完整伪代码的答案。我不会接受涉及转换为除 bitset
之外的其他类型的答案,因为虽然在这里使用位集可能会工作得更慢,但在程序的后面位集将会非常快。
Say I have 2 bitsets
bitset<1024> test, current;
How am I supposed to modulus current
with test
and output it in another bitset<1024>
? Note that test
may be of any form, not just powers of two?
Looking for an answer with either complete code or complete pseudocode. I will not accept answers involving converting to another type except bitset
because although using bitsets here may work slower, but later in the program bitsets are going to be very fast.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不想自己实现模算法,可以尝试以下方法:
boost::dynamic_bitset
。dynamic_bitset
。希望有一个 bigint 库可以让您访问其缓冲区,以便您可以将字节从
dynamic_bitset
直接复制到 bigint 中。希望与模运算本身相比,复制 256 个字节的开销可以忽略不计。
哦,bigint 表示形式应该与
dynamic_bitset
具有相同的字节顺序。Here's something you could try if you don't want to implement the modulo algorithm yourself:
std::bitset
, useboost::dynamic_bitset
.dynamic_bitset
.Hopefully, there's a bigint library out there that lets you access its buffer, so that you can copy the bytes from the
dynamic_bitset
directly into the bigint.And hopefully, the overhead of copying the 256 bytes around is negligible compared to the modulo operation itself.
Oh, and the bigint representation should have the same byte order as the
dynamic_bitset
.