Example #1
0
	void next(std::deque<std::deque<match_t *> > *last_round, std::deque<player_t *> &tournament_players) {
		int half = tournament_players.size()/2;

		/** "Rotates clockwise" */
		tournament_players.insert(tournament_players.begin() + 1, tournament_players[half]);
		tournament_players.erase(tournament_players.begin() + half + 1);
		tournament_players.insert(tournament_players.end(), tournament_players[half]);
		tournament_players.erase(tournament_players.begin() + half);
	}
Example #2
0
BOOL CWizKMDatabaseServer::document_downloadFullListEx(const CWizStdStringArray& arrayDocumentGUID, std::deque<WIZDOCUMENTDATAEX>& arrayRet)
{
    int nCountPerPage = 30;
    //
    CWizStdStringArray::const_iterator it = arrayDocumentGUID.begin();
    //
    while (1)
    {
        //
        CWizStdStringArray subArray;
        //
        for (;
            it != arrayDocumentGUID.end(); )
        {
            subArray.push_back(*it);
            it++;
            //
            if (subArray.size() == nCountPerPage)
                break;
        }
        //
        std::deque<WIZDOCUMENTDATAEX> subRet;
        if (!document_downloadFullList(subArray, subRet))
            return FALSE;
        //
        arrayRet.insert(arrayRet.end(), subRet.begin(), subRet.end());
        //
        if (it == arrayDocumentGUID.end())
            break;
    }
    //
    return TRUE;
}
Example #3
0
bool CWizDatabase::GetAllObjectsNeedToBeDownloaded(std::deque<WIZOBJECTDATA>& arrayData)
{
    CWizDocumentDataArray arrayDocument;
    CWizDocumentAttachmentDataArray arrayAttachment;
    GetNeedToBeDownloadedDocuments(arrayDocument);
    GetNeedToBeDownloadedAttachments(arrayAttachment);

    arrayData.assign(arrayAttachment.begin(), arrayAttachment.end());
    arrayData.insert(arrayData.begin(), arrayDocument.begin(), arrayDocument.end());

    return true;
}
void Color3DTree::Node::insertSorted(std::deque<Neighbour>& nearestNeighbours, const Neighbour& neighbour, unsigned int maxneighbours) const
{
  std::deque<Neighbour>::iterator it = nearestNeighbours.begin();
  const std::deque<Neighbour>::iterator end = it + maxneighbours;
  ASSERT(end == nearestNeighbours.end());
  int distance = neighbour.getDistance();
  for(; it < end; it++)
    if(it->getDistance() > distance)
    {
      nearestNeighbours.insert(it, neighbour);
      nearestNeighbours.pop_back();
      break;
    }
}
    std::vector<T> filter(const std::vector<T> & in)
    {
        assert(in.size() > 0);

        //---------------------------------------------------------------------
        // init state

        unsigned hist_ptr = 0;

        std::fill(_history.begin(), _history.end(), in[0]);
        std::fill(_pool.begin(), _pool.end(), in[0]);

        // pool is keep sorted

        //---------------------------------------------------------------------
        // filter input

        std::vector<T> out;
        out.reserve(in.size());

        for(auto x : in)
        {
            // step 1, remove oldest value from the pool.

            auto last = _history[hist_ptr];

            auto last_pos = std::lower_bound(_pool.begin(), _pool.end(), last);

            _pool.erase(last_pos);

            // step 2, insert new value into pool

            auto insert_pos = std::lower_bound(_pool.begin(), _pool.end(), x);

            _pool.insert(insert_pos, x);

            // step 3, write input value into history.

            _history[hist_ptr] = x;

            hist_ptr = (hist_ptr + 1) % _history.size();

            // median is always the middle of the pool

            out.push_back(*(_pool.begin() +_median));
        }

        return out;
    }
