当前位置: 首页>>代码示例>>C++>>正文


C++ unordered_map::size方法代码示例

本文整理汇总了C++中boost::unordered_map::size方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::size方法的具体用法?C++ unordered_map::size怎么用?C++ unordered_map::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::unordered_map的用法示例。


在下文中一共展示了unordered_map::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
        }
    }
}
开发者ID:Zishuo,项目名称:CAB_SDN,代码行数:30,代码来源:lru_cache.hpp

示例2: if

static double
score2(const boost::unordered_map<int, double> &m0,
       const boost::unordered_map<int, double> &m1)
{
  int tmp = 0;
  auto i0 = m0.begin();
  auto i1 = m1.begin();
  while (i0 != m0.end() && i1 != m1.end()) {
    if (i0->first < i1->first) ++i0;
    else if (i0->first > i1->first) ++i1;
    else ++tmp, ++i0, ++i1;
  }
  return m0.size() + m1.size() - tmp;
}
开发者ID:FormatMemory,项目名称:QuerySimulation,代码行数:14,代码来源:main.cpp

示例3: slotObjectsSelected

void IfcTreeWidget::slotObjectsSelected( boost::unordered_map<int, shared_ptr<IfcPPEntity> >& map )
{
	if( m_block_selection_signals )
	{
		return;
	}

	if( map.size() < 1 )
	{
		return;
	}

	// take the first object from map and highlight it
	shared_ptr<IfcPPEntity> object = (*(map.begin())).second;
	int selected_id = object->m_id;

	for( int i=0; i<topLevelItemCount(); ++i )
	{
		QTreeWidgetItem* toplevel_item = topLevelItem( i );
		QTreeWidgetItem* selected_item = ViewerUtil::findItemByIfcId( toplevel_item, selected_id );
		if( selected_item != 0 )
		{
			blockSignals(true);
			m_block_selection_signals = true;
			setCurrentItem( selected_item, 1, QItemSelectionModel::SelectCurrent );
			blockSignals(false);
			m_block_selection_signals = false;
			break;
		}
	}
}
开发者ID:IfcGitHub,项目名称:ifcplusplus,代码行数:31,代码来源:IfcTreeWidget.cpp

示例4: srv_scrape

std::string srv_scrape(const Ctracker_input& ti, t_user* user)
{
	if (m_use_sql && m_config.m_log_scrape)
		m_scrape_log_buffer += Csql_query(m_database, "(?,?,?),")(ntohl(ti.m_ipa))(user ? user->uid : 0)(srv_time()).read();
	if (!m_config.m_anonymous_scrape && !user)
		return "d14:failure reason25:unregistered torrent passe";
	std::string d;
	d += "d5:filesd";
	if (ti.m_info_hashes.empty())
	{
		m_stats.scraped_full++;
		d.reserve(90 * m_torrents.size());
		for (auto& i : m_torrents)
		{
			if (i.second.leechers || i.second.seeders)
				d += (boost::format("20:%sd8:completei%de10:downloadedi%de10:incompletei%dee") % boost::make_iterator_range(i.first) % i.second.seeders % i.second.completed % i.second.leechers).str();
		}
	}
	else
	{
		m_stats.scraped_http++;
		if (ti.m_info_hashes.size() > 1)
			m_stats.scraped_multi++;
		for (auto& j : ti.m_info_hashes)
		{
			if (const t_torrent* i = find_torrent(j))
				d += (boost::format("20:%sd8:completei%de10:downloadedi%de10:incompletei%dee") % j % i->seeders % i->completed % i->leechers).str();
		}
	}
	d += "e";
	if (m_config.m_scrape_interval)
		d += (boost::format("5:flagsd20:min_request_intervali%dee") % m_config.m_scrape_interval).str();
	d += "e";
	return d;
}
开发者ID:blacklizard,项目名称:xbt,代码行数:35,代码来源:server.cpp

示例5: buildGraph

