生成汉明距离最大为2的所有无序比特串对
Generate all unordered pairs of bit strings with Hamming distance at most 2
我正在寻找一种有效的方法来生成汉明距离最大为2的所有无序比特串对(表示为整数)。在这个答案中,示出了对于具有汉明距离1的对,这是如何非常有效地完成的。
换句话说,上面的答案给出了超立方体图的所有边。用这些术语来说,我正在寻找一种有效的方法来生成超立方体的正方形的边。
有没有一些很好的已知快速方法,也许类似地基于比特技巧?
对Nate Kohl的答案有一个简单的修改。
int n = 3;
// examine all vertices from 0...2^n-1
unsigned long long max = 1ULL << n;
for (unsigned long long vertex = 0; vertex < max; ++vertex) {
std::cout << vertex << ':';
// print all vertices that differ from vertex by one bit
unsigned long long mask = 1;
for (int shift_amt = 0; shift_amt < n; ++shift_amt) {
std::cout << ' ' << (vertex ^ (mask << shift_amt));
}
for (int shift_amt1 = 0; shift_amt1 < n; ++shift_amt1) {
for (int shift_amt2 = 0; shift_amt2 < shift_amt1; ++shift_amt2) {
std::cout << ' ' << (vertex ^ (mask << shift_amt1) ^ (mask << shift_amt2));
}
}
std::cout << 'n';
}
相关文章:
- 生成具有均匀汉明权重 (popcount) c++ 的整数
- 汉明距离:计数不正确
- 如何生成统一的随机二进制数以成对计算C++中的汉明距离?
- 汉明距离直觉
- C ++中汉明距离的更快形式(可能利用标准库)
- 寻找汉明数——不是代码或距离
- C++汉明函数
- 生成汉明距离最大为2的所有无序比特串对
- 我应该如何存储和计算二进制代码之间的汉明距离
- 如何有效地确定一个整数的汉明权是否正是一
- 利用汉明距离进行目标检测
- 矢量C++的汉明重量<int>
- 2位集之间的快速汉明距离
- 生成给定汉明距离内的所有字符串
- CRC/奇偶校验/汉明保护16位并行总线
- 我们如何同时使用汉明距离和坐标之间的距离来匹配特征
- 来自 32 个 8 位比较的 32 位汉明字符串形成
- 优化的CUDA基质汉明距离
- 计算汉明权重,在Java中也称为popcount
- 如何计算两个短针的汉明距离