From d81a4cb99799a9395ac4157f87c960a81d6e3a14 Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Wed, 20 May 2015 10:23:50 +0200 Subject: [PATCH] Fixes high memory usage (one part): global suffixes do not need to be super-global. --- lib/characterization_family.cpp | 48 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/lib/characterization_family.cpp b/lib/characterization_family.cpp index d27499b..747733a 100644 --- a/lib/characterization_family.cpp +++ b/lib/characterization_family.cpp @@ -13,18 +13,14 @@ using namespace std; characterization_family create_seperating_family(const adaptive_distinguishing_sequence & sequence, const separating_matrix & sep_matrix) { const auto N = sequence.CI.size(); - // all words (global/local) for all states + vector suffixes(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 state_needs_global_suffixes(N, false); + characterization_family ret(N); // 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>> work; work.push({{}, sequence}); while (!work.empty()) { @@ -40,6 +36,8 @@ characterization_family create_seperating_family(const adaptive_distinguishing_s suffixes[state].insert(word); } + trie all_global_separating_words; + for (auto && p : node.CI) { for (auto && q : node.CI) { const auto s = p.second; @@ -50,10 +48,26 @@ characterization_family create_seperating_family(const adaptive_distinguishing_s suffixes[s].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( + [¤t_suffixes](auto w) { current_suffixes.insert(w); }); + + // and fix them + ret[s].global_suffixes = flatten(current_suffixes); + current_suffixes.clear(); + } + 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 } - - // 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( - [¤t_suffixes](auto w) { current_suffixes.insert(w); }); - } - - ret[s].global_suffixes = flatten(current_suffixes); - } - return ret; }