depth: make constructor explicit

This commit is contained in:
Justin Viiret
2017-03-30 16:33:11 +11:00
committed by Matthew Barr
parent 37cb93e60f
commit cf82924a39
17 changed files with 248 additions and 221 deletions

View File

@@ -501,7 +501,7 @@ buildCastle(const CastleProto &proto,
// possibly means that we've got a repeat that we can't trigger. We do
// need to cope with it though.
if (contains(triggers, top)) {
min_period = minPeriod(triggers.at(top), cr, &is_reset);
min_period = depth(minPeriod(triggers.at(top), cr, &is_reset));
}
if (min_period > pr.bounds.max) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016, Intel Corporation
* Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -208,7 +208,7 @@ void reformAnchoredRepeatsComponent(NGHolder &g,
/* get bounds */
depth min;
depth max = 1;
depth max(1);
if (selfLoop) {
// A self-loop indicates that this is a '.+' or '.*'
@@ -229,9 +229,9 @@ void reformAnchoredRepeatsComponent(NGHolder &g,
}
}
min = 0;
min = depth(0);
} else {
min = 1;
min = depth(1);
}
*startBegin = min;
@@ -326,8 +326,8 @@ void reformUnanchoredRepeatsComponent(NGHolder &g,
}
/* get bounds */
depth min = 1;
depth max = 1;
depth min(1);
depth max(1);
if (selfLoop) {
// A self-loop indicates that this is a '.+' or '.*'
@@ -349,7 +349,7 @@ void reformUnanchoredRepeatsComponent(NGHolder &g,
DEBUG_PRINTF("min greater than one, skipping\n");
return;
}
min = 0;
min = depth(0);
}
*startBegin += min;
@@ -502,7 +502,7 @@ void collapseVariableDotRepeat(NGHolder &g, NFAVertex start,
startEnd->str().c_str());
if (start == g.start && startEnd->is_infinite()) {
*startEnd = dots.size();
*startEnd = depth(dots.size());
} else if (startEnd->is_finite()) {
*startEnd += dots.size();
}

View File

@@ -372,15 +372,16 @@ deque<unique_ptr<NGHolder>> calcComponents(unique_ptr<NGHolder> g,
}
bool shell_comp = false;
splitIntoComponents(std::move(g), comps, MAX_HEAD_SHELL_DEPTH,
MAX_TAIL_SHELL_DEPTH, &shell_comp);
splitIntoComponents(std::move(g), comps, depth(MAX_HEAD_SHELL_DEPTH),
depth(MAX_TAIL_SHELL_DEPTH), &shell_comp);
if (shell_comp) {
DEBUG_PRINTF("re-running on shell comp\n");
assert(!comps.empty());
auto sc = std::move(comps.back());
comps.pop_back();
splitIntoComponents(std::move(sc), comps, 0, 0, &shell_comp);
splitIntoComponents(std::move(sc), comps, depth(0), depth(0),
&shell_comp);
}
DEBUG_PRINTF("finished; split into %zu components\n", comps.size());

View File

@@ -84,7 +84,7 @@ void checkVertex(const ReportManager &rm, const NGHolder &g, NFAVertex v,
return;
}
if (is_any_start(v, g)) {
info.min = 0;
info.min = depth(0);
info.max = max(info.max, depth(0));
return;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016, Intel Corporation
* Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -26,7 +26,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
/** \file
/**
* \file
* \brief Prefilter Reductions.
*
* This file contains routines for reducing the size of an NFA graph that we
@@ -92,13 +93,13 @@ struct RegionInfo {
u32 id; //!< region id
deque<NFAVertex> vertices; //!< vertices in the region
CharReach reach; //!< union of region reach
depth minWidth = 0; //!< min width of region subgraph
depth maxWidth = depth::infinity(); //!< max width of region subgraph
depth minWidth{0}; //!< min width of region subgraph
depth maxWidth{depth::infinity()}; //!< max width of region subgraph
bool atBoundary = false; //!< region is next to an accept
// Bigger score is better.
size_t score() const {
// FIXME: charreach should be a signal?
// TODO: charreach should be a signal?
size_t numVertices = vertices.size();
if (atBoundary) {
return numVertices - min(PENALTY_BOUNDARY, numVertices);

View File

@@ -105,8 +105,8 @@ typedef boost::filtered_graph<NGHolder, ReachFilter<NGHolder>> RepeatGraph;
struct ReachSubgraph {
vector<NFAVertex> vertices;
depth repeatMin = 0;
depth repeatMax = 0;
depth repeatMin{0};
depth repeatMax{0};
u32 minPeriod = 1;
bool is_reset = false;
enum RepeatType historyType = REPEAT_RING;
@@ -586,8 +586,8 @@ bool processSubgraph(const NGHolder &g, ReachSubgraph &rsi,
range.first, range.second);
return false;
}
rsi.repeatMin = range.first;
rsi.repeatMax = range.second;
rsi.repeatMin = depth(range.first);
rsi.repeatMax = depth(range.second);
// If we've got a self-loop anywhere, we've got inf max.
if (anySelfLoop(g, rsi.vertices.begin(), rsi.vertices.end())) {
@@ -2106,7 +2106,7 @@ void populateFixedTopInfo(const map<u32, u32> &fixed_depth_tops,
td = depth::infinity();
break;
}
depth td_t = fixed_depth_tops.at(top);
depth td_t(fixed_depth_tops.at(top));
if (td == td_t) {
continue;
} else if (td == depth::infinity()) {
@@ -2479,7 +2479,7 @@ bool isPureRepeat(const NGHolder &g, PureRepeat &repeat) {
// have the same report set as the vertices in the repeat.
if (repeat.bounds.min == depth(1) &&
g[g.start].reports == g[v].reports) {
repeat.bounds.min = 0;
repeat.bounds.min = depth(0);
DEBUG_PRINTF("graph is %s repeat\n", repeat.bounds.str().c_str());
} else {
DEBUG_PRINTF("not a supported repeat\n");

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016, Intel Corporation
* Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -94,7 +94,7 @@ vector<DepthMinMax> getDistancesFromSOM(const NGHolder &g_orig) {
if (v_orig == g_orig.startDs || is_virtual_start(v_orig, g_orig)) {
// StartDs and virtual starts always have zero depth.
d = DepthMinMax(0, 0);
d = DepthMinMax(depth(0), depth(0));
} else {
u32 new_idx = g[v_new].index;
d = temp_depths.at(new_idx);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016, Intel Corporation
* Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -157,12 +157,12 @@ depth findMaxWidth(const NGHolder &h, const SpecialEdgeFilter &filter,
if (colors.at(NODE_ACCEPT) == boost::white_color) {
acceptDepth = depth::unreachable();
} else {
acceptDepth = -1 * distance.at(NODE_ACCEPT);
acceptDepth = depth(-1 * distance.at(NODE_ACCEPT));
}
if (colors.at(NODE_ACCEPT_EOD) == boost::white_color) {
acceptEodDepth = depth::unreachable();
} else {
acceptEodDepth = -1 * distance.at(NODE_ACCEPT_EOD);
acceptEodDepth = depth(-1 * distance.at(NODE_ACCEPT_EOD));
}
depth d;

View File

@@ -551,7 +551,7 @@ bool handleMixedPrefixCliche(const NGHolder &h, RoseGraph &g, RoseVertex v,
&& is_subset_of(exits, base_succ)
&& is_subset_of(base_succ, exits_and_repeat_verts)) {
/* we have a jump edge */
ri.repeatMin = 0;
ri.repeatMin = depth(0);
} else {
return false;
}
@@ -802,7 +802,7 @@ void convertAnchPrefixToBounds(RoseBuildImpl &tbi) {
DepthMinMax bounds(pr.bounds); // copy
if (delay_adj > bounds.min) {
bounds.min = 0;
bounds.min = depth(0);
} else {
bounds.min -= delay_adj;
}

View File

@@ -425,8 +425,8 @@ struct OutfixInfo {
RevAccInfo rev_info;
u32 maxBAWidth = 0; //!< max bi-anchored width
depth minWidth = depth::infinity();
depth maxWidth = 0;
depth minWidth{depth::infinity()};
depth maxWidth{0};
u64a maxOffset = 0;
bool in_sbmatcher = false; //!< handled by small-block matcher.

View File

@@ -970,7 +970,7 @@ void RoseSuffixInfo::reset(void) {
rdfa.reset();
haig.reset();
tamarama.reset();
dfa_min_width = 0;
dfa_min_width = depth(0);
dfa_max_width = depth::infinity();
}
@@ -1181,7 +1181,7 @@ void LeftEngInfo::reset(void) {
tamarama.reset();
lag = 0;
leftfix_report = MO_INVALID_IDX;
dfa_min_width = 0;
dfa_min_width = depth(0);
dfa_max_width = depth::infinity();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016, Intel Corporation
* Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -85,7 +85,7 @@ struct LeftEngInfo {
std::shared_ptr<TamaProto> tamarama;
u32 lag = 0U;
ReportID leftfix_report = MO_INVALID_IDX;
depth dfa_min_width = 0;
depth dfa_min_width{0};
depth dfa_max_width = depth::infinity();
bool operator==(const LeftEngInfo &other) const {
@@ -125,7 +125,7 @@ struct RoseSuffixInfo {
std::shared_ptr<raw_som_dfa> haig;
std::shared_ptr<raw_dfa> rdfa;
std::shared_ptr<TamaProto> tamarama;
depth dfa_min_width = 0;
depth dfa_min_width{0};
depth dfa_max_width = depth::infinity();
bool operator==(const RoseSuffixInfo &b) const;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -54,9 +54,10 @@ struct DepthOverflowError {};
*/
class depth {
public:
depth() : val(val_unreachable) {}
/** \brief The default depth is special value "unreachable". */
depth() = default;
depth(u32 v) : val(v) {
explicit depth(u32 v) : val(v) {
if (v > max_value()) {
DEBUG_PRINTF("depth %u too large to represent!\n", v);
throw DepthOverflowError();
@@ -196,6 +197,29 @@ public:
return *this;
}
depth operator-(s32 d) const {
if (is_unreachable()) {
return unreachable();
}
if (is_infinite()) {
return infinity();
}
s64a rv = val - d;
if (rv < 0 || (u64a)rv >= val_infinity) {
DEBUG_PRINTF("depth %lld too large to represent!\n", rv);
throw DepthOverflowError();
}
return depth((u32)rv);
}
depth operator-=(s32 d) {
depth rv = *this - d;
*this = rv;
return *this;
}
#ifdef DUMP_SUPPORT
/** \brief Render as a string, useful for debugging. */
std::string str() const;
@@ -209,7 +233,7 @@ private:
static constexpr u32 val_infinity = (1u << 31) - 1;
static constexpr u32 val_unreachable = 1u << 31;
u32 val;
u32 val = val_unreachable;
};
/**