// Let an object un-register its existence void object_registrar::unregister_object_imp ( object_id obj ) { set_type::iterator const i = db_.find( obj ); if ( i != db_.end() ) { db_.erase( i ); #if CONTROL_EXTRA_PRINTING std::cout << "Unregistered " << obj << '.' << std::endl; #endif } else { overkilled_.push_back( obj ); #if CONTROL_EXTRA_PRINTING std::cout << "Attempted to unregister a non-existant " << obj << '.' << std::endl; #endif } }
size_type erase (const key_type& k) { if (k.first < k.second) { if (empty ()) { return 0; } iterator pos = find_first_intersect (k); if (pos == end ()) { return 0; } const Key alpha = pos->first; const Key beta = std::min (pos->second, k.first); Key delta = pos->second; size_type count = 0; while (pos != m_set.end () && intersect (*pos, k)) { delta = pos->second; m_set.erase (pos++); ++count; } insert (std::make_pair (alpha, beta)); insert (std::make_pair (k.second, delta)); return count; } return 0; }
std::pair<iterator, bool> insert (const value_type& x) { if (x.first < x.second) { if (empty ()) { return m_set.insert (x); } iterator pos = find_first_touch (x); if (pos == end ()) { //nothing intersects x return m_set.insert (x); } const Key alpha = std::min (x.first, pos->first); Key beta = pos->second; while (pos != m_set.end () && touch (*pos, x)) { beta = pos->second; m_set.erase (pos++); } beta = std::max (beta, x.second); return m_set.insert (std::make_pair (alpha, beta)); } return std::make_pair (m_set.end (), false); }
inline Size Observer::unregisterWith(const ext::shared_ptr<Observable>& h) { boost::lock_guard<boost::recursive_mutex> lock(mutex_); if (h) { QL_REQUIRE(proxy_, "unregister called without a proxy"); h->unregisterObserver(proxy_); } return observables_.erase(h); }
//-----------------------------------------------------------------// handle_type insert(const T& st) { handle_type h; if(erase_set_.empty()) { h = static_cast<handle_type>(array_.size()); array_.push_back(st); } else { set_it it = erase_set_.begin(); h = *it; array_[h] = st; erase_set_.erase(it); } return h; }
//-----------------------------------------------------------------// handle_type create() { handle_type h; if(erase_set_.empty()) { if(current_ < limit_) { h = current_; ++current_; } else { current_ = limit_ - 1; h = 0; } } else { set_it it = erase_set_.begin(); h = *it; erase_set_.erase(it); } return h; }
inline void ObservableSettings::unregisterDeferredObserver( const ext::shared_ptr<Observer::Proxy>& o) { deferredObservers_.erase(o); }
inline Size Observer::unregisterWith(const ext::shared_ptr<Observable>& h) { if (h) h->unregisterObserver(this); return observables_.erase(h); }
inline void ObservableSettings::unregisterDeferredObserver(Observer* o) { deferredObservers_.erase(o); }
void erase (iterator f, iterator l) { m_set.erase (f, l); }
void erase (iterator pos) { m_set.erase (pos); }
/** * Moore's algorithm for DFA state minimization. Identifies all the * indistinguishable subsets of * DFA states and replaces them with a single state. */ void optimize() { // Compilers: Principles, Techniques and Tools SE, page 182 std::unordered_set<set_type, dfa_set_hash, dfa_set_eq> Gamma, newGamma; std::unordered_map<node_type *, const set_type *> Map, newMap; set_type newG; // Create the initial partition - to accepting and non-accepting states Gamma.insert(_nodes); bool initialPartition = true; // Refine partitions until there are no more changes. while (true) { for (auto G : Gamma) // Copy { while (!G.empty()) { newG.clear(); node_type* pivot = nullptr; for (auto it = G.begin(); it != G.end();) { bool equiv; if (pivot == nullptr) pivot = *it; // Initial partition is made by grouping all the terminal states // emiting the same token type (all non-terminals also together). if (initialPartition) equiv = (pivot->terminal() == (*it)->terminal()) && (pivot->get_terminal() == (*it)->get_terminal()); else equiv = check_equivalence(pivot, *it, Map); if (equiv) { newG.insert(*it); G.erase(it++); } else { ++it; } } auto subset = &*newGamma.insert(newG).first; for (auto it = newG.begin(); it != newG.end(); ++it) { newMap.emplace(*it, subset); } } } initialPartition = false; if (newGamma.size() == Gamma.size()) break; else { newGamma.swap(Gamma); newMap.swap(Map); newGamma.clear(); newMap.clear(); } } set_type dead_states; _initial = *newMap.at(_initial)->begin(); for (auto& node : _nodes) { for (auto& transitions : node->transitions) { auto& equiv_class = *newMap.at(transitions.next); auto it = equiv_class.begin(); transitions.next = *it; while (++it != equiv_class.end()) { dead_states.insert(*it); } } } for (auto& node : dead_states) { _nodes.erase(node); delete node; } aggregate(); }