void densifyWaypoints(){
	if(waypointMaxDistance>0){
		std::cout << "densifying waypoints" << std::endl;
		int count=0;
		current_path.push_front(startState);
		for(int i=0;i<current_path.size()-1;++i){
			if((current_path[i]-current_path[i+1]).norm()>waypointMaxDistance){
				count++;
				current_path.insert(current_path.begin()+i+1,current_path[i]+(current_path[i+1]-current_path[i])*(waypointMaxDistance/((current_path[i+1]-current_path[i]).norm())));
			}
		}
		current_path.pop_front();
		std::cout << count << " points added" << std::endl;
	}
}
Example #7
0
void
test(int P, std::deque<int>& c1, int x)
{
    typedef std::deque<int> C;
    typedef C::iterator I;
    typedef C::const_iterator CI;
    std::size_t c1_osize = c1.size();
    CI i = c1.insert(c1.begin() + P, x);
    assert(i == c1.begin() + P);
    assert(c1.size() == c1_osize + 1);
    assert(distance(c1.begin(), c1.end()) == c1.size());
    i = c1.begin();
    for (int j = 0; j < P; ++j, ++i)
        assert(*i == j);
    assert(*i == x);
    ++i;
    for (int j = P; j < c1_osize; ++j, ++i)
        assert(*i == j);
}
void
test(int P, std::deque<int>& c1, const std::deque<int>& c2)
{
    typedef std::deque<int> C;
    typedef C::iterator I;
    typedef C::const_iterator CI;
    typedef bidirectional_iterator<CI> BCI;
    std::size_t c1_osize = c1.size();
    CI i = c1.insert(c1.begin() + P, BCI(c2.begin()), BCI(c2.end()));
    assert(i == c1.begin() + P);
    assert(c1.size() == c1_osize + c2.size());
    assert(distance(c1.begin(), c1.end()) == c1.size());
    i = c1.begin();
    for (int j = 0; j < P; ++j, ++i)
        assert(*i == j);
    for (int j = 0; j < c2.size(); ++j, ++i)
        assert(*i == j);
    for (int j = P; j < c1_osize; ++j, ++i)
        assert(*i == j);
}
	bool sortMembers(const DependencyIdMap& depMap, std::deque<DependencyId>& members) {
		//organize members dependencies
		const std::size_t membersSize = members.size();
		if (membersSize>1) {
			//bool sorting = true;
			std::size_t index = 0;
			std::size_t moveCounter = 0;
			while(index < membersSize) {
				bool moved = false;
				DependencyId currId = members[index];
				if (depMap.count(currId)>0) {
					//have dependencies
					const DependencyIdSet& deps = depMap.at(currId);
					int lastDep = getIndexOfLastDependency(members, deps);
					if (lastDep > index) {
						//move
						std::deque<DependencyId>::iterator indexIter = members.begin() + index;
						members.erase(indexIter);
						std::deque<DependencyId>::iterator lastDepIter = members.begin() + lastDep;
						members.insert(lastDepIter, currId);
						moved = true;
						moveCounter++;
					}
				}
				if (moved==false) {
					index++;
					moveCounter = 0;
				} else {
					std::size_t rest = membersSize - index;
					if (moveCounter>=rest) {
						//cycle detected - break
						return false;
					}
				}
			}
		}
		return true;
	}
Example #10
0
void
    test_insert_range(
        std::deque<int> &std_deque
      , SeqContainer &seq_container
      , std::deque<int> const& input_deque
      , std::size_t index
    )
{
    BOOST_TEST(CheckEqualContainers(&std_deque, &seq_container));

    std_deque.insert(
        std_deque.begin() + index
      , input_deque.begin()
      , input_deque.end()
    );

    seq_container.insert(
        seq_container.begin() + index
      , input_deque.begin()
      , input_deque.end()
    );
    BOOST_TEST(CheckEqualContainers(&std_deque, &seq_container));
}
void calculate() {
	size_t min = SIZE_MAX;
	size_t cnt = 0;

	g_list.clear();

	std::vector<size_t> mullist;

	for(i = 0; i < g_num + 1; ++i) {
		g_list.push_back(g_num_arr[i]);
	}//for

	function<void(size_t, size_t &)> cal = [&](size_t id, size_t & min) {
		showdbg("id: %lu listsz: %lu\n", id, g_list.size());
		showdbg("list: ");
		for(auto ii : g_list)
			showdbg("%lu ", ii);
		showdbg("\n");


		if(g_list.size() == 2) {
			showdbg("fin: cnt=%lu\n", cnt);
			if(min > cnt) {
				min = cnt;
				showdbg("update min!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");

				showdbg("mullist: ");
				for(auto ii : mullist)
					showdbg("%lu ", ii);
				showdbg("\n");
			}//if
			showdbg("\n");

			return;
		}//if
		
		if(id + 2 == g_list.size())
			return;

		auto erased = g_list[id + 1];
		auto cnt_resv = cnt;

		mullist.push_back(g_list[id + 1]);
		cnt += g_list[id] * g_list[id + 1] * g_list[id + 2];
		showdbg("cnt += %lu*%lu*%lu = %lu\n", g_list[id], g_list[id+1], g_list[id+2], cnt);

		g_list.erase(g_list.begin() + id + 1);

		for(auto newid = 0; (newid + 2) <= g_list.size(); ++newid) {
			cal(newid, min);
		}//for
		mullist.pop_back();
		g_list.insert(g_list.begin() + id + 1, erased);
		cnt = cnt_resv;
	};

	for(auto newid = 0; newid < g_list.size() - 1; ++newid) {
		cal(newid, min);
	}//for

	g_result = min;
}//calculate()
void bad_insert_deque1(std::deque<int> &D, int n) {
  auto i1 = D.cbegin(), i0 = i1++;
  D.insert(i1, n);
  *i0; // expected-warning{{Invalidated iterator accessed}}
  *i1; // expected-warning{{Invalidated iterator accessed}}
}
 //vector<int> d_;
 // Adds a number into the data structure.
 void addNum(int num)
 {
     auto it = lower_bound(d_.begin(), d_.end(), num);
     d_.insert(it, num);
 }