Are std::find and std::map.find both O(logN)?
Are std::find and std::map.find both O(logN)?
std::find
和std::map.find
都是O(logN(吗?如果是,std::find
如何在对数时间内实现对std::map
的搜索?
std::find
的实现是否专门用于std::map
用例?
否,std::find
是O(N(,与容器无关。它不知道"容器",std::map
没有专门化。std::find
只使用迭代器,迭代器没有关于底层容器的信息。根据cppreference.com,该实现等效于:
template<class InputIt, class T>
InputIt find(InputIt first, InputIt last, const T& value)
{
for (; first != last; ++first) {
if (*first == value) {
return first;
}
}
return last;
}
根据C++标准(强调矿(:
25.2.5查找[alg.Find]
template<class InputIterator, class T>
InputIterator find(InputIterator first, InputIterator last,
const T& value);
...
返回:范围
[first,last)
中的第一个迭代器i
,它符合以下相应条件:*i == value
。如果未找到此类迭代器,则返回last
。复杂性:最多对应谓词的倒数第一个应用程序
相关文章:
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 在 QVector<std::unique_ptr 上使用 std::find<Type>>
- std::find,返回所有找到的值的替代方法,而不仅仅是存在重复的向量的第一个值
- 为什么在向量上使用 std::find() 时会出现错误?
- 使用 std::find 时没有匹配的函数调用错误
- std::set<Key,Compare,Allocator>::find() 函数使用"<"运算符而不是"=="运算符背后的直觉是什么?
- STL std::find() C++
- 如何将 std::find() 与 2d std: 数组一起使用?
- 为什么 std::find( s.begin(), s.end(), val ) 比集合 s 的 s.find(val) 慢 1000 倍<int>?
- 如果迭代器没有因插入而无效,则使用std::find和C::insert()是线程安全的
- 未按值排序的std::find和std::any_of
- 为什么std::map有find成员函数
- 在libc++和libstdc++之间的std::map上使用std::find时的实现差异
- 有没有办法在Cython中导入std::find find_if等?
- std::map::find 的效率是否与值的数据大小有关?
- std::string::find 为取消引用的迭代器和等效字符串文本返回不同的值
- 使用 find() 通过 std::set 的迭代器将不起作用。出了什么问题?
- Android-NDK 的 GGC/C++ 对于 std::string::find/std::getline(...) 来说似乎不稳定
- MinGW g++ cannot find std::stof
- 如何将std::find/std::find_if用于自定义类对象的向量