Lines Matching refs:state
51 // void Free(S *state, StateId s);
69 S *state = mru_;
71 state->Reset();
72 return state;
77 void Free(S *state, StateId s) {
81 mru_ = state;
93 // you must set the final weight even if the state is non-final to
105 typedef S State;
107 typedef typename State::Arc Arc;
114 using VectorFstBaseImpl<State>::NumStates;
115 using VectorFstBaseImpl<State>::Start;
116 using VectorFstBaseImpl<State>::AddState;
117 using VectorFstBaseImpl<State>::SetState;
118 using VectorFstBaseImpl<State>::ReserveStates;
164 const S *state =
166 if (state) {
168 *copied_state = *state;
183 // Gets a state from its ID; state must exist.
191 // Gets a state from its ID; state must exist.
199 // Gets a state from its ID; return 0 if it doesn't exist.
209 // Gets a state from its ID; add it if necessary.
220 S *state = ExtendState(s);
221 state->final = w;
222 state->flags |= kCacheFinal | kCacheRecent | kCacheModified;
225 // AddArc adds a single arc to state s and does incremental cache
229 S *state = ExtendState(s);
230 state->arcs.push_back(arc);
232 ++state->niepsilons;
235 ++state->noepsilons;
237 const Arc *parc = state->arcs.empty() ? 0 : &(state->arcs.back());
239 state->flags |= kCacheModified;
241 !(state->flags & kCacheProtect)) {
248 // Adds a single arc to state s but delays cache book-keeping.
249 // SetArcs must be called when all PushArc calls at a state are
252 S *state = ExtendState(s);
253 state->arcs.push_back(arc);
256 // Marks arcs of state s as cached and does cache book-keeping after all
259 S *state = ExtendState(s);
260 vector<Arc> &arcs = state->arcs;
261 state->niepsilons = state->noepsilons = 0;
267 ++state->niepsilons;
269 ++state->noepsilons;
272 state->flags |= kCacheArcs | kCacheRecent | kCacheModified;
274 !(state->flags & kCacheProtect)) {
282 S *state = ExtendState(s);
283 state->arcs.reserve(n);
287 S *state = ExtendState(s);
288 const vector<Arc> &arcs = state->arcs;
292 --state->niepsilons;
294 --state->noepsilons;
297 state->arcs.resize(arcs.size() - n);
299 state->flags |= kCacheModified;
301 !(state->flags & kCacheProtect)) {
307 S *state = ExtendState(s);
308 size_t n = state->arcs.size();
309 state->niepsilons = 0;
310 state->noepsilons = 0;
311 state->arcs.clear();
313 state->flags |= kCacheModified;
315 !(state->flags & kCacheProtect)) {
360 VectorFstBaseImpl<State>::DeleteStates();
365 // Is the start state cached?
372 // Is the final weight of state s cached?
374 const S *state = CheckState(s);
375 if (state && state->flags & kCacheFinal) {
376 state->flags |= kCacheRecent;
383 // Are arcs of state s cached?
385 const S *state = CheckState(s);
386 if (state && state->flags & kCacheArcs) {
387 state->flags |= kCacheRecent;
395 const S *state = GetState(s);
396 return state->final;
400 const S *state = GetState(s);
401 return state->arcs.size();
405 const S *state = GetState(s);
406 return state->niepsilons;
410 const S *state = GetState(s);
411 return state->noepsilons;
416 const S *state = GetState(s);
418 data->narcs = state->arcs.size();
419 data->arcs = data->narcs > 0 ? &(state->arcs[0]) : 0;
420 data->ref_count = &(state->ref_count);
427 // Update number of known states taking in account the existence of state s.
433 // Find the mininum never-expanded state Id
476 static const uint32 kCacheProtect = 0x0008; // Mark state as GC protected
479 static const uint32 kCacheModified = 0x0010; // Mark state as modified
485 mutable bool cache_start_; // Is the start state cached?
488 mutable StateId min_unexpanded_state_id_; // minimum never-expanded state Id
489 StateId cache_first_state_id_; // First cached state id
490 S *cache_first_state_; // First cached state
500 // Gets a state from its ID; add it if necessary.
503 // If 'protect_' true and a new state, protects from garbage collection.
505 return cache_first_state_; // Return 1st cached state
507 cache_first_state_id_ = s; // Remember 1st cached state
519 return cache_first_state_; // Return 1st cached state
521 while (NumStates() <= s) // Add state to main cache
523 S *state = VectorFstBaseImpl<S>::GetState(s);
524 if (!state) {
525 state = allocator_->Allocate(s);
526 if (protect_) state->flags |= kCacheProtect;
527 SetState(s, state);
528 if (cache_first_state_id_ != kNoStateId) { // Forget 1st cached state
548 return state;
573 S* state = VectorFstBaseImpl<S>::GetState(s);
574 if (cache_size_ > cache_target && state->ref_count == 0 &&
575 (free_recent || !(state->flags & kCacheRecent)) && s != current) {
576 cache_size_ -= sizeof(S) + state->arcs.capacity() * sizeof(Arc);
577 allocator_->Free(state, s);
581 state->flags &= ~kCacheRecent;
608 // Arcs implemented by an STL vector per state. Similar to VectorState
636 typedef CacheState<A> State;
644 : CacheBaseImpl<State>(impl, preserve_cache) {}
647 void operator=(const CacheImpl<State> &impl); // disallow
651 // Use this to make a state iterator for a CacheBaseImpl-derived Fst,
652 // which must have type 'State' defined. Note this iterator only
653 // returns those states reachable from the initial state, so consider
660 typedef typename F::State State;
661 typedef CacheBaseImpl<State> Impl;
665 fst_.Start(); // force start state
676 // force state expansion
710 // which must have types 'Arc' and 'State' defined.
716 typedef typename F::State State;
718 typedef CacheBaseImpl<State, C> Impl;
746 const State *state_;
753 // which must have types 'Arc' and 'State' defined.
759 typedef typename F::State State;
763 typedef CacheBaseImpl<State, C> Impl;
788 state_->flags |= CacheBaseImpl<State, C>::kCacheModified;
854 State *state_;