return false;
}
-template<class VertexDepth>
-depth maxDistFromStart(const VertexDepth &d) {
- if (!d.fromStartDotStar.max.is_unreachable()) {
- // A path from startDs, any path, implies we can match at any offset.
- return depth::infinity();
- }
- return d.fromStart.max;
-}
-
static
const depth& maxDistToAccept(const NFAVertexBidiDepth &d) {
if (d.toAccept.max.is_unreachable()) {
const NFAVertexBidiDepth &dv = depths.at(v_idx);
if (report.minOffset) {
- depth max_offset = maxDistFromStart(du) + maxDistToAccept(dv);
+ depth max_offset = maxDistFromStartOfData(du) + maxDistToAccept(dv);
if (max_offset.is_finite() && max_offset < report.minOffset) {
DEBUG_PRINTF("max_offset=%s too small\n", max_offset.str().c_str());
return true;
if (report.minLength && is_any_accept(v, g)) {
// Simple take on min_length. If we're an edge to accept and our max
// dist from start is too small, we can be pruned.
- const depth &width = du.fromStart.max;
+ const depth &width = maxDistFromInit(du);
if (width.is_finite() && width < report.minLength) {
DEBUG_PRINTF("max width %s from start too small for min_length\n",
width.str().c_str());
replaceReports(g, [&](NFAVertex v, ReportID id) {
const auto &d = depths.at(g[v].index);
const depth &min_depth = min(d.fromStartDotStar.min, d.fromStart.min);
- const depth &max_depth = maxDistFromStart(d);
+ const depth &max_depth = maxDistFromStartOfData(d);
DEBUG_PRINTF("vertex %zu has min_depth=%s, max_depth=%s\n", g[v].index,
min_depth.str().c_str(), max_depth.str().c_str());
#include "ng_util.h"
#include "grey.h"
-#include "ng_depth.h" // for NFAVertexDepth
#include "ng_dump.h"
#include "ng_prune.h"
#include "ue2common.h"
namespace ue2 {
-depth maxDistFromInit(const NFAVertexDepth &vd) {
- if (vd.fromStart.max.is_unreachable()) {
- return vd.fromStartDotStar.max;
- } else if (vd.fromStartDotStar.max.is_unreachable()) {
- return vd.fromStart.max;
- } else {
- return max(vd.fromStartDotStar.max, vd.fromStart.max);
- }
-}
-
-depth maxDistFromStartOfData(const NFAVertexDepth &vd) {
- if (vd.fromStartDotStar.max.is_reachable()) {
- /* the irrepressible nature of floating literals cannot be contained */
- return depth::infinity();
- } else {
- return vd.fromStart.max;
- }
-}
-
NFAVertex getSoleDestVertex(const NGHolder &g, NFAVertex a) {
assert(a != NGHolder::null_vertex());
#ifndef NG_UTIL_H
#define NG_UTIL_H
+#include "ng_depth.h"
#include "ng_holder.h"
#include "ue2common.h"
#include "util/flat_containers.h"
#include <boost/graph/depth_first_search.hpp> // for default_dfs_visitor
+#include <algorithm>
#include <map>
#include <unordered_map>
#include <vector>
namespace ue2 {
struct Grey;
-struct NFAVertexDepth;
struct ue2_literal;
-class depth;
class ReportManager;
-depth maxDistFromInit(const NFAVertexDepth &d);
-depth maxDistFromStartOfData(const NFAVertexDepth &d);
+template<class VertexDepth>
+depth maxDistFromInit(const VertexDepth &vd) {
+ if (vd.fromStart.max.is_unreachable()) {
+ return vd.fromStartDotStar.max;
+ } else if (vd.fromStartDotStar.max.is_unreachable()) {
+ return vd.fromStart.max;
+ } else {
+ return std::max(vd.fromStartDotStar.max, vd.fromStart.max);
+ }
+}
+
+template<class VertexDepth>
+depth maxDistFromStartOfData(const VertexDepth &vd) {
+ if (vd.fromStartDotStar.max.is_reachable()) {
+ /* the irrepressible nature of floating literals cannot be contained */
+ return depth::infinity();
+ } else {
+ return vd.fromStart.max;
+ }
+}
/** True if the given vertex is a dot (reachable on any character). */
template<class GraphT>