-rw-r--r-- 1101 cryptattacktester-20230614/subset_cost.cpp raw
#include <map>
#include "subset_cost.h"
using namespace std;
static map<tuple<bigint,bigint,bool>,bigint> subset_cost_length1_cache;
bigint subset_cost_length1(bigint m,bigint n,bool precomputed)
{
if (n <= 0) return 0;
tuple<bigint,bigint,bool> key = make_tuple(m,n,precomputed);
if (subset_cost_length1_cache.count(key) > 0)
return subset_cost_length1_cache[key];
bigint result = 0;
if (!precomputed)
result += n-1; // bit_vector_xor(H.at(i), precomputed.at(i-1))
if (n == m) {
++result; // bit_vector_ixor(s_new, precomputed.at(n-1))
return result;
}
result += subset_cost_length1(n,n,1); // subset(L_sum, L_set, n, n, idx_bits, s_new, H, prefix, precomputed);
for (bigint i = n;i < m;++i) {
++result; // bit_vector_xor(s, H.at(i))
result += subset_cost_length1(i,n-1,1); // subset(L_sum, L_set, i, n-1, idx_bits, s_new, H, prefix_new, precomputed);
}
subset_cost_length1_cache[key] = result;
return result;
}
bigint subset_cost(bigint m,bigint n,bigint length,bool precomputed)
{
return length*subset_cost_length1(m,n,precomputed);
}