@@ -312,14 +312,14 @@ class LatticeBiglmFasterDecoder {
312312 // for the current frame. [note: it's inserted if necessary into hash toks_
313313 // and also into the singly linked list of tokens active on this frame
314314 // (whose head is at active_toks_[frame]).
315- inline Token *FindOrAddToken (PairId state_pair, int32 frame, BaseFloat tot_cost ,
316- bool emitting, bool *changed) {
315+ inline Elem *FindOrAddToken (PairId state_pair, int32 frame,
316+ BaseFloat tot_cost, bool emitting, bool *changed) {
317317 // Returns the Token pointer. Sets "changed" (if non-NULL) to true
318318 // if the token was newly created or the cost changed.
319319 KALDI_ASSERT (frame < active_toks_.size ());
320320 Token *&toks = active_toks_[frame].toks ;
321- Elem *e_found = toks_.Find (state_pair);
322- if (e_found == NULL ) { // no such token presently.
321+ Elem *e_found = toks_.Insert (state_pair, NULL );
322+ if (e_found-> val == NULL ) { // no such token presently.
323323 const BaseFloat extra_cost = 0.0 ;
324324 // tokens on the currently final frame have zero extra_cost
325325 // as any of them could end up
@@ -328,9 +328,9 @@ class LatticeBiglmFasterDecoder {
328328 // NULL: no forward links yet
329329 toks = new_tok;
330330 num_toks_++;
331- toks_. Insert (state_pair, new_tok) ;
331+ e_found-> val = new_tok;
332332 if (changed) *changed = true ;
333- return new_tok ;
333+ return e_found ;
334334 } else {
335335 Token *tok = e_found->val ; // There is an existing Token for this state.
336336 if (tok->tot_cost > tot_cost) { // replace old token
@@ -346,7 +346,7 @@ class LatticeBiglmFasterDecoder {
346346 } else {
347347 if (changed) *changed = false ;
348348 }
349- return tok ;
349+ return e_found ;
350350 }
351351 }
352352
@@ -744,11 +744,11 @@ class LatticeBiglmFasterDecoder {
744744 else if (tot_cost + config_.beam < next_cutoff)
745745 next_cutoff = tot_cost + config_.beam ; // prune by best current token
746746 PairId next_pair = ConstructPair (arc.nextstate , next_lm_state);
747- Token *next_tok = FindOrAddToken (next_pair, frame, tot_cost, true , NULL );
747+ Elem *e_next = FindOrAddToken (next_pair, frame, tot_cost, true , NULL );
748748 // true: emitting, NULL: no change indicator needed
749749
750750 // Add ForwardLink from tok to next_tok (put on head of list tok->links)
751- tok->links = new ForwardLink (next_tok , arc.ilabel , arc.olabel ,
751+ tok->links = new ForwardLink (e_next-> val , arc.ilabel , arc.olabel ,
752752 graph_cost, ac_cost, tok->links );
753753 }
754754 } // for all arcs
@@ -770,7 +770,7 @@ class LatticeBiglmFasterDecoder {
770770 KALDI_ASSERT (queue_.empty ());
771771 BaseFloat best_cost = std::numeric_limits<BaseFloat>::infinity ();
772772 for (const Elem *e = toks_.GetList (); e != NULL ; e = e->tail ) {
773- queue_.push_back (e-> key );
773+ queue_.push_back (e);
774774 // for pruning with current best token
775775 best_cost = std::min (best_cost, static_cast <BaseFloat>(e->val ->tot_cost ));
776776 }
@@ -784,11 +784,12 @@ class LatticeBiglmFasterDecoder {
784784 BaseFloat cutoff = best_cost + config_.beam ;
785785
786786 while (!queue_.empty ()) {
787- PairId state_pair = queue_.back ();
787+ const Elem *e = queue_.back ();
788788 queue_.pop_back ();
789789
790- Token *tok = toks_.Find (state_pair)->val ; // would segfault if state not in
791- // toks_ but this can't happen.
790+ PairId state_pair = e->key ;
791+ Token *tok = e->val ; // would segfault if state not in
792+ // toks_ but this can't happen.
792793 BaseFloat cur_cost = tok->tot_cost ;
793794 if (cur_cost > cutoff) // Don't bother processing successors.
794795 continue ;
@@ -812,15 +813,15 @@ class LatticeBiglmFasterDecoder {
812813 if (tot_cost < cutoff) {
813814 bool changed;
814815 PairId next_pair = ConstructPair (arc.nextstate , next_lm_state);
815- Token *new_tok = FindOrAddToken (next_pair, frame, tot_cost,
816- false , &changed); // false: non-emit
816+ Elem *e_new = FindOrAddToken (next_pair, frame, tot_cost,
817+ false , &changed); // false: non-emit
817818
818- tok->links = new ForwardLink (new_tok , 0 , arc.olabel ,
819+ tok->links = new ForwardLink (e_new-> val , 0 , arc.olabel ,
819820 graph_cost, 0 , tok->links );
820821
821822 // "changed" tells us whether the new token has a different
822823 // cost from before, or is new [if so, add into queue].
823- if (changed) queue_.push_back (next_pair );
824+ if (changed) queue_.push_back (e_new );
824825 }
825826 }
826827 } // for all arcs
@@ -835,7 +836,7 @@ class LatticeBiglmFasterDecoder {
835836 std::vector<TokenList> active_toks_; // Lists of tokens, indexed by
836837 // frame (members of TokenList are toks, must_prune_forward_links,
837838 // must_prune_tokens).
838- std::vector<PairId > queue_; // temp variable used in ProcessNonemitting,
839+ std::vector<const Elem* > queue_; // temp variable used in ProcessNonemitting,
839840 std::vector<BaseFloat> tmp_array_; // used in GetCutoff.
840841 // make it class member to avoid internal new/delete.
841842 const fst::Fst<fst::StdArc> &fst_;
0 commit comments