]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
findMinWidth, findMaxWidth: width for a given top
authorJustin Viiret <justin.viiret@intel.com>
Tue, 1 Dec 2015 23:24:54 +0000 (10:24 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Sun, 6 Dec 2015 22:38:32 +0000 (09:38 +1100)
Currently only implemented for Castle suffixes.

src/nfa/castlecompile.cpp
src/nfa/castlecompile.h
src/rose/rose_build_impl.h
src/rose/rose_build_misc.cpp
src/rose/rose_build_width.cpp

index b18eb9ad8f3dc60d4f337df645ce813168c625d7..7d37ef81009e969392370677da8c0a9e7ccd98b1 100644 (file)
@@ -708,6 +708,22 @@ depth findMaxWidth(const CastleProto &proto) {
     return max_width;
 }
 
+depth findMinWidth(const CastleProto &proto, u32 top) {
+    if (!contains(proto.repeats, top)) {
+        assert(0); // should not happen
+        return depth::infinity();
+    }
+    return proto.repeats.at(top).bounds.min;
+}
+
+depth findMaxWidth(const CastleProto &proto, u32 top) {
+    if (!contains(proto.repeats, top)) {
+        assert(0); // should not happen
+        return depth(0);
+    }
+    return proto.repeats.at(top).bounds.max;
+}
+
 CastleProto::CastleProto(const PureRepeat &pr) {
     assert(pr.reach.any());
     assert(pr.reports.size() == 1);
index fbafb606bec41202ed6d7e5327721f413550bb14..a35f229dd31d4acec3f55ae31001a0491c92175e 100644 (file)
@@ -85,6 +85,8 @@ struct CastleProto {
 std::set<ReportID> all_reports(const CastleProto &proto);
 depth findMinWidth(const CastleProto &proto);
 depth findMaxWidth(const CastleProto &proto);
+depth findMinWidth(const CastleProto &proto, u32 top);
+depth findMaxWidth(const CastleProto &proto, u32 top);
 
 /**
  * \brief Remap tops to be contiguous.
index 26a7c6064bbbc5aa79a030bc825fc37502fb3860..3112d6398f8fc5fed2753320bc67ca711df372e9 100644 (file)
@@ -130,6 +130,8 @@ private:
 
     friend depth findMinWidth(const suffix_id &s);
     friend depth findMaxWidth(const suffix_id &s);
+    friend depth findMinWidth(const suffix_id &s, u32 top);
+    friend depth findMaxWidth(const suffix_id &s, u32 top);
 };
 
 std::set<ReportID> all_reports(const suffix_id &s);
@@ -138,6 +140,8 @@ bool has_eod_accepts(const suffix_id &s);
 bool has_non_eod_accepts(const suffix_id &s);
 depth findMinWidth(const suffix_id &s);
 depth findMaxWidth(const suffix_id &s);
+depth findMinWidth(const suffix_id &s, u32 top);
+depth findMaxWidth(const suffix_id &s, u32 top);
 size_t hash_value(const suffix_id &s);
 
 /** \brief represents an engine to the left of a rose role */
index 1d58c2415cad2d9862fd32b7dccc00352f43480e..b8775912bbb54f2786584988d525b6d935e01380 100644 (file)
@@ -907,6 +907,18 @@ depth findMinWidth(const suffix_id &s) {
     }
 }
 
+depth findMinWidth(const suffix_id &s, u32 top) {
+    assert(s.graph() || s.castle() || s.haig() || s.dfa());
+    // TODO: take top into account for non-castle suffixes.
+    if (s.graph()) {
+        return findMinWidth(*s.graph());
+    } else if (s.castle()) {
+        return findMinWidth(*s.castle(), top);
+    } else {
+        return s.dfa_min_width;
+    }
+}
+
 depth findMaxWidth(const suffix_id &s) {
     assert(s.graph() || s.castle() || s.haig() || s.dfa());
     if (s.graph()) {
@@ -918,6 +930,18 @@ depth findMaxWidth(const suffix_id &s) {
     }
 }
 
+depth findMaxWidth(const suffix_id &s, u32 top) {
+    assert(s.graph() || s.castle() || s.haig() || s.dfa());
+    // TODO: take top into account for non-castle suffixes.
+    if (s.graph()) {
+        return findMaxWidth(*s.graph());
+    } else if (s.castle()) {
+        return findMaxWidth(*s.castle(), top);
+    } else {
+        return s.dfa_max_width;
+    }
+}
+
 bool has_eod_accepts(const suffix_id &s) {
     assert(s.graph() || s.castle() || s.haig() || s.dfa());
     if (s.graph()) {
index 2a7f2bd6809e11b2b9c0f9dff7b4d52bea5fc726..6bfcee4859bb69f13e08be121017a531d3f705f2 100644 (file)
@@ -94,10 +94,11 @@ u32 findMinWidth(const RoseBuildImpl &tbi, enum rose_literal_table table) {
         }
 
         if (g[v].suffix) {
-            depth suffix_width = findMinWidth(g[v].suffix);
+            depth suffix_width = findMinWidth(g[v].suffix, g[v].suffix.top);
             assert(suffix_width.is_reachable());
-            DEBUG_PRINTF("%zu has suffix (width %s), can fire report at %u\n",
-                         g[v].idx, suffix_width.str().c_str(),
+            DEBUG_PRINTF("%zu has suffix with top %u (width %s), can fire "
+                         "report at %u\n",
+                         g[v].idx, g[v].suffix.top, suffix_width.str().c_str(),
                          w + suffix_width);
             minWidth = min(minWidth, w + suffix_width);
         }
@@ -146,8 +147,9 @@ u32 findMaxBAWidth(const RoseBuildImpl &tbi) {
             if (has_non_eod_accepts(g[v].suffix)) {
                 return ROSE_BOUND_INF;
             }
-            depth suffix_width = findMaxWidth(g[v].suffix);
-            DEBUG_PRINTF("suffix max width %s\n", suffix_width.str().c_str());
+            depth suffix_width = findMaxWidth(g[v].suffix, g[v].suffix.top);
+            DEBUG_PRINTF("suffix max width for top %u is %s\n", g[v].suffix.top,
+                         suffix_width.str().c_str());
             assert(suffix_width.is_reachable());
             if (!suffix_width.is_finite()) {
                 DEBUG_PRINTF("suffix too wide\n");