void *runner(void *f) { string tmp = "", content = *(string *)f; //將傳過來的指標轉成string for (int i = 0; i < content.length()+1; ++i) { if(content[i]=='\'' && tmp!="" &&((content[i+1]>='a' && content[i+1]<='z') || (content[i+1]>='A' && content[i+1]<='Z')) ) // 單引號的前後為英文單字的 { tmp += content[i]; continue; } if(content[i]>='a' && content[i] <='z') tmp += content[i]; else if(content[i] >='A' && content[i] <= 'Z') tmp += tolower(content[i]); else if(tmp != "") { pthread_mutex_lock(&mutex); //鎖 /* critical section */ iter = m.find(tmp); //搜尋 if(iter != m.end()) iter->second++; //資料重複,所以將次數+1 else m.insert(map_type::value_type(tmp,1)); //插入資料 pthread_mutex_unlock(&mutex); //解鎖 tmp = ""; } } pthread_exit(0); //結束thread }
void SiblingCoupling::operator() (const MeshBase::const_element_iterator & range_begin, const MeshBase::const_element_iterator & range_end, processor_id_type p, map_type & coupled_elements) { LOG_SCOPE("operator()", "SiblingCoupling"); for (const auto & elem : as_range(range_begin, range_end)) { std::vector<const Elem *> active_siblings; const Elem * parent = elem->parent(); if (!parent) continue; #ifdef LIBMESH_ENABLE_AMR parent->active_family_tree(active_siblings); #endif for (const Elem * sibling : active_siblings) if (sibling->processor_id() != p) coupled_elements.insert (std::make_pair(sibling, _dof_coupling)); } }
void probe (map_type& testMap, std::string name, auto keys, auto values, size_t toFind) { // map_type const int width (15); const int precision (6); std::cout << std::setw (width) << keys.size () << " : " << std::setw (width) << name << " : " << std::flush; high_resolution_clock::time_point startTime = high_resolution_clock::now (); auto itValues = begin (values); for_each (begin (keys), end (keys), [&testMap, &itValues](size_t key) { testMap.insert (std::make_pair (key, (*itValues++))); }); high_resolution_clock::time_point findTime = high_resolution_clock::now (); size_t currFind = 0; for (auto k : keys) { if (currFind >= toFind) break; bool exists = testMap.find (k) != testMap.end (); if (exists) ++currFind; } high_resolution_clock::time_point endTime = high_resolution_clock::now (); duration<double> time_span_insert = duration_cast<duration<double>> (findTime-startTime); duration<double> time_span_find = duration_cast<duration<double>> (endTime-findTime); std::cout << "time insert = " << std::fixed << std::setprecision (precision) << time_span_insert.count () << " time find = " << std::setprecision (precision) << time_span_find.count () << std::setw (width) << " found = " << std::setw (width) << currFind << std::endl; }
inline std::error_category const & to_std_category( boost::system::error_category const & cat ) { if( cat == boost::system::system_category() ) { static const std_category system_instance( &cat, 0x1F4D7 ); return system_instance; } else if( cat == boost::system::generic_category() ) { static const std_category generic_instance( &cat, 0x1F4D3 ); return generic_instance; } else { typedef std::map< boost::system::error_category const *, std::unique_ptr<std_category>, cat_ptr_less > map_type; static map_type map_; static std::mutex map_mx_; std::lock_guard<std::mutex> guard( map_mx_ ); map_type::iterator i = map_.find( &cat ); if( i == map_.end() ) { std::unique_ptr<std_category> p( new std_category( &cat, 0 ) ); std::pair<map_type::iterator, bool> r = map_.insert( map_type::value_type( &cat, std::move( p ) ) ); i = r.first; } return *i->second; } }
KOKKOS_INLINE_FUNCTION void operator()(uint32_t i, value_type & v) const { const uint32_t key = Near ? i/collisions : i%(inserts/collisions); typename map_type::insert_result result = map.insert(key,i); v.failed_count += !result.failed() ? 0 : 1; v.max_list = result.list_position() < v.max_list ? v.max_list : result.list_position(); }
static bool parseUrlEncodedParams(char const *str,map_type ¶ms) { // Parse a string in format key1=value1&key2=value2&... // where keys and values are url-encoded using %XX escapes. // For delimiting key=value pairs, either '&' or ';' may be used. // If the same key appears multiple times, only the last one is // stored in the map. ASSERT( str ); while( *str ) { while( *str == ';' || *str == '&' ) { str++; } if( !*str ) { break; } std::pair<std::string,std::string> keyval; size_t len = strcspn(str,"=&;"); if( !len ) { return false; } if( !urlDecode(str,len,keyval.first) ) { return false; } str += len; if( *str == '=' ) { str++; len = strcspn(str,"&;"); if( !urlDecode(str,len,keyval.second) ) { return false; } str += len; } // insert_result is a pair with an iterator pointing to an // existing conflicting member and a bool indicating success std::pair<typename map_type::iterator,bool> insert_result = params.insert(keyval); if( !insert_result.second ) { // key already in params ASSERT( insert_result.first->first == keyval.first ); insert_result.first->second = keyval.second; } } return true; }
static void set(map_type & x, const key_type & v, mapped_type & m) { if (x.count(v) == 0) { x.insert(std::make_pair(v, m)); } else { PyErr_SetString(PyExc_IndexError, "Value already set"); boost::python::throw_error_already_set(); } }
inline OccupationInfo& find_or_insert(Point const& point, Point& mapped_point) { typename map_type::iterator it = map.find(point); if (it == boost::end(map)) { std::pair<typename map_type::iterator, bool> pair = map.insert(std::make_pair(point, OccupationInfo())); it = pair.first; } mapped_point = it->first; return it->second; }
inline class_id class_id_map::get_local(type_id const& type) { std::pair<map_type::iterator, bool> result = m_classes.insert( std::make_pair(type, 0)); if (result.second) result.first->second = m_local_id++; assert(m_local_id >= local_id_base); return result.first->second; }
LUABIND_API class_id allocate_class_id(type_id const& cls) { typedef std::map<type_id, class_id> map_type; static map_type registered; static class_id id = 0; std::pair<map_type::iterator, bool> inserted = registered.insert( std::make_pair(cls, id)); if (inserted.second) ++id; return inserted.first->second; }
size_t listen(dht::DhtRunner& node, std::string chain, map_type& map) { std::future<size_t> token = node.listen(chain, [&map](const std::vector<std::shared_ptr<dht::Value>>& values) { // For every value found... for (const auto& value : values) { // Unpack then register and display it, if it's a new value. std::string content = value->unpack<std::string>(); if(!map.count(content)) { map.insert(std::make_pair(content, get_timestamp())); disp(content); } } // Continue lookup until no values are left. return true; }); if(token.wait_for(std::chrono::seconds(1)) != std::future_status::ready) { verbose("Warning: Could not create a listener since 1000ms."); verbose(" Trying again for 30s..."); if(token.wait_for(std::chrono::seconds(30)) != std::future_status::ready) verbose("Error: Failure."); else verbose(" Done."); } auto v = token.get(); verbose("Starting listening to " + chain + " with token " + std::to_string(v) + "."); return v; }
inline void class_id_map::put(class_id id, type_id const& type) { assert(id < local_id_base); std::pair<map_type::iterator, bool> result = m_classes.insert( std::make_pair(type, 0)); assert( result.second || result.first->second == id || result.first->second >= local_id_base ); if (!result.second && result.first->second >= local_id_base) { --m_local_id; } result.first->second = id; assert(m_local_id >= local_id_base); }
inline operation operation_sequence::new_operation(int id, int error_code) { using namespace std; if ( error_code < 0 || (error_code > BOOST_IOSTREAMS_TEST_MAX_OPERATION_ERROR && error_code != INT_MAX) ) { throw runtime_error( string("The error code ") + lexical_cast<string>(error_code) + " is out of range" ); } if (last_executed_ != INT_MIN) throw runtime_error( "Operations in progress; call reset() " "before creating more operations" ); map_type::const_iterator it = operations_.find(id); if (it != operations_.end()) throw runtime_error( string("The operation ") + lexical_cast<string>(id) + " already exists" ); operation op(*this, id, error_code); operations_.insert(make_pair(id, ptr_type(op.pimpl_))); return op; }
bool register_parser(osmium::io::file_format format, create_parser_type create_function) { if (! m_callbacks.insert(map_type::value_type(format, create_function)).second) { return false; } return true; }
KOKKOS_INLINE_FUNCTION void operator()(size_type i) const { if ( m_src.valid_at(i) ) m_dst.insert(m_src.key_at(i), m_src.value_at(i)); }
short AddType(const char* componentName){ ComponentFactoryFuncPtr function = &createType<Type>; m_Map.insert(std::make_pair(componentName, function)); return 0; };
KOKKOS_INLINE_FUNCTION void operator()(typename device_type::size_type i) const { m_map.insert(i%(m_num_insert/m_num_duplicates), uint32_t(i)); }
static void do_(map_type& m, int key) { m.insert(std::make_pair(key, std::unique_ptr<base>{new T})); filler<Ts...>::do_(m, key + 1); }
inline bool add_factory(message::factory &&factory) { lock guard(m); return factories.insert(map_type::entry(factory.get_type(), factory.move())) != factories.end(); }
KOKKOS_INLINE_FUNCTION void operator()(uint32_t i, value_type & failed_count) const { const uint32_t key = Near ? i/collisions : i%(inserts/collisions); if (map.insert(key,i).failed()) ++failed_count; }
//! computing (phi composition this) Pass& composition_left(const Pass& phi) { pa.insert(phi.pa.begin(), phi.pa.end()); return *this; }
void DefaultCoupling::operator() (const MeshBase::const_element_iterator & range_begin, const MeshBase::const_element_iterator & range_end, processor_id_type p, map_type & coupled_elements) { LOG_SCOPE("operator()", "DefaultCoupling"); #ifdef LIBMESH_ENABLE_PERIODIC bool check_periodic_bcs = (_periodic_bcs && !_periodic_bcs->empty()); UniquePtr<PointLocatorBase> point_locator; if (check_periodic_bcs) { libmesh_assert(_mesh); point_locator = _mesh->sub_point_locator(); } #endif if (!this->_n_levels) { for (MeshBase::const_element_iterator elem_it = range_begin; elem_it != range_end; ++elem_it) { const Elem * const elem = *elem_it; if (elem->processor_id() != p) coupled_elements.insert (std::make_pair(elem,_dof_coupling)); } return; } typedef LIBMESH_BEST_UNORDERED_SET<const Elem*> set_type; set_type next_elements_to_check(range_begin, range_end); set_type elements_to_check; set_type elements_checked; for (unsigned int i=0; i != this->_n_levels; ++i) { elements_to_check.swap(next_elements_to_check); next_elements_to_check.clear(); elements_checked.insert(elements_to_check.begin(), elements_to_check.end()); for (set_type::const_iterator elem_it = elements_to_check.begin(), elem_end = elements_to_check.end(); elem_it != elem_end; ++elem_it) { std::vector<const Elem *> active_neighbors; const Elem * const elem = *elem_it; if (elem->processor_id() != p) coupled_elements.insert (std::make_pair(elem,_dof_coupling)); for (unsigned int s=0; s<elem->n_sides(); s++) { const Elem *neigh = elem->neighbor_ptr(s); // If we have a neighbor here if (neigh) { // Mesh ghosting might ask us about what we want to // distribute along with non-local elements, and those // non-local elements might have remote neighbors, and // if they do then we can't say anything about them. if (neigh == remote_elem) continue; } #ifdef LIBMESH_ENABLE_PERIODIC // We might still have a periodic neighbor here else if (check_periodic_bcs) { libmesh_assert(_mesh); neigh = elem->topological_neighbor (s, *_mesh, *point_locator, _periodic_bcs); } #endif // With no regular *or* periodic neighbors we have nothing // to do. if (!neigh) continue; // With any kind of neighbor, we need to couple to all the // active descendants on our side. #ifdef LIBMESH_ENABLE_AMR if (neigh == elem->neighbor_ptr(s)) neigh->active_family_tree_by_neighbor(active_neighbors,elem); # ifdef LIBMESH_ENABLE_PERIODIC else neigh->active_family_tree_by_topological_neighbor (active_neighbors,elem,*_mesh,*point_locator,_periodic_bcs); # endif #else active_neighbors.clear(); active_neighbors.push_back(neigh); #endif for (std::size_t a=0; a != active_neighbors.size(); ++a) { const Elem * neighbor = active_neighbors[a]; if (!elements_checked.count(neighbor)) next_elements_to_check.insert(neighbor); if (neighbor->processor_id() != p) coupled_elements.insert (std::make_pair(neighbor, _dof_coupling)); } } } } }
bool Emplace(const std::string& key, ElementType&& value) { return m_value->insert(std::make_pair(AUTOJSONCXX_MOVE(key), AUTOJSONCXX_MOVE(value))).second; }
bool insert(void* obj, long key) { std::pair<map_type::iterator,bool> p = m.insert(map_type::value_type(key,obj)); return p.second; }
bool Emplace(const std::string& key, const ElementType& value) { return m_value->insert(std::make_pair(key, value)).second; }
void insert(map_type &m, const set_type& s, const pair_type& r) { pair<set_type, pair_type> p1 = make_pair(s, r); m.insert(p1); }
void PointNeighborCoupling::operator() (const MeshBase::const_element_iterator & range_begin, const MeshBase::const_element_iterator & range_end, processor_id_type p, map_type & coupled_elements) { LOG_SCOPE("operator()", "PointNeighborCoupling"); #ifdef LIBMESH_ENABLE_PERIODIC bool check_periodic_bcs = (_periodic_bcs && !_periodic_bcs->empty()); UniquePtr<PointLocatorBase> point_locator; if (check_periodic_bcs) { libmesh_assert(_mesh); point_locator = _mesh->sub_point_locator(); } #endif if (!this->_n_levels) { for (MeshBase::const_element_iterator elem_it = range_begin; elem_it != range_end; ++elem_it) { const Elem * const elem = *elem_it; if (elem->processor_id() != p) coupled_elements.insert (std::make_pair(elem,_dof_coupling)); } return; } typedef LIBMESH_BEST_UNORDERED_SET<const Elem*> set_type; set_type next_elements_to_check(range_begin, range_end); set_type elements_to_check; set_type elements_checked; for (unsigned int i=0; i != this->_n_levels; ++i) { elements_to_check.swap(next_elements_to_check); next_elements_to_check.clear(); elements_checked.insert(elements_to_check.begin(), elements_to_check.end()); for (set_type::const_iterator elem_it = elements_to_check.begin(), elem_end = elements_to_check.end(); elem_it != elem_end; ++elem_it) { std::set<const Elem *> point_neighbors; const Elem * const elem = *elem_it; if (elem->processor_id() != p) coupled_elements.insert (std::make_pair(elem,_dof_coupling)); #ifdef LIBMESH_ENABLE_PERIODIC // We might have a periodic neighbor here if (check_periodic_bcs) { libmesh_not_implemented(); } else #endif { elem->find_point_neighbors(point_neighbors); } for (std::set<const Elem *>::const_iterator it = point_neighbors.begin(), end_it = point_neighbors.end(); it != end_it; ++it) { const Elem * neighbor = *it; if (!elements_checked.count(neighbor)) next_elements_to_check.insert(neighbor); if (neighbor->processor_id() != p) coupled_elements.insert (std::make_pair(neighbor, _dof_coupling)); } } } }