Ejemplo n.º 1
0
	void get_top(size_t k, time_t time, ResultContainer &top_size)
	{
		std::vector<typename treap_t::p_node_type> top_nodes;

		{
			std::unique_lock<std::mutex> locker(m_lock);
			treap_to_container(m_treap.top(), top_nodes);

			for (auto it = top_nodes.begin(); it != top_nodes.end(); ++it) {
				auto n = *it;
				if (check_expiration(n, time, m_period)) {
					m_treap.erase(n);
					delete n;
					--m_num_events;
				} else {
					top_size.push_back(*n);
				}
			}
		}

		k = std::min(top_size.size(), k);
		std::function<decltype(weight_compare)> comparator_weight(weight_compare);
		std::partial_sort(top_size.begin(), top_size.begin() + k, top_size.end(), std::not2(comparator_weight));
		top_size.resize(k);
	}