コード例 #1
0
ファイル: lru_cache.hpp プロジェクト: Zishuo/CAB_SDN
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
0
ファイル: server.cpp プロジェクト: blacklizard/xbt
void read_db_torrents_sql()
{
	try
	{
		if (!m_config.m_auto_register)
		{
			Csql_result result = Csql_query(m_database, "select info_hash, @fid from @files where flags & 1").execute();
			while (Csql_row row = result.fetch_row())
			{
				m_torrents.erase(to_array<char, 20>(row[0]));
				Csql_query(m_database, "delete from @files where @fid = ?")(row[1]).execute();
			}
		}
		if (m_config.m_auto_register && !m_torrents.empty())
			return;
		Csql_result result = Csql_query(m_database, "select info_hash, @completed, @fid, ctime from @files where @fid >= ?")(m_fid_end).execute();
		// m_torrents.reserve(m_torrents.size() + result.size());
		while (Csql_row row = result.fetch_row())
		{
			m_fid_end = std::max<int>(m_fid_end, row[2].i() + 1);
			if (row[0].size() != 20 || find_torrent(row[0].s()))
				continue;
			t_torrent& file = m_torrents[to_array<char, 20>(row[0])];
			if (file.fid)
				continue;
			file.completed = row[1].i();
			file.dirty = false;
			file.fid = row[2].i();
			file.ctime = row[3].i();
		}
	}
	catch (bad_query&)
	{
	}
}
コード例 #3
0
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();
	}
}
コード例 #4
0
ファイル: server.cpp プロジェクト: blacklizard/xbt
void read_db_users()
{
	m_read_db_users_time = srv_time();
	if (!m_use_sql)
		return;
	try
	{
		Csql_query q(m_database, "select @uid");
		if (m_read_users_can_leech)
			q += ", can_leech";
		if (m_read_users_peers_limit)
			q += ", peers_limit";
		if (m_read_users_torrent_pass)
			q += ", torrent_pass";
		q += ", torrent_pass_version";
		if (m_read_users_wait_time)
			q += ", wait_time";
		q += " from @users";
		Csql_result result = q.execute();
		// m_users.reserve(result.size());
		for (auto& i : m_users)
			i.second.marked = true;
		m_users_torrent_passes.clear();
		while (Csql_row row = result.fetch_row())
		{
			t_user& user = m_users[row[0].i()];
			user.marked = false;
			int c = 0;
			user.uid = row[c++].i();
			if (m_read_users_can_leech)
				user.can_leech = row[c++].i();
			if (m_read_users_peers_limit)
				user.peers_limit = row[c++].i();
			if (m_read_users_torrent_pass)
			{
				if (row[c].size() == 32)
					m_users_torrent_passes[to_array<char, 32>(row[c])] = &user;
				c++;
			}
			user.torrent_pass_version = row[c++].i();
			if (m_read_users_wait_time)
				user.wait_time = row[c++].i();
		}
		for (auto i = m_users.begin(); i != m_users.end(); )
		{
			if (i->second.marked)
				m_users.erase(i++);
			else
				i++;
		}
	}
	catch (bad_query&)
	{
	}
}
コード例 #5
0
    // finds a promise by ID, returns and unregisters the promise
    inline boost::promise<message_reply*>* get_promise(uint64_t promise_id) {
      boost::unordered_map<uint64_t, boost::promise<message_reply*>* >
          ::iterator iter = promises.find(promise_id);
      if (iter == promises.end()) return NULL;
      else {
        boost::promise<message_reply*>* ret = iter->second;
        promises.erase(iter);
        return ret;
      }

    }
コード例 #6
0
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);
  }
