예제 #1
0
void ProcessPit_onepass(Array2D<elev_t> &dem, Array2D<label_t> &labels, std::queue<GridCellZ<elev_t> > &depressionQue, std::queue<GridCellZ<elev_t> > &traceQueue, GridCellZ_pq<elev_t> &priorityQueue, std::vector<std::map<label_t, elev_t> > &my_graph){
  while (!depressionQue.empty()){
    GridCellZ<elev_t> c = depressionQue.front();
    depressionQue.pop();

    for(int n=1;n<=8;n++){
      int nx = c.x+dx[n];
      int ny = c.y+dy[n];

      if(!dem.inGrid(nx,ny))
        continue;

      WatershedsMeet(labels(c.x,c.y),labels(nx,ny),dem(c.x,c.y),dem(nx,ny),my_graph);

      if(labels(nx,ny)!=0)
        continue;    

      labels(nx,ny) = labels(c.x,c.y);

      if (dem(nx,ny) > c.z) { //Slope cell
        traceQueue.emplace(nx,ny,dem(nx,ny));
      } else {                //Depression cell
        dem(nx,ny) = c.z;
        depressionQue.emplace(nx,ny,c.z);
      }
    }
  }
}
예제 #2
0
static void try_queue_killstreak() {
    int minstreak = prec_min_streak.GetInt();
    if (ks_killCount >= minstreak) {
        g_ksQueue.emplace(ks_startTick, ks_killCount);
    }
    reset_killstreak_counter();
}
예제 #3
0
    /// Attempt to parse all JSON-encoded messages from the buffer
    ///
    /// This parses all whitespace-delimited JSON objects from the buffer and
    /// and adds them to the m_ingress message queue to be dispatched
    /// later.
    ///
    /// Each JSON message should be an object at the top level with a string
    /// `type` field. There should also be a `entity` field which can be of any
    /// type. It is this entity field object that's passed to the message
    /// handler so it's up to the handler to determine validity.
    ///
    /// If a JSON message is not an object, missing the 'type' field or the
    /// type field is the wrong type then the message is ignored. The buffer
    /// will still be consumed as if it were a valid message.
    ///
    /// If the buffer contains incomplete or malformed JSON then no messages
    /// are processed. No messages are added to `m_ingress`. The buffer is not
    /// consumed.
    void parseBuffer() {
        if (m_buffer.empty()) {
            return;
        }
        std::string json_error;

        std::vector<json11::Json> messages =
            json11::Json::parse_multi(m_buffer.c_str(), json_error);
        // Parsing will fail if the buffer contains a partial message, so the
        // JSON may be well formed but incomplete. This is not ideal. Ideally
        // we should be able to read all the complete messages and only leave
        // the incomplete one in the buffer. This may be an argument in favour
        // of not using `parse_multi`.
        if (json_error.size()) {
            printf("(MessageProcessor) JSON decode error: %s\n",
                   json_error.c_str());
        } else {
            m_buffer.clear();
            for (json11::Json message : messages) {
                json11::Json type = message["type"];
                // If the 'type' field doesn't exist then is_string()
                // is falsey
                if (type.is_string()) {
                    m_ingress.emplace(type.string_value(), message["entity"]);
                }
            }
        }
    }
예제 #4
0
	void Save(Data &&data)
	{
		std::unique_lock<std::mutex> lock(m_queueGuard);
		m_queue.emplace();
		m_queue.back().swap(data);
		m_condition.notify_all();
	}
예제 #5
0
	    void submit(Function&& f)
	    {
		{ // acquire lock
		    std::lock_guard<std::mutex> lg(_cond_mutex);
		    _tasks.emplace(f);
		}
		_cond_var.notify_all();
	    }
예제 #6
0
  std::future<uintptr_t> run(FuncTy Func, ReturnStmtSyntax Return) {
    auto Task = std::make_shared<std::packaged_task<uintptr_t()>>(
      std::bind(Func, Return));

    auto Future = Task->get_future();
    {
      std::unique_lock<std::mutex> L(QueueLock);
      Tasks.emplace([Task](){ (*Task)(); });
    }
    Condition.notify_one();
    return Future;
  }
