C++ STL multimapでの検索法
STL multimupにて検索する際下記1.2で速度の違いはありますでしょうか。
- findとupper_boundを利用して該当データを全て調べる方法
- equal_rangeで該当データを全て調べる方法
c++
1multimap<string, string> test; 2string n = "b"; 3 4test.insert(pair<string, string>("a", "a")); 5test.insert(pair<string, string>("a", "b")); 6test.insert(pair<string, string>("b", "a")); 7test.insert(pair<string, string>("b", "b")); 8test.insert(pair<string, string>("c", "a")); 9test.insert(pair<string, string>("c", "b")); 10 11//find + upper_bound ver 12auto p = test.find(n); 13do{ 14 cout <<p->first << " " << p->second << endl; 15 p++; 16}while(p != test.upper_bound(n)); 17 18// equal_range ver 19auto p2 = test.equal_range(n); 20auto pb = p2.first; 21auto pe = p2.second; 22do{ 23 cout << pb->first << " " << pb->second << endl; 24 pb++; 25}while(pb != pe);

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/28 12:24 編集