コード例 #7
0
ファイル: HashRouter.cpp プロジェクト: Blizzard-/rippled
HashRouter::Entry& HashRouter::findCreateEntry (uint256 const& index, bool& created)
{
    boost::unordered_map<uint256, Entry>::iterator fit = mSuppressionMap.find (index);

    if (fit != mSuppressionMap.end ())
    {
        created = false;
        return fit->second;
    }

    created = true;

    int now = UptimeTimer::getInstance ().getElapsedSeconds ();
    int expireTime = now - mHoldTime;

    // See if any supressions need to be expired
    std::map< int, std::list<uint256> >::iterator it = mSuppressionTimes.begin ();

    if ((it != mSuppressionTimes.end ()) && (it->first <= expireTime))
    {
        BOOST_FOREACH (uint256 const & lit, it->second)
        mSuppressionMap.erase (lit);
        mSuppressionTimes.erase (it);
    }
コード例 #8
0
ファイル: server.cpp プロジェクト: blacklizard/xbt
void read_db_torrents()
{
	m_read_db_torrents_time = srv_time();
	if (m_use_sql)
		read_db_torrents_sql();
	else if (!m_config.m_auto_register)
	{
		std::set<t_torrent*> new_torrents;
		std::ifstream is("xbt_torrents.txt");
		for (std::string s; getline(is, s); )
		{
			s = hex_decode(s);
			if (s.size() == 20)
				new_torrents.insert(&m_torrents[to_array<char, 20>(s)]);
		}
		for (auto i = m_torrents.begin(); i != m_torrents.end(); )
		{
			if (new_torrents.count(&i->second))
				i++;
			else
				m_torrents.erase(i++);
		}
	}
}
コード例 #9
0
void Task::cleanHashFeatures (const int current_image_idx,
                        const int max_number_img,
                        boost::unordered_map<boost::uuids::uuid, StereoFeature> &hash)
{
    if (current_image_idx > max_number_img)
    {
        const int border_image_idx = (current_image_idx - max_number_img);

        /** All the images with idx <= border_image_idx should be eliminated **/
        for (boost::unordered_map<boost::uuids::uuid, StereoFeature>::const_iterator
                it = hash.begin(); it != hash.end(); ++it)
        {
            if (it->second.img_idx <= border_image_idx)
            {
                #ifdef DEBUG_PRINTS
                std::cout<<"[CLEAN_HASH_FEATURES] Remove from hash "<<boost::lexical_cast<std::string>(it->first)<<"\n";
                #endif
                hash.erase(it);
            }
        }
    }

    return;
}
コード例 #10
0
bool LLNetMap::mmsetunmark::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
	mm_MarkerColors.erase(mPtr->mClosestAgentAtLastRightClick);
	return true;
}
コード例 #11
0
ファイル: voxel.cpp プロジェクト: WuNL/lab_workspace
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(),
            p*vector1[2].eigen_vector(2).real();

        //cout << "9D向量="<<iter->second.vector_9D<<endl;
        //ArrayXd ad = iter->second.vector_9D;
        //cout <<"ad = "<<ad<<endl;
        //cout <<"ad square="<<ad.square()<<endl;
        tempmat.setZero();

        iter++;

    }

    double tn = ros::Time::now().toSec();
    //cout << "对栅格计算处理的时间"<<(tn - t2)<<endl;
    //cout <<"栅格数量为" <<m.size()<<endl;

}
コード例 #12
0
ファイル: xmlio.cpp プロジェクト: glormph/pout2mzid
//------------------------------------------------------------------------------
bool MzIDIO::insertMZIDValues(boost::unordered_map<PercolatorOutFeatures, string, PercolatorOutFeatures> &pout_values,
                              vector <string> &filenames, bool multiplemzidfiles) {
  ifstream fpr;
  ofstream fpw;
  ostream *wout;
  string mzidname,s1,psmid;
  int i1,vi1,n,xmlindent;

  n=0;
  psmid="";
  try {
    for (vi1=0; vi1<filenames.size(); vi1++) {
      mzidname=boost::lexical_cast<boost::filesystem::path>(filenames[vi1]).stem().string();
      if (!multiplemzidfiles)
        mzidname="";
      fpr.open(filenames[vi1].c_str());
      if (outputfileending.length()>0) {
        fpw.open(setOutputFileName(filenames[vi1]).c_str());
        wout=&fpw;
        }
      else
        wout=&cout;
      while (getline(fpr,s1)) {
        if (s1.find(MZID_PARAM::END_INSERT_TAG)!=string::npos) {
          if (psmid.length()==0)
            THROW_ERROR_VALUE(PRINT_TEXT::BAD_XML,filenames[vi1]);
          for (i1=0; i1<ARRAYSIZE(MZID_PARAM::ELEMENT_DATA::ELEMENTS); i1++) {
            if (pout_values.find(PercolatorOutFeatures(mzidname,psmid,i1))==pout_values.end())
              continue;
            n++;
            switch (MZID_PARAM::ELEMENT_DATA::ELEMENTS[i1]) {
              case MZID_PARAM::CVPARAM: {
                *wout << boost::format(MZID_PARAM::CVPARAM_TAG) % string(xmlindent,' ')
                        % MZID_PARAM::ELEMENT_DATA::ACCESSIONS[i1]
                        % MZID_PARAM::ELEMENT_DATA::CVREFS[i1]
                        % MZID_PARAM::ELEMENT_DATA::NAMES[i1]
                        % pout_values[PercolatorOutFeatures(mzidname,psmid,i1)];
                break;
                }
              case MZID_PARAM::USERPARAM: {
                *wout << boost::format(MZID_PARAM::USERPARAM_TAG) % string(xmlindent,' ')
                        % MZID_PARAM::ELEMENT_DATA::NAMES[i1]
                        % pout_values[PercolatorOutFeatures(mzidname,psmid,i1)];
                break;
                }
              }
            pout_values.erase(PercolatorOutFeatures(mzidname,psmid,i1));
            }
          psmid="";
          }
        xmlindent=s1.find_first_not_of(" ");
        *wout << s1 << endl;
        if (s1.find(MZID_PARAM::PSMID_TAG)!=string::npos && s1.find(MZID_PARAM::START_INSERT_TAG)!=string::npos) {
          i1=s1.find(MZID_PARAM::PSMID_TAG)+strlen(MZID_PARAM::PSMID_TAG);
          psmid=s1.substr(i1,s1.find("\"",i1)-i1);
          }
        }
      fpr.close();
      fpw.close();
      }
    clog << boost::format(PRINT_TEXT::INSERTED) % n << endl;
    for (boost::unordered_map<PercolatorOutFeatures, string, PercolatorOutFeatures>::iterator
        it=pout_values.begin(); it!=pout_values.end(); it++)
      cerr << boost::format(PRINT_TEXT::PSM_NOT_ENTERED) % it->first.filename % it->first.psmid << endl;
    return true;
    }
  catch (exception &e) {
    cerr << e.what() << endl;
    fpr.close();
    fpw.close();
    return false;
    }
  }