예제 #7
0
파일: Core.cpp 프로젝트: CarlKenner/dolphin
void QueueHostJob(std::function<void()> job, bool run_during_stop)
{
  if (!job)
    return;

  bool send_message = false;
  {
    std::lock_guard<std::mutex> guard(s_host_jobs_lock);
    send_message = s_host_jobs_queue.empty();
    s_host_jobs_queue.emplace(HostJob{std::move(job), run_during_stop});
  }
  // If the the queue was empty then kick the Host to come and get this job.
  if (send_message)
    Host_Message(WM_USER_JOB_DISPATCH);
}
예제 #8
0
void ProcessTraceQue_onepass(Array2D<elev_t> &dem, Array2D<label_t> &labels, std::queue<GridCellZ<elev_t> > &traceQueue, GridCellZ_pq<elev_t> &priorityQueue, std::vector<std::map<label_t, elev_t> > &my_graph){
  while (!traceQueue.empty()){
    GridCellZ<elev_t> c = traceQueue.front();
    traceQueue.pop();

    bool bInPQ = false;
    for(int n=1;n<=8;n++){
      int nx = c.x+dx[n];
      int ny = c.y+dy[n];

      if(!dem.inGrid(nx,ny))
        continue;

      WatershedsMeet(labels(c.x,c.y),labels(nx,ny),dem(c.x,c.y),dem(nx,ny),my_graph);

      if(labels(nx,ny)!=0)
        continue;    
      
      //The neighbour is unprocessed and higher than the central cell
      if(c.z<dem(nx,ny)){
        traceQueue.emplace(nx,ny,dem(nx,ny));
        labels(nx,ny) = labels(c.x,c.y);
        continue;
      }

      //Decide  whether (nx, ny) is a true border cell
      if (!bInPQ) {
        bool isBoundary = true;
        for(int nn=1;nn<=8;nn++){
          int nnx = nx+dx[n];
          int nny = ny+dy[n];
          if(!dem.inGrid(nnx,nny))
            continue;
          if (labels(nnx,nny)!=0 && dem(nnx,nny)<dem(nx,ny)){
            isBoundary = false;
            break;
          }
        }
        if(isBoundary){
          priorityQueue.push(c);
          bInPQ = true;
        }
      }
    }
  }
}
예제 #9
0
    TaskHandle enqueueTask(const Task::TaskFunction& function, const ProblemSpace& problemSpace) {
        Task task(function, problemSpace);
        std::unique_lock<std::mutex> lock(m_queueMutex);
        m_tasks.emplace(std::move(task));
        TaskHandle handle(m_tasks.back());
        m_queueSemaphore.notify();

        if (!m_running) {
            for (unsigned int i = 0; i < std::thread::hardware_concurrency(); i++) {
                m_threads.emplace_back(std::bind(&ThreadPool::threadFunction, this));
            }

            m_running = true;
        }

        return handle;
    }
예제 #10
0
	std::shared_future<typename std::result_of<Function(Args...)>::type> asyncTask(Function&& f, Args&&... args)
	{
		using taskpkg_t = std::packaged_task<typename std::result_of<Function(Args...)>::type()>;
		auto task = new taskpkg_t(std::bind(std::forward<Function>(f), std::forward<Args>(args)...));
		auto taskFuture = task->get_future().share();

		{
			std::lock_guard<std::mutex> l(mtx);
			taskQueue.emplace([task](){
				(*task)();
				delete task;
			});
		}

		idleWaitCV.notify_one();
		return taskFuture;
	}
