aboutsummaryrefslogtreecommitdiff
path: root/src/include/fst/visit.h
diff options
context:
space:
mode:
authorPrzemyslaw Szczepaniak <pszczepaniak@google.com>2013-03-04 11:30:34 +0000
committerPrzemyslaw Szczepaniak <pszczepaniak@google.com>2013-03-04 11:30:34 +0000
commit5bf56ba7027cd5f22ff52d0138893f7a585135fb (patch)
tree19e17fc79b8873e66f211276d4dd169c480cede1 /src/include/fst/visit.h
parent3da1eb108d36da35333b2d655202791af854996b (diff)
parent5b6dc79427b8f7eeb6a7ff68034ab8548ce670ea (diff)
downloadopenfst-5bf56ba7027cd5f22ff52d0138893f7a585135fb.tar.gz
Diffstat (limited to 'src/include/fst/visit.h')
-rw-r--r--src/include/fst/visit.h21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/include/fst/visit.h b/src/include/fst/visit.h
index a02d86a..5f5059a 100644
--- a/src/include/fst/visit.h
+++ b/src/include/fst/visit.h
@@ -238,18 +238,28 @@ class CopyVisitor {
};
-// Visits input FST up to a state limit following queue order.
+// Visits input FST up to a state limit following queue order. If
+// 'access_only' is true, aborts on visiting first state not
+// accessible from the initial state.
template <class A>
class PartialVisitor {
public:
typedef A Arc;
typedef typename A::StateId StateId;
- explicit PartialVisitor(StateId maxvisit) : maxvisit_(maxvisit) {}
+ explicit PartialVisitor(StateId maxvisit, bool access_only = false)
+ : maxvisit_(maxvisit),
+ access_only_(access_only),
+ start_(kNoStateId) {}
- void InitVisit(const Fst<A> &ifst) { nvisit_ = 0; }
+ void InitVisit(const Fst<A> &ifst) {
+ nvisit_ = 0;
+ start_ = ifst.Start();
+ }
- bool InitState(StateId s, StateId) {
+ bool InitState(StateId s, StateId root) {
+ if (access_only_ && root != start_)
+ return false;
++nvisit_;
return nvisit_ <= maxvisit_;
}
@@ -262,7 +272,10 @@ class PartialVisitor {
private:
StateId maxvisit_;
+ bool access_only_;
StateId nvisit_;
+ StateId start_;
+
};