写了一个异或的函数
//TruncatedStepRow
template<size_t WIDTH> template<size_t W>
TruncatedStepRow<WIDTH>::TruncatedStepRow(const TruncatedStepRow<W>& a, const TruncatedStepRow<W>& b, size_t len, size_t lenIndices, int lenTrim) :
StepRow<WIDTH> {a}
{
cout<<"len="<<len<<endl; //30
cout<<"lenIndices="<<lenIndices<<endl; //1
// cout<<"lenTrim="<<lenTrim<<endl; //3
assert(len+lenIndices <= W);
assert(len-lenTrim+(2*lenIndices) <= WIDTH);
// unsigned char hash[len-lenTrim];
cout<<"colision hash a =";
for(long long unsigned int i=0;i<len;i++){
cout<<a.hash[i];
}
cout<<endl;
cout<<"colision hash b =";
for(long long unsigned int i=0;i<len;i++){
cout<<b.hash[i];
}
cout<<endl;
for (int i = lenTrim; i < (int)len-lenTrim; i++){
hash[i-lenTrim] = a.hash[i] ^ a.hash[i];
}
// cout<<endl;
print_hash(len-lenTrim);
if (a.IndicesBefore(b, len, lenIndices)) {
std::copy(a.hash+len, a.hash+len+lenIndices, hash+len-lenTrim);
std::copy(b.hash+len, b.hash+len+lenIndices, hash+len-lenTrim+lenIndices);
} else {
std::copy(b.hash+len, b.hash+len+lenIndices, hash+len-lenTrim);
std::copy(a.hash+len, a.hash+len+lenIndices, hash+len-lenTrim+lenIndices);
}
//cout<<endl;
//cout<<endl;
}
相同的值异或应该是0才对,为什么输出还是4或者7 啊??
template<size_t WIDTH> template<size_t W>
TruncatedStepRow<WIDTH>::TruncatedStepRow(const TruncatedStepRow<W>& a, const TruncatedStepRow<W>& b, size_t len, size_t lenIndices, int lenTrim) :
StepRow<WIDTH> {a}
{
cout<<"len="<<len<<endl; //30
cout<<"lenIndices="<<lenIndices<<endl; //1
// cout<<"lenTrim="<<lenTrim<<endl; //3
assert(len+lenIndices <= W);
assert(len-lenTrim+(2*lenIndices) <= WIDTH);
// unsigned char hash[len-lenTrim];
cout<<"colision hash a =";
for(long long unsigned int i=0;i<len;i++){
cout<<a.hash[i];
}
cout<<endl;
cout<<"colision hash b =";
for(long long unsigned int i=0;i<len;i++){
cout<<b.hash[i];
}
cout<<endl;
for (int i = lenTrim; i < (int)len-lenTrim; i++){
hash[i-lenTrim] = a.hash[i] ^ a.hash[i];
}
// cout<<endl;
print_hash(len-lenTrim);
if (a.IndicesBefore(b, len, lenIndices)) {
std::copy(a.hash+len, a.hash+len+lenIndices, hash+len-lenTrim);
std::copy(b.hash+len, b.hash+len+lenIndices, hash+len-lenTrim+lenIndices);
} else {
std::copy(b.hash+len, b.hash+len+lenIndices, hash+len-lenTrim);
std::copy(a.hash+len, a.hash+len+lenIndices, hash+len-lenTrim+lenIndices);
}
//cout<<endl;
//cout<<endl;
}
相同的值异或应该是0才对,为什么输出还是4或者7 啊??
全部评论
相关推荐
算法冲刺中:你这bg开不出来,还有谁能开出来呢
查看11道真题和解析 点赞 评论 收藏
分享
球球与墩墩:这不是前端常考的对象扁平化吗,面试官像是前端出来的
const flattern = (obj) => {
const res = {};
const dfs = (curr, path) => {
if(typeof curr === 'object' && curr !== null) {
const isArray = Array.isArray(curr);
for(let key in curr) {
const newPath = path ? isArray ? `${path}[${key}]` : `${path}.${key}` : key;
dfs(curr[key], newPath);
}
} else {
res[path] = curr
}
}
dfs(obj);
return res;
}
查看3道真题和解析 点赞 评论 收藏
分享
点赞 评论 收藏
分享
