diff options
author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2013-03-04 11:30:34 +0000 |
---|---|---|
committer | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2013-03-04 11:30:34 +0000 |
commit | 5bf56ba7027cd5f22ff52d0138893f7a585135fb (patch) | |
tree | 19e17fc79b8873e66f211276d4dd169c480cede1 /src/include/fst/queue.h | |
parent | 3da1eb108d36da35333b2d655202791af854996b (diff) | |
parent | 5b6dc79427b8f7eeb6a7ff68034ab8548ce670ea (diff) | |
download | openfst-5bf56ba7027cd5f22ff52d0138893f7a585135fb.tar.gz |
Merge remote-tracking branch 'goog/ics-ub-google-tts' into jb-mr2-devandroid-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1android-cts-4.4_r4android-cts-4.4_r1android-4.4w_r1android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.4_r0.7android-4.4.4_r2.0.1android-4.4.4_r2android-4.4.4_r1.0.1android-4.4.4_r1android-4.4.3_r1.1.0.1android-4.4.3_r1.1android-4.4.3_r1.0.1android-4.4.3_r1android-4.4.2_r2.0.1android-4.4.2_r2android-4.4.2_r1.0.1android-4.4.2_r1android-4.4.1_r1.0.1android-4.4.1_r1android-4.3_r3.1android-4.3_r3android-4.3_r2.3android-4.3_r2.2android-4.3_r2.1android-4.3_r2android-4.3_r1.1android-4.3_r1android-4.3_r0.9.1android-4.3_r0.9android-4.3.1_r1tools_r22.2kitkat-wearkitkat-releasekitkat-mr2.2-releasekitkat-mr2.1-releasekitkat-mr2-releasekitkat-mr1.1-releasekitkat-mr1-releasekitkat-devkitkat-cts-releasekitkat-cts-devjb-mr2.0.0-releasejb-mr2.0-releasejb-mr2-releasejb-mr2-devidea133-weekly-releaseidea133
Diffstat (limited to 'src/include/fst/queue.h')
-rw-r--r-- | src/include/fst/queue.h | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/src/include/fst/queue.h b/src/include/fst/queue.h index e31f087..95a082d 100644 --- a/src/include/fst/queue.h +++ b/src/include/fst/queue.h @@ -23,6 +23,7 @@ #define FST_LIB_QUEUE_H__ #include <deque> +using std::deque; #include <vector> using std::vector; @@ -791,13 +792,13 @@ struct TrivialStateEquivClass { }; -// Pruning queue discipline: Enqueues a state 's' only when its -// shortest distance (so far), as specified by 'distance', is less -// than (as specified by 'comp') the shortest distance Times() the -// 'threshold' to any state in the same equivalence class, as -// specified by the function object 'class_func'. The underlying -// queue discipline is specified by 'queue'. The ownership of 'queue' -// is given to this class. +// Distance-based pruning queue discipline: Enqueues a state 's' +// only when its shortest distance (so far), as specified by +// 'distance', is less than (as specified by 'comp') the shortest +// distance Times() the 'threshold' to any state in the same +// equivalence class, as specified by the function object +// 'class_func'. The underlying queue discipline is specified by +// 'queue'. The ownership of 'queue' is given to this class. template <typename Q, typename L, typename C> class PruneQueue : public QueueBase<typename Q::StateId> { public: @@ -884,6 +885,54 @@ class NaturalPruneQueue : }; +// Filter-based pruning queue discipline: Enqueues a state 's' only +// if allowed by the filter, specified by the function object 'state_filter'. +// The underlying queue discipline is specified by 'queue'. The ownership +// of 'queue' is given to this class. +template <typename Q, typename F> +class FilterQueue : public QueueBase<typename Q::StateId> { + public: + typedef typename Q::StateId StateId; + + FilterQueue(Q *queue, const F &state_filter) + : QueueBase<StateId>(OTHER_QUEUE), + queue_(queue), + state_filter_(state_filter) {} + + ~FilterQueue() { delete queue_; } + + StateId Head() const { return queue_->Head(); } + + // Enqueues only if allowed by state filter. + void Enqueue(StateId s) { + if (state_filter_(s)) { + queue_->Enqueue(s); + } + } + + void Dequeue() { queue_->Dequeue(); } + + void Update(StateId s) {} + bool Empty() const { return queue_->Empty(); } + void Clear() { queue_->Clear(); } + + private: + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const { return Head(); } + virtual void Enqueue_(StateId s) { Enqueue(s); } + virtual void Dequeue_() { Dequeue(); } + virtual void Update_(StateId s) { Update(s); } + virtual bool Empty_() const { return Empty(); } + virtual void Clear_() { return Clear(); } + + Q *queue_; + const F &state_filter_; // Filter to prune states + + DISALLOW_COPY_AND_ASSIGN(FilterQueue); +}; + } // namespace fst #endif |