void PropertyExpressionEngine::buildGraph(const ExpressionMap & exprs,
                                          boost::unordered_map<int, ObjectIdentifier> & revNodes, DiGraph & g) const
{
    boost::unordered_map<ObjectIdentifier, int> nodes;
    std::vector<Edge> edges;

    // Build data structure for graph
    for (ExpressionMap::const_iterator it = exprs.begin(); it != exprs.end(); ++it)
        buildGraphStructures(it->first, it->second.expression, nodes, revNodes, edges);

    // Create graph
    g = DiGraph(revNodes.size());

    // Add edges to graph
    for (std::vector<Edge>::const_iterator i = edges.begin(); i != edges.end(); ++i)
        add_edge(i->first, i->second, g);

    // Check for cycles
    bool has_cycle = false;
    int src = -1;
    cycle_detector vis(has_cycle, src);
    depth_first_search(g, visitor(vis));

    if (has_cycle) {
        std::string s =  revNodes[src].toString() + " reference creates a cyclic dependency.";

        throw Base::Exception(s.c_str());
    }
}
开发者ID:Jonham,项目名称:FreeCAD,代码行数:29,代码来源:PropertyExpressionEngine.cpp

示例6: hit

static double
recall(const boost::unordered_map<int, double> &real,
       const boost::unordered_map<int, double> &fake,
       double thres = 0.0)
{
  return 1.0 * hit(real, fake, thres).first / real.size();
}
开发者ID:FormatMemory,项目名称:QuerySimulation,代码行数:7,代码来源:main.cpp

示例7: humanAccountID

std::string RippleAddress::humanAccountID () const
{
    switch (nVersion)
    {
    case VER_NONE:
        throw std::runtime_error ("unset source - humanAccountID");

    case VER_ACCOUNT_ID:
    {
        boost::mutex::scoped_lock sl (rncLock);
        boost::unordered_map< Blob , std::string >::iterator it = rncMap.find (vchData);

        if (it != rncMap.end ())
            return it->second;

        if (rncMap.size () > 10000)
            rncMap.clear ();

        return rncMap[vchData] = ToString ();
    }

    case VER_ACCOUNT_PUBLIC:
    {
        RippleAddress   accountID;

        (void) accountID.setAccountID (getAccountID ());

        return accountID.ToString ();
    }

    default:
        throw std::runtime_error (str (boost::format ("bad source: %d") % int (nVersion)));
    }
}
开发者ID:justmoon,项目名称:rippled,代码行数:34,代码来源:ripple_RippleAddress.cpp

示例8: it

inline void operator<< (object::with_zone& o, const boost::unordered_map<K,V>& v)
{
    o.type = type::MAP;
    if(v.empty()) {
        o.via.map.ptr  = NULL;
        o.via.map.size = 0;
    } else {
        object_kv* p = (object_kv*)o.zone->malloc(sizeof(object_kv)*v.size());
        object_kv* const pend = p + v.size();
        o.via.map.ptr  = p;
        o.via.map.size = v.size();
        typename boost::unordered_map<K,V>::const_iterator it(v.begin());
        do {
            p->key = object(it->first, o.zone);
            p->val = object(it->second, o.zone);
            ++p;
            ++it;
        } while(p < pend);
    }
}
开发者ID:RedSunCMX,项目名称:izenelib,代码行数:20,代码来源:map.hpp

示例9: serialize

		static void serialize(storage_type& s, const boost::unordered_map<T1, T2>& o)
			{
			uint32_t sz = o.size();
			s.serialize(sz);

			for (typename boost::unordered_map<T1,T2>::const_iterator it = o.begin(), it_end = o.end(); it != it_end; ++it)
				{
				s.serialize(it->first);
				s.serialize(it->second);
				}
			}
开发者ID:WantonSoup,项目名称:ufora,代码行数:11,代码来源:BoostContainerSerializers.hpp

示例10: buildGraphStructures

