]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
smallwrite: bfs ordering, refine daddy selection
authorJustin Viiret <justin.viiret@intel.com>
Tue, 11 Apr 2017 03:56:51 +0000 (13:56 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 30 May 2017 03:57:32 +0000 (13:57 +1000)
src/nfa/mcclellancompile.cpp
src/smallwrite/smallwrite_build.cpp

index e2466000e128a241554d08c45a2dc103a2178a9d..e875477b18e27f420bd68ba4af606bf5b83973fa 100644 (file)
@@ -841,9 +841,17 @@ void find_better_daddy(dfa_info &info, dstate_id_t curr_id, bool using8bit,
 
     flat_set<dstate_id_t> hinted;
     if (trust_daddy_states) {
-        hinted.insert(currState.daddy);
-        addIfEarlier(hinted, info.raw.start_floating, curr_id);
-        addIfEarlier(hinted, info.raw.start_anchored, curr_id);
+        // Use the daddy already set for this state so long as it isn't already
+        // a Sherman state.
+        if (!info.is_sherman(currState.daddy)) {
+            hinted.insert(currState.daddy);
+        } else {
+            // Fall back to granddaddy, which has already been processed (due
+            // to BFS ordering) and cannot be a Sherman state.
+            dstate_id_t granddaddy = info.states[currState.daddy].daddy;
+            assert(!info.is_sherman(granddaddy));
+            hinted.insert(granddaddy);
+        }
     } else {
         hinted = find_daddy_candidates(info, curr_id);
     }
index fac8d012b9904c3a721c2317aad500f5c82aa498..ce3315e8c65b4f978c84d0d2da600026d387d563 100644 (file)
@@ -452,6 +452,13 @@ void buildAutomaton(LitTrie &trie,
     ACVisitor ac_vis(trie, failure_map, ordering);
     boost::breadth_first_search(trie, trie.root, visitor(ac_vis));
 
+    // Renumber with BFS ordering, which is assumed by other DFA construction
+    // code (i.e. Sherman state computation).
+    size_t idx = 0;
+    for (auto v : ordering) {
+        trie[v].index = idx++;
+    }
+
     // Compute missing edges from failure map.
     for (auto v : ordering) {
         DEBUG_PRINTF("vertex %zu\n", trie[v].index);