Cambridge SMT System
task.hifst.rtn.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use these files except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 // Copyright 2012 - Gonzalo Iglesias, AdriĆ  de Gispert, William Byrne
14 
15 #ifndef TASK_HIFST_RTN_HPP
16 #define TASK_HIFST_RTN_HPP
17 
25 namespace ucam {
26 namespace hifst {
27 
33 template<class Arc>
34 class RTN {
35 
36  typedef typename Arc::Label Label;
37  typedef std::unordered_map< Label , boost::shared_ptr< fst::Fst<Arc> > >
38  hifst_rtn_t;
39  private:
41  hifst_rtn_t rtn_ , rtn2_;
42 
43  public:
45  RTN() {};
46 
48  inline fst::Fst<Arc> *operator() ( const unsigned cc, const unsigned x, const unsigned y ) {
49  Label hieroindex = APBASETAG + cc * APCCTAG + x * APXTAG + y * APYTAG;
50  typename hifst_rtn_t::iterator itx = rtn_.find ( hieroindex );
51  if ( itx != rtn_.end() )
52  return itx->second.get();
53  return NULL;
54  };
55 
57  inline void Add ( const unsigned cc,
58  const unsigned x,
59  const unsigned y,
60  fst::Fst<Arc> *fst ,
61  fst::Fst<Arc> *fst2 = NULL) {
62  Label hieroindex = APBASETAG + cc * APCCTAG + x * APXTAG + y * APYTAG;
63  rtn_[hieroindex] = boost::shared_ptr<fst::Fst<Arc> > ( fst );
64  if (fst2 != NULL)
65  rtn2_[hieroindex] = boost::shared_ptr<fst::Fst<Arc> > ( fst2 );
66  };
68  inline void Add ( const unsigned cc,
69  const unsigned x,
70  const unsigned y,
71  boost::shared_ptr< fst::Fst<Arc> > fst ,
72  boost::shared_ptr< fst::Fst<Arc> > fst2 ) {
73  Label hieroindex = APBASETAG + cc * APCCTAG + x * APXTAG + y * APYTAG;
74  rtn_[hieroindex] = fst;
75  rtn2_[hieroindex] = fst2;
76  };
77 
79  inline void clear() {
80  rtn_.clear();
81  };
82 
84  inline std::size_t size() {
85  return rtn_.size();
86  };
87 
88  private:
89  ZDISALLOW_COPY_AND_ASSIGN ( RTN );
90 };
91 
92 }
93 } // end namespaces
94 
95 #endif //TASK_HIFST_RTN_HPP
void clear()
Clears hash.
std::size_t size()
Returns size (number of FSAs) in the RTN/cyk grid.
#define APBASETAG
Convenience class that stores pointers to cell FSAs. These pointers are organized through a hash usin...
Definition: fstio.hpp:27
RTN()
constructor
fst::Fst< Arc > * operator()(const unsigned cc, const unsigned x, const unsigned y)
If exists, returns pointer FSA for a given key. Otherwise returns NULL.
#define APXTAG
void Add(const unsigned cc, const unsigned x, const unsigned y, fst::Fst< Arc > *fst, fst::Fst< Arc > *fst2=NULL)
Adds a new cell fsa to the rtn for coordinates cc,x,y, takes ownership of the pointer. fst is the pointer arc and fst2 contains the pointee fst.
void Add(const unsigned cc, const unsigned x, const unsigned y, boost::shared_ptr< fst::Fst< Arc > > fst, boost::shared_ptr< fst::Fst< Arc > > fst2)
Adds a new cell fsa to the rtn for coordinates cc,x,y.
#define APYTAG
#define APCCTAG
Definition: bleu.hpp:14