void PropertyExpressionEngine::buildGraphStructures(const ObjectIdentifier & path,
                                                    const boost::shared_ptr<Expression> expression,
                                                    boost::unordered_map<ObjectIdentifier, int> & nodes,
                                                    boost::unordered_map<int, ObjectIdentifier> & revNodes,
                                                    std::vector<Edge> & edges) const
{
    std::set<ObjectIdentifier> deps;

    /* Insert target property into nodes structure */
    if (nodes.find(path) == nodes.end()) {
        int s = nodes.size();

        revNodes[s] = path;
        nodes[path] = s;
    }
    else
        revNodes[nodes[path]] = path;

    /* Get the dependencies for this expression */
    expression->getDeps(deps);

    /* Insert dependencies into nodes structure */
    std::set<ObjectIdentifier>::const_iterator di = deps.begin();
    while (di != deps.end()) {
        Property * prop = di->getProperty();

        if (prop) {
            ObjectIdentifier cPath(di->canonicalPath());

            if (nodes.find(cPath) == nodes.end()) {
                int s = nodes.size();

                nodes[cPath] = s;
            }

            edges.push_back(std::make_pair(nodes[path], nodes[cPath]));
        }
        ++di;
    }
}
开发者ID:Jonham,项目名称:FreeCAD,代码行数:40,代码来源:PropertyExpressionEngine.cpp

示例11: hopscotch_map_sanity_checks

