Skip to content

Commit

Permalink
Deleted hash map
Browse files Browse the repository at this point in the history
  • Loading branch information
samo538 committed Nov 26, 2024
1 parent 550c81d commit 6302fe7
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions src/nfa/operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ namespace {
return alph + x * alph_size + y * alph_size * no_states;
}

typedef struct{
size_t index;
bool used;
}Used_symbol;

Simlib::Util::BinaryRelation compute_iny_direct_simulation(const Nfa& aut) {
// ! Preprocessing
Nfa reverted_nfa;
Expand All @@ -81,21 +76,23 @@ namespace {
size_t no_states = aut.num_of_states();
size_t matrix_size = no_states * no_states * alph_syms.size();

std::vector<int> matrix (matrix_size, 0);
std::unordered_map<Symbol, Used_symbol> index_map;

for (size_t x = 0; x < alph_syms.size(); x++){ // Helper hash table, that matches symbols to matrix indexes (x)
Used_symbol data;
data.used = 0;
data.index = x;
index_map.insert({alph_syms[x], data});
}
std::vector<int> matrix (matrix_size, 0); // Stores the value of cnt()
std::vector<int> index_map {}; // Associates every Symbol with unique value
std::vector<bool> usage_map (alph_syms.size(), false); // Storing usage of Symbols

result_sim_tmp.resize(no_states);
for (size_t i = 0; i < no_states; i++){
result_sim_tmp[i].resize(no_states, true);
}

// TODO this is very memory inefficient
for (size_t x = 0; x < alph_syms.size(); x++){ // Indexing every Symbol with an number
if (index_map.size() <= alph_syms[x]){
index_map.resize(alph_syms[x] + 1 ,0);
}
index_map[alph_syms[x]] = x;
}

reverted_nfa = revert(aut); // Reverted NFA
// ! End of preprocessing

Expand All @@ -112,37 +109,33 @@ namespace {
auto symbol_q = aut.delta[q].begin();
for (size_t x = 0; x < alph_syms.size(); x++) {

size_t p_size;
size_t q_size;
size_t x_index;
if (symbol_q == aut.delta[q].end()){ // If we searched all symbols in q
break;
}

// Helper variables
Symbol active_sym = (*symbol_q).symbol; // get the active symbol
auto x_index_it = index_map.find(active_sym); // get the index of the symbol
x_index = (*x_index_it).second.index;
(*x_index_it).second.used = 1;
// Mark the Symbol as used
usage_map[index_map[active_sym]] = true;

// Compute_lenght
q_size = (*symbol_q).num_of_targets();
// Store_into_matrix
matrix[index_fn(x_index, p, q, alph_syms.size(), no_states)] = q_size;
std::advance(symbol_q, 1);
matrix[index_fn(index_map[active_sym], p, q, alph_syms.size(), no_states)] = q_size;
std::advance(symbol_q, 1);
}
for(SymbolPost active_sym : aut.delta[p]){
auto x_index_it = index_map.find(active_sym.symbol); // get the index of the symbol
if ((*x_index_it).second.used == 0){
bool is_present = usage_map[index_map[active_sym.symbol]]; // get the index of the symbol
if (is_present == false){
if (result_sim_tmp[p][q] != false) {
worklist.push_back(std::pair(p,q)); // worklist append
result_sim_tmp[p][q] = false;
}
}
}
for (std::pair<const Symbol, Used_symbol>& index : index_map){
index.second.used = 0;
}
usage_map.clear();
usage_map.resize(alph_syms.size(), false);
}
}
// ! End of initial refinement
Expand Down

0 comments on commit 6302fe7

Please sign in to comment.