[英]How do I efficiently copy unique objects from one vector to another (which is made up of a subset of identical objects)?
[英]How do I check if one vector is a subset of another?
目前,我認為我最好的選擇是使用std :: set_intersection,然后檢查較小輸入的大小是否與set_intersection填充的元素數相同。
有更好的解決方案嗎?
嘗試這個:
if (std::includes(set_one.begin(), set_one.end(),
set_two.begin(), set_two.end()))
{
// ...
}
關於includes() 。
includes()算法比較兩個排序的序列,如果范圍[start2,finish2]中的每個元素都包含在[start1,finish1]范圍內,則返回true。 否則返回false。 includes()假定使用operator <()或使用謂詞comp對序列進行排序。
跑進來
最多((finish1 - start1)+(finish2 - start2))* 2 - 1執行比較。
加O(nlog(n))用於排序向量。 你不會比這更快。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.