void hopscotch_map_sanity_checks() {
  ASSERT_TRUE(cm2.begin() == cm2.end());
  for (size_t i = 0;i < NINS; ++i) {
    cm2[17 * i] = i;
    um2[17 * i] = i;
  }

  for (size_t i = 0;i < NINS; ++i) {
    assert(cm2[17 * i] == i);
    assert(um2[17 * i] == i);
  }
  assert(cm2.size() == NINS);
  assert(um2.size() == NINS);

  for (size_t i = 0;i < NINS; i+=2) {
    cm2.erase(17*i);
    um2.erase(17*i);
  }
  for (size_t i = 0;i < NINS; i+=2) {
    assert(cm2.count(17*i) == i % 2);
    assert(um2.count(17*i) == i % 2);
    if (cm2.count(17*i)) {
      assert(cm2.find(17*i)->second == i);
    }
  }

  assert(cm2.size() == NINS / 2);
  assert(um2.size() == NINS / 2);

  typedef graphlab::hopscotch_map<uint32_t, uint32_t>::value_type vpair;
  {
    size_t cnt = 0;
    foreach(vpair &v, cm2) {
      ASSERT_EQ(v.second, um2[v.first]);
      ++cnt;
    }
    ASSERT_EQ(cnt, NINS / 2);
  }
开发者ID:HanumathRao,项目名称:graphlab,代码行数:38,代码来源:hopscotch_test.cpp

示例12: save

void save(Archive & ar, const boost::unordered_map<T,U> & t, unsigned int version)
{
    // write the size
    // TODO: should we handle bucket size as well?
    typedef typename boost::unordered_map<T, U>::size_type size_type;
    typedef typename boost::unordered_map<T,U>::const_iterator const_iterator;
    size_type size = t.size();
    ar & BOOST_SERIALIZATION_NVP(size);
    unsigned int count = 0;
    for (const_iterator it = t.begin(); it != t.end(); it++) {
        ar & boost::serialization::make_nvp("pair" + count, *it);
        count++;
    }
}
开发者ID:selmanj,项目名称:repel,代码行数:14,代码来源:boost_serialize_unordered_map.hpp

示例13: update_register_map

/// Only used by Cpp Vertex Shader
void stream_assembler::update_register_map( boost::unordered_map<semantic_value, size_t> const& reg_map )
{
	register_to_input_element_desc.clear();
	register_to_input_element_desc.reserve( reg_map.size() );

	typedef pair<semantic_value, size_t> pair_t;
	for(auto const& sv_reg_pair: reg_map)
	{
		input_element_desc const* elem_desc = layout_->find_desc(sv_reg_pair.first);
		
		if(elem_desc == nullptr)
		{
			register_to_input_element_desc.clear();
			return;
		}

		register_to_input_element_desc.push_back(
			make_pair(sv_reg_pair.second, elem_desc) 
			);
	}
}
开发者ID:2007750219,项目名称:softart,代码行数:22,代码来源:stream_assembler.cpp

示例14: humanAccountID

std::string RippleAddress::humanAccountID () const
{
    switch (nVersion)
    {
    case VER_NONE:
        throw std::runtime_error ("unset source - humanAccountID");

    case VER_ACCOUNT_ID:
    {
        StaticScopedLockType sl (s_lock, __FILE__, __LINE__);
        boost::unordered_map< Blob , std::string >::iterator it = rncMap.find (vchData);

        if (it != rncMap.end ())
            return it->second;

        // VFALCO NOTE Why do we throw everything out? We could keep two maps
        //             here, switch back and forth keep one of them full and clear the
        //             other on a swap - but always check both maps for cache hits.
        //
        if (rncMap.size () > 250000)
            rncMap.clear ();

        return rncMap[vchData] = ToString ();
    }

    case VER_ACCOUNT_PUBLIC:
    {
        RippleAddress   accountID;

        (void) accountID.setAccountID (getAccountID ());

        return accountID.ToString ();
    }

    default:
        throw std::runtime_error (str (boost::format ("bad source: %d") % int (nVersion)));
    }
}
开发者ID:Blizzard-,项目名称:rippled,代码行数:38,代码来源:RippleAddress.cpp

示例15: updateDevice

int DeviceCassandraController::updateDevice(
    const string &devicename, const string &username,
    boost::unordered_map<string, string> &params) {
  if (params.size() <= 0)
    return 0;

  string errorCode = "";
  int result;

  // Get the current device.
  boost::shared_ptr<Device> device = getDevice(devicename, username, errorCode);
  if (!errorCode.empty()) {
    return boost::lexical_cast<int>(errorCode);
  }

  // Check if devicename needs to be changed.
  if (params.count("new_devicename")) {
    // Delete the current device from db.
    result = deleteDevice(devicename, username);
    if (result != 0) {
      return result;
    }
  }

  // Update data in the current device.
  if (params.count("new_devicename")) {
    device->setDevicename(params["new_devicename"]);
  }
  if (params.count("type")) {
    device->setType(params["type"]);
  }
  if (params.count("metadata")) {
    device->setContentMeta(params["metadata"]);
    device->setContentTimestamp(time(NULL));
  }
  if (params.count("dir_ip")) {
    device->setDirIp(params["dir_ip"]);
  }
  if (params.count("dir_port")) {
    unsigned short portValue = -1;
    if (!ControllerHelper::isNullOREmptyString(params["dir_port"]))
      portValue = boost::lexical_cast<unsigned short>(params["dir_port"]);
    device->setDirPort(portValue);
  }
  if (params.count("ip")) {
    device->setIp(params["ip"]);
  }
  if (params.count("port")) {
    unsigned short portValue = -1;
    if (!ControllerHelper::isNullOREmptyString(params["port"]))
      portValue = boost::lexical_cast<unsigned short>(params["port"]);
    device->setPort(portValue);
  }
  if (params.count("os")) {
    device->setOs(params["os"]);
  }
  if (params.count("description")) {
    device->setDescription(params["description"]);
  }
  if (params.count("public_folder")) {
    device->setPublicFolder(params["public_folder"]);
  }
  if (params.count("private_folder")) {
    device->setPrivateFolder(params["private_folder"]);
  }
  if (params.count("is_indexed")) {
    bool is_indexed = false;
    if (boost::iequals(params["is_indexed"], "true"))
      is_indexed = true;
    device->setSearchable(is_indexed);
  }

  // Update lastseen.
  device->setLastSeen(time(NULL));

  // Add the new device.
  result = addDevice(device);
  return result;
}
开发者ID:srcvirus,项目名称:pweb_home_agent,代码行数:79,代码来源:device_cassandra_controller.cpp


注:本文中的boost::unordered_map::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。