1
Fork 0
mirror of https://github.com/Jaxan/hybrid-ads.git synced 2025-04-27 23:17:44 +02:00

Fixes high memory usage (one part): global suffixes do not need to be super-global.

This commit is contained in:
Joshua Moerman 2015-05-20 10:23:50 +02:00
parent da393cc19f
commit d81a4cb997

View file

@ -13,18 +13,14 @@ using namespace std;
characterization_family create_seperating_family(const adaptive_distinguishing_sequence & sequence, characterization_family create_seperating_family(const adaptive_distinguishing_sequence & sequence,
const separating_matrix & sep_matrix) { const separating_matrix & sep_matrix) {
const auto N = sequence.CI.size(); const auto N = sequence.CI.size();
// all words (global/local) for all states
vector<trie> suffixes(N); vector<trie> suffixes(N);
characterization_family ret(N);
// all global separating sequences, which we will add to a state in the end ...
trie all_global_separating_words;
// ... to these particualr states
vector<bool> state_needs_global_suffixes(N, false);
// First we accumulate the kind-of-UIOs and the separating words we need. We will do this with a // First we accumulate the kind-of-UIOs and the separating words we need. We will do this with a
// breath first search. // breath first search. If we encouter a set of states which is not a singleton, we add
// sequences from the matrix, locally and globally.
stack<pair<word, reference_wrapper<const adaptive_distinguishing_sequence>>> work; stack<pair<word, reference_wrapper<const adaptive_distinguishing_sequence>>> work;
work.push({{}, sequence}); work.push({{}, sequence});
while (!work.empty()) { while (!work.empty()) {
@ -40,6 +36,8 @@ characterization_family create_seperating_family(const adaptive_distinguishing_s
suffixes[state].insert(word); suffixes[state].insert(word);
} }
trie all_global_separating_words;
for (auto && p : node.CI) { for (auto && p : node.CI) {
for (auto && q : node.CI) { for (auto && q : node.CI) {
const auto s = p.second; const auto s = p.second;
@ -50,10 +48,26 @@ characterization_family create_seperating_family(const adaptive_distinguishing_s
suffixes[s].insert(sep_word); suffixes[s].insert(sep_word);
all_global_separating_words.insert(sep_word); all_global_separating_words.insert(sep_word);
state_needs_global_suffixes[s] = true;
} }
} }
// Finalize the suffixes
for (auto && p : node.CI) {
const auto s = p.second;
auto & current_suffixes = suffixes[s];
// local suffixes are done by now
ret[s].local_suffixes = flatten(current_suffixes);
// add the global ones
all_global_separating_words.for_each(
[&current_suffixes](auto w) { current_suffixes.insert(w); });
// and fix them
ret[s].global_suffixes = flatten(current_suffixes);
current_suffixes.clear();
}
continue; continue;
} }
@ -62,21 +76,5 @@ characterization_family create_seperating_family(const adaptive_distinguishing_s
for (auto && c : node.children) work.push({word, c}); // and visit the children with word for (auto && c : node.children) work.push({word, c}); // and visit the children with word
} }
// Then we flatten them into a characterization family.
characterization_family ret(N);
for (state s = 0; s < N; ++s) {
auto & current_suffixes = suffixes[s];
ret[s].local_suffixes = flatten(current_suffixes);
if (state_needs_global_suffixes[s]) {
all_global_separating_words.for_each(
[&current_suffixes](auto w) { current_suffixes.insert(w); });
}
ret[s].global_suffixes = flatten(current_suffixes);
}
return ret; return ret;
} }