How to store binary data when you only care about speed?으로 대답하려면 몇 가지 비교를 작성하려고합니다. 따라서 std::bitset
을 사용하고 싶습니다. 그러나 공정한 비교를 위해 1D std::bitset
으로 2D를 에뮬레이트하고 싶습니다. 2D 비트 세트가 1D로 저장 될 때 XOR 비트셋
그래서 대신 가진
:bitset<3> b1(string("010"));
bitset<3> b2(string("111"));
내가 사용하고 싶습니다 :
bitset<2 * 3> b1(string("010111"));
데이터 지역성을 최적화 할 수 있습니다. 그러나, 지금은 내 최소한의 예에서 볼 수 있듯이, How should I store and compute Hamming distance between binary codes?에 문제가 있습니다 :
#include <vector>
#include <iostream>
#include <random>
#include <cmath>
#include <numeric>
#include <bitset>
int main()
{
const int N = 1000000;
const int D = 100;
unsigned int hamming_dist[N] = {0};
std::bitset<D> q;
for(int i = 0; i < D; ++i)
q[i] = 1;
std::bitset<N * D> v;
for(int i = 0; i < N; ++i)
for(int j = 0; j < D; ++j)
v[j + i * D] = 1;
for(int i = 0; i < N; ++i)
hamming_dist[i] += (v[i * D]^q).count();
std::cout << "hamming_distance = " << hamming_dist[0] << "\n";
return 0;
}
오류 : 그것을 알고하지 않기 때문에 발생
Georgioss-MacBook-Pro:bit gsamaras$ g++ -Wall bitset.cpp -o bitset
bitset.cpp:24:32: error: invalid operands to binary expression ('reference' (aka
'__bit_reference<std::__1::__bitset<1562500, 100000000> >') and
'std::bitset<D>')
hamming_dist[i] += (v[i * D]^q).count();
~~~~~~~~^~
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/bitset:1096:1: note:
candidate template ignored: could not match 'bitset' against
'__bit_reference'
operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
^
1 error generated.
가 중지! D 비트를 처리 한 후 멈추라 고 어떻게 말할 수 있습니까?
2D data-structure을 사용하지 않고 의미합니다.
하지만 지금은 1D가 아닌 2D 데이터 구조입니다. 맞습니까? : / – gsamaras