Exemplo n.º 1
0
 vector<string> summaryRanges(vector<int>& nums) {
   if (nums.empty()) {
     return {};
   }
   int pre = nums[0];
   int first = pre;
   std::vector<std::string> ans;
   auto add_ans = [this, &ans, &pre, &first]() {
     if (pre == first) {
       ans.push_back(build_vec({pre}));
     } else {
       ans.push_back(build_vec({first, pre}));
     }
   };
   for (size_t i = 1; i < nums.size(); ++i) {
     if (nums[i] == pre + 1) {
       pre = nums[i];
     } else {
       add_ans();
       pre = first = nums[i];
     }
   }
   add_ans();
   return ans;
 }
Exemplo n.º 2
0
	std::vector<boost::asio::const_buffer> const& chained_buffer::build_iovec(int to_send)
	{
		TORRENT_ASSERT(is_single_thread());
		TORRENT_ASSERT(!m_destructed);
		m_tmp_vec.clear();
		build_vec(to_send, m_tmp_vec);
		return m_tmp_vec;
	}
Exemplo n.º 3
0
	void chained_buffer::build_mutable_iovec(int bytes, std::vector<span<char>> &vec)
	{
		TORRENT_ASSERT(!m_destructed);
		build_vec(bytes, vec);
	}