예제 #11
0
 void updateFps(unsigned long long& lastId, double& fps, unsigned int& fpsCounter,
                std::queue<std::chrono::high_resolution_clock::time_point>& fpsQueue,
                const unsigned long long id, const int numberGpus)
 {
     try
     {
         // If only 1 GPU -> update fps every frame.
         // If > 1 GPU:
             // We updated fps every (3*numberGpus) frames. This is due to the variability introduced by
             // using > 1 GPU at the same time.
             // However, we update every frame during the first few frames to have an initial estimator.
         // In any of the previous cases, the fps value is estimated during the last several frames.
         // In this way, a sudden fps drop will be quickly visually identified.
         if (lastId != id)
         {
             lastId = id;
             fpsQueue.emplace(std::chrono::high_resolution_clock::now());
             bool updatePrintedFps = true;
             if (fpsQueue.size() > 5)
             {
                 const auto factor = (numberGpus > 1 ? 25u : 15u);
                 updatePrintedFps = (fpsCounter % factor == 0);
                 // updatePrintedFps = (numberGpus == 1 ? true : fpsCounter % (3*numberGpus) == 0);
                 fpsCounter++;
                 if (fpsQueue.size() > factor)
                     fpsQueue.pop();
             }
             if (updatePrintedFps)
             {
                 const auto timeSec = (double)std::chrono::duration_cast<std::chrono::nanoseconds>(
                     fpsQueue.back()-fpsQueue.front()
                 ).count() * 1e-9;
                 fps = (fpsQueue.size()-1) / (timeSec != 0. ? timeSec : 1.);
             }
         }
     }
     catch (const std::exception& e)
     {
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
예제 #12
0
void runOnMainLoop(std::function<void()> _task) {
    std::lock_guard<std::mutex> lock(m_tasksMutex);
    m_tasks.emplace(std::move(_task));

    requestRender();
}
예제 #13
0
 void emplace(Args&&... args) {
   return q.emplace(std::forward<Args>(args)...);
 }
예제 #14
0
 static void key_callback(int key, int state) { input_events.emplace(key, state, qts::controls::KEYBOARD); }
int main()
{
	
	std::ios_base::sync_with_stdio(false);

	int n,m;

	cin >> n;

	visited.assign(n,false);

	string s;

	for(int i = 0; i<n; i++)
	{
		cin >> s;
		table[s] = i;
	}

	cin >> m;

	string ss;
	for(int i = 0; i<m; i++)
	{
		cin >> s;
		cin >> ss;

		adjlist[table[s]].push_back(table[ss]);
		adjlist[table[ss]].push_back(table[s]);
	}



	int connected = 0;
	
	//bfs
	for(int i = 0;i<n;i++)
	{
		if(!visited[i])
		{
			visited[i] = true;

			bfsQ.emplace(i);

			while(!bfsQ.empty())
			{
				int current = bfsQ.front(); //curent vertex
				bfsQ.pop();

				for(auto it = adjlist[current].begin(); it != adjlist[current].end();it++)
				{
					
					if(!visited[*it])
					{
						bfsQ.push(*it);
						visited[*it] = true;
					}
				}			
			}

			connected++;
		}
	}




	cout<<connected;
}
예제 #16
0
 static void mouse_button_callback(int button, int action) { input_events.emplace(button, action, qts::controls::MOUSE_BUTTON); }
예제 #17
0
 static void mouse_wheel_callback(int pos) { mouse_wheel_events.emplace(pos); }
예제 #18
0
 void enqueue(Event* event) {
     event_queue.emplace(event);
     antares_event_translator_cancel(translator.c_obj());
 }
예제 #19
0
    /*!
     * Explores the current component that starts at node using BFS.
     */
    unsigned ExploreComponent(std::queue<std::pair<NodeID, NodeID>> &bfs_queue,
                              NodeID node,
                              unsigned current_component)
    {
        /*
           Graphical representation of variables:

           u           v           w
           *---------->*---------->*
                            e2
        */

        bfs_queue.emplace(node, node);
        // mark node as read
        m_component_index_list[node] = current_component;

        unsigned current_component_size = 1;

        while (!bfs_queue.empty())
        {
            // fetch element from BFS queue
            std::pair<NodeID, NodeID> current_queue_item = bfs_queue.front();
            bfs_queue.pop();

            const NodeID v = current_queue_item.first;  // current node
            const NodeID u = current_queue_item.second; // parent
            // increment size counter of current component
            ++current_component_size;
            if (m_barrier_nodes.find(v) != m_barrier_nodes.end())
            {
                continue;
            }
            const NodeID to_node_of_only_restriction =
                m_restriction_map.CheckForEmanatingIsOnlyTurn(u, v);

            for (auto e2 : m_graph.GetAdjacentEdgeRange(v))
            {
                const NodeID w = m_graph.GetTarget(e2);

                if (to_node_of_only_restriction != std::numeric_limits<unsigned>::max() &&
                    w != to_node_of_only_restriction)
                {
                    // At an only_-restriction but not at the right turn
                    continue;
                }

                if (u != w)
                {
                    // only add an edge if turn is not a U-turn except
                    // when it is at the end of a dead-end street.
                    if (!m_restriction_map.CheckIfTurnIsRestricted(u, v, w))
                    {
                        // only add an edge if turn is not prohibited
                        if (std::numeric_limits<unsigned>::max() == m_component_index_list[w])
                        {
                            // insert next (node, parent) only if w has
                            // not yet been explored
                            // mark node as read
                            m_component_index_list[w] = current_component;
                            bfs_queue.emplace(w, v);
                        }
                    }
                }
            }
        }

        return current_component_size;
    }
예제 #20
0
파일: main.cpp 프로젝트: CCJY/coliru
 void sendMessageC(Args... args)
 {
     messages.emplace(new T(args...));
 }