Skip to content

Instantly share code, notes, and snippets.

@kanav99
Created October 13, 2020 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanav99/7f1126d84812d14ff09074ff7cef4ffc to your computer and use it in GitHub Desktop.
Save kanav99/7f1126d84812d14ff09074ff7cef4ffc to your computer and use it in GitHub Desktop.
bool hash_reduce(LatticeVector *v, vector<LatticeVector *> &L, stack<LatticeVector *> &S, int n) {
if (v -> zero) {
return true;
}
for (int i = 0; i < T; ++i) {
unsigned long long h = get_hash(v, i);
cache[i] = h;
vector<LatticeVector *> &list = hash_table[i][h];
int j = 0;
while (j < list.size()) {
auto l = list[j];
int c1 = reduction_factor(v, l);
if (c1 != 0) {
force_reduce(v, l, c1);
if (v->zero) {
return true;
}
else {
S.push(v);
if (v -> norm2 < TARGET_NORM2) {
L.push_back(v);
}
return false;
}
}
// This is the only function call where we call dot products?
int c = reduction_factor(l, v);
if (c != 0) {
removing_id = l->id;
L.erase(remove_if(L.begin(), L.end(), remove_helper), L.end());
// Removing All Occurrences of `l`
for (int k = 0; k < T; ++k) {
unsigned long long hh = get_hash(*l, k);
auto &temp = hash_table[k][hh];
temp.erase(remove_if(temp.begin(), temp.end(), remove_helper), temp.end());
}
// Reduce the vector `l`
force_reduce(l, v, c);
if (!l -> zero)
S.push(l);
}
else {
j += 1;
}
}
}
L.push_back(v);
for (int i = 0; i < T; ++i) {
unsigned long long h = cache[i];
vector<LatticeVector *> &list = hash_table[i][h];
list.push_back(v);
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment