本文整理汇总了C++中boost::unordered_map::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::insert方法的具体用法?C++ unordered_map::insert怎么用?C++ unordered_map::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::unordered_map
的用法示例。
在下文中一共展示了unordered_map::insert方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insert
inline void lru_cache_cab::insert(const bucket* pbuck, const double & time)
{
assert(cache.size() + flow_table.size() <=_capacity);
buffer_check.insert(std::make_pair(pbuck, time)); // insert bucket as rec
cache.insert(container_T::value_type(pbuck, time)); // insert bucket
for (auto iter = pbuck->related_rules.begin(); iter != pbuck->related_rules.end(); iter++)
{
// rule_down_count += 1; // controller does not know which rules are kept in OFswtich
auto ins_rule_result = flow_table.insert(std::make_pair(*iter, 1));
if (!ins_rule_result.second)
++ins_rule_result.first->second;
else
++rule_down_count; // controller knows which rules are kept in OFswitch
}
while(cache.size() + flow_table.size() > _capacity) // kick out
{
const bucket * to_kick_buck = cache.right.begin()->second;
cache.right.erase(cache.right.begin());
buffer_check.erase(to_kick_buck);
for (auto iter = to_kick_buck->related_rules.begin(); iter != to_kick_buck->related_rules.end(); ++iter) // dec flow occupy no.
{
--flow_table[*iter];
if (flow_table[*iter] == 0)
flow_table.erase(*iter);
}
}
}
示例2: key
Key* key(uint x) {
std::pair<boost::unordered_map<uint, var>::iterator, bool>
r = keys.insert(std::make_pair((x << 1) + 1, null));
if (r.second)
r.first->second = new Key((x << 1) + 1);
return static_cast<Key*>(r.first->second.ptr);
}
示例3: catch
template <typename T> void insert_visitor(boost::function<void(T)> f) {
try {
fs.insert(std::make_pair(boost::ref(typeid(T)), boost::bind(f, boost::bind(any_cast_f<T>, boost::lambda::_1))));
} catch (boost::bad_any_cast& e) {
std::cout << e.what() << std::endl;
}
}
示例4: processPickups
void Streamer::processPickups(Player &player, const std::vector<SharedCell> &cells)
{
static boost::unordered_map<int, Item::SharedPickup> discoveredPickups;
for (std::vector<SharedCell>::const_iterator c = cells.begin(); c != cells.end(); ++c)
{
for (boost::unordered_map<int, Item::SharedPickup>::const_iterator p = (*c)->pickups.begin(); p != (*c)->pickups.end(); ++p)
{
boost::unordered_map<int, Item::SharedPickup>::iterator d = discoveredPickups.find(p->first);
if (d == discoveredPickups.end())
{
if (checkPlayer(p->second->players, player.playerID, p->second->interiors, player.interiorID, p->second->worlds, player.worldID))
{
if (boost::geometry::comparable_distance(player.position, p->second->position) <= p->second->streamDistance)
{
boost::unordered_map<int, int>::iterator i = internalPickups.find(p->first);
if (i == internalPickups.end())
{
p->second->worldID = !p->second->worlds.empty() ? player.worldID : -1;
}
discoveredPickups.insert(*p);
}
}
}
}
}
if (processingFinalPlayer)
{
boost::unordered_map<int, int>::iterator i = internalPickups.begin();
while (i != internalPickups.end())
{
boost::unordered_map<int, Item::SharedPickup>::iterator d = discoveredPickups.find(i->first);
if (d == discoveredPickups.end())
{
DestroyPickup(i->second);
i = internalPickups.erase(i);
}
else
{
discoveredPickups.erase(d);
++i;
}
}
for (boost::unordered_map<int, Item::SharedPickup>::iterator d = discoveredPickups.begin(); d != discoveredPickups.end(); ++d)
{
if (internalPickups.size() == visiblePickups)
{
break;
}
int internalID = CreatePickup(d->second->modelID, d->second->type, d->second->position[0], d->second->position[1], d->second->position[2], d->second->worldID);
if (internalID == INVALID_ALTERNATE_ID)
{
break;
}
internalPickups.insert(std::make_pair(d->second->pickupID, internalID));
}
discoveredPickups.clear();
}
}
示例5: getImage
cairo_surface_t* getImage(string path)
{
auto it = images.find(path);
if (it != images.end())
return (*it).second;
cairo_surface_t* image = cairo_image_surface_create_from_png(path.c_str());
images.insert(std::make_pair(path, image));
return image;
}
示例6: p
inline boost::unordered_map<K, V> operator>> (object o, boost::unordered_map<K, V>& v)
{
if(o.type != type::MAP) { throw type_error(); }
object_kv* p(o.via.map.ptr);
object_kv* const pend(o.via.map.ptr + o.via.map.size);
for(; p != pend; ++p) {
K key;
p->key.convert(&key);
V val;
p->val.convert(&val);
v.insert(std::pair<K,V>(key, val));
}
return v;
}
示例7: load
void load(Archive & ar, boost::unordered_map<T,U> & t, unsigned int version)
{
// clear the map
t.clear();
// read the size
typedef typename boost::unordered_map<T,U>::size_type size_type;
size_type size;
ar & BOOST_SERIALIZATION_NVP(size);
for (size_type i = 0; i < size; i++) {
// read a pair
std::pair<T, U> pair;
ar & boost::serialization::make_nvp("pair"+i, pair);
// insert it into the map
t.insert(pair);
}
}
示例8: GetString
static CStrInternInternals* GetString(const char* str, size_t len)
{
// g_Strings is not thread-safe, so complain if anyone is using this
// type in non-main threads. (If that's desired, g_Strings should be changed
// to be thread-safe, preferably without sacrificing performance.)
ENSURE(ThreadUtil::IsMainThread());
#if BOOST_VERSION >= 104200
StringsKeyProxy proxy = { str, len };
boost::unordered_map<StringsKey, shared_ptr<CStrInternInternals> >::iterator it =
g_Strings.find(proxy, StringsKeyProxyHash(), StringsKeyProxyEq());
#else
// Boost <= 1.41 doesn't support the new find(), so do a slightly less efficient lookup
boost::unordered_map<StringsKey, shared_ptr<CStrInternInternals> >::iterator it =
g_Strings.find(str);
#endif
if (it != g_Strings.end())
return it->second.get();
shared_ptr<CStrInternInternals> internals(new CStrInternInternals(str, len));
g_Strings.insert(std::make_pair(internals->data, internals));
return internals.get();
}
示例9: generateUmap
void Voxelize::generateUmap(pcl::PointCloud<pcl::PointXYZ> &cloud,double resolution,boost::unordered_map<unordered_map_voxel,un_key> &m)//遍历每个点,生成栅格。然后计算每个栅格的参数
{
double t0 = ros::Time::now().toSec();
un_key tempp; //key键不允许修改,全存在value中
for(int i=0;i<cloud.size();i++)
{
unordered_map_voxel tempv(cloud[i].x,cloud[i].y,cloud[i].z,resolution);
pair<umap::iterator,bool> pair_insert = m.insert(umap::value_type(tempv,tempp));//这个pair就是用来存储插入返回值的,看是否这个栅格已经存在
pair_insert.first->second.vec_index_point.push_back(i);
/*
if(!pair_insert.second)//如果栅格已经存在,那么把value++
{
(pair_insert.first)->second.cout++;
pair_insert.first->second.vec_index_point.push_back(i);
}
else{
pair_insert.first->second.vec_index_point.push_back(i);
}
*/
}
double t2 = ros::Time::now().toSec();
//cout <<"划栅格的时间为"<<(t2-t0)<<endl;
Matrix3d tempmat;
tempmat.setZero();
pcl::PointXYZ temppoint(0,0,0);
for(umap::iterator iter=m.begin();iter!=m.end();)
{
temppoint.x=temppoint.y=temppoint.z=0;
if(iter->second.vec_index_point.size()<10)
{
m.erase(iter++);
continue;
}
for(int j = 0;j<iter->second.vec_index_point.size();j++)
{
double x_ = cloud[iter->second.vec_index_point[j]].x;
double y_ = cloud[iter->second.vec_index_point[j]].y;
double z_ = cloud[iter->second.vec_index_point[j]].z;
tempmat += (Vector3d(x_,y_,z_) * RowVector3d(x_,y_,z_));//存储pipiT的和
temppoint.x += x_;
temppoint.y += y_;
temppoint.z += z_;
}
int n = iter->second.vec_index_point.size();
//cout <<"栅格大小为"<<n<<endl;
Vector3d v(temppoint.x/n,temppoint.y/n,temppoint.z/n);//存储栅格重心
RowVector3d vT(temppoint.x/n,temppoint.y/n,temppoint.z/n);
tempmat /= n;
tempmat -= v*vT;//S
iter->second.matS = tempmat;
//cout <<"S 矩阵= "<< tempmat <<endl;
vector<eigen_sort> vector1(3);//用于排序
//cout <<"tempmat="<<endl<<tempmat<<endl;
EigenSolver<MatrixXd> es(tempmat);
VectorXcd eivals = es.eigenvalues();
MatrixXcd eigenvectors = es.eigenvectors();
//cout << "特征值="<<eivals<<endl;
vector1[0]=eigen_sort(eivals(0).real(),es.eigenvectors().col(0));
vector1[1]=eigen_sort(eivals(1).real(),es.eigenvectors().col(1));
vector1[2]=eigen_sort(eivals(2).real(),es.eigenvectors().col(2));
sort(vector1.begin(),vector1.end());
double lamada1 = vector1[0].eigen_value;
double lamada2 = vector1[1].eigen_value;
double lamada3 = vector1[2].eigen_value;
//cout <<"lamada="<<lamada1<<" "<<lamada2<<" "<<lamada3<<endl;
//
if(vector1[0].eigen_vector(2).real()<0)
{
vector1[0].eigen_vector(2).real() = -vector1[0].eigen_vector(2).real();
}
if(vector1[2].eigen_vector(2).real()<0)
{
vector1[2].eigen_vector(2).real() = -vector1[2].eigen_vector(2).real();
}
iter->second.c = (lamada3-lamada2)/(lamada1+lamada2+lamada3);
iter->second.p = 2*(lamada2-lamada1)/(lamada1+lamada2+lamada3);
iter->second.u = v;
iter->second.v1 = vector1[0].eigen_vector;
iter->second.v3 = vector1[2].eigen_vector;
double c = iter->second.c;
double p = iter->second.p;
iter->second.vector_9D << v(0),v(1),v(2),p*vector1[0].eigen_vector(0).real(),p*vector1[0].eigen_vector(1).real(),
p*vector1[0].eigen_vector(2).real(),c*vector1[2].eigen_vector(0).real(),c*vector1[2].eigen_vector(1).real(),
//.........这里部分代码省略.........
示例10: readStreamData
void IfcPPReaderSTEP::readStreamData( std::string& read_in, const IfcPPModel::IfcPPSchemaVersion& ifc_version, boost::unordered_map<int,shared_ptr<IfcPPEntity> >& target_map )
{
std::string current_numeric_locale(setlocale(LC_NUMERIC, nullptr));
setlocale(LC_NUMERIC,"C");
if( ifc_version.m_ifc_file_schema_enum == IfcPPModel::IFC_VERSION_UNDEFINED || ifc_version.m_ifc_file_schema_enum == IfcPPModel::IFC_VERSION_UNKNOWN )
{
std::wstring error_message;
error_message.append( L"Unsupported IFC version: " );
error_message.append( ifc_version.m_IFC_FILE_SCHEMA );
messageCallback( error_message, StatusCallback::MESSAGE_TYPE_ERROR, __FUNC__ );
progressValueCallback(0.0, "parse");
return;
}
if( read_in.size() == 0 )
{
return;
}
messageCallback( std::wstring( L"Detected IFC version: ") + ifc_version.m_IFC_FILE_SCHEMA, StatusCallback::MESSAGE_TYPE_GENERAL_MESSAGE, "" );
std::stringstream err;
std::vector<std::string> step_lines;
std::vector<std::pair<std::string, shared_ptr<IfcPPEntity> > > vec_entities;
try
{
splitIntoStepLines( read_in, step_lines );
read_in.clear(); // the input string is not needed any more
const size_t num_lines = step_lines.size();
vec_entities.resize( num_lines );
readStepLines( step_lines, vec_entities );
}
catch( UnknownEntityException& e )
{
std::string unknown_keyword = e.m_keyword;
err << __FUNC__ << ": unknown entity: " << unknown_keyword.c_str() << std::endl;
}
catch( IfcPPOutOfMemoryException& e)
{
throw e;
}
catch( IfcPPException& e )
{
err << e.what();
}
catch(std::exception& e)
{
err << e.what();
}
catch(...)
{
err << __FUNC__ << ": error occurred" << std::endl;
}
step_lines.clear();
// copy entities into map so that they can be found during entity attribute initialization
for( size_t ii_entity = 0; ii_entity < vec_entities.size(); ++ii_entity )
{
std::pair<std::string, shared_ptr<IfcPPEntity> >& entity_read_object = vec_entities[ii_entity];
shared_ptr<IfcPPEntity> entity = entity_read_object.second;
if( entity ) // skip aborted entities
{
target_map.insert( std::make_pair( entity->m_id, entity ) );
}
}
try
{
readEntityArguments( ifc_version, vec_entities, target_map );
}
catch( IfcPPOutOfMemoryException& e)
{
throw e;
}
catch( IfcPPException& e )
{
err << e.what();
}
catch(std::exception& e)
{
err << e.what();
}
catch(...)
{
err << __FUNC__ << ": error occurred" << std::endl;
}
setlocale(LC_NUMERIC,current_numeric_locale.c_str());
if( err.tellp() > 0 )
{
messageCallback( err.str().c_str(), StatusCallback::MESSAGE_TYPE_ERROR, __FUNC__ );
}
}
示例11: buildTable
bool buildTable(Kompex::SQLiteStatement * stmt,
int32_t &name_id,
boost::unordered_map<std::string,int32_t> &table_names,
std::string const &sql_table_name,
std::vector<Tile*> list_tiles,
osmscout::Database &map,
osmscout::TypeSet const &typeSet,
bool allow_duplicate_nodes,
bool allow_duplicate_ways,
bool allow_duplicate_areas)
{
// spec area search parameter
osmscout::AreaSearchParameter area_search_param;
area_search_param.SetUseLowZoomOptimization(false);
// create the sql statement
std::string stmt_insert = "INSERT INTO "+sql_table_name;
stmt_insert +=
"(id,node_offsets,way_offsets,area_offsets) VALUES("
"@id,@node_offsets,@way_offsets,@area_offsets);";
try {
stmt->BeginTransaction();
stmt->Sql(stmt_insert);
}
catch(Kompex::SQLiteException &exception) {
qDebug() << "ERROR: SQLite exception with insert statement:"
<< QString::fromStdString(exception.GetString());
return false;
}
// osmscout may return nearby results again so we make
// sure offsets are only included once if requested
std::set<osmscout::FileOffset> set_node_offsets;
std::set<osmscout::FileOffset> set_way_offsets;
std::set<osmscout::FileOffset> set_area_offsets;
// container for blob memory we delete after
// committing the sql transaction
std::vector<char*> list_blobs;
// keep track of the number of transactions and
// commit after a certain limit
size_t transaction_limit=5000;
size_t transaction_count=0;
for(size_t i=0; i < list_tiles.size(); i++) {
// for each tile
// get objects from osmscout
GeoBoundingBox const &bbox = list_tiles[i]->bbox;
std::vector<osmscout::NodeRef> listNodes;
std::vector<osmscout::WayRef> listWays;
std::vector<osmscout::AreaRef> listAreas;
map.GetObjects(bbox.minLon,bbox.minLat,
bbox.maxLon,bbox.maxLat,
typeSet,
listNodes,
listWays,
listAreas);
// merge all of the object refs into one list
// of MapObjects so its easier to manage
std::vector<MapObject> list_map_objects;
list_map_objects.reserve(listNodes.size()+listWays.size()+listAreas.size());
for(size_t j=0; j < listNodes.size(); j++) {
osmscout::NodeRef &nodeRef = listNodes[j];
if(nodeRef->GetName().empty()) {
continue;
}
if(!allow_duplicate_nodes) {
if(set_node_offsets.count(nodeRef->GetFileOffset()) != 0) {
continue;
}
set_node_offsets.insert(nodeRef->GetFileOffset());
}
MapObject map_object;
map_object.name = nodeRef->GetName();
map_object.offset = nodeRef->GetFileOffset();
map_object.type = osmscout::refNode;
list_map_objects.push_back(map_object);
}
for(size_t j=0; j < listWays.size(); j++) {
osmscout::WayRef &wayRef = listWays[j];
if(wayRef->GetName().empty()) {
continue;
}
if(!allow_duplicate_ways) {
if(set_way_offsets.count(wayRef->GetFileOffset()) != 0) {
continue;
}
set_way_offsets.insert(wayRef->GetFileOffset());
}
MapObject map_object;
map_object.name = wayRef->GetName();
map_object.offset = wayRef->GetFileOffset();
map_object.type = osmscout::refWay;
//.........这里部分代码省略.........