832 B
832 B
HashMap::Size / Empty
size_t Size() const;
bool Empty() const;
获取哈希表的元素数量或判断是否为空。
参数: 无
返回:
Size()- 返回元素数量Empty()- 容器为空返回true,否则返回false
复杂度: O(1)
线程安全: ❌ 非线程安全
异常: 无
示例:
XCEngine::Containers::HashMap<int, const char*> map;
std::cout << "Empty: " << (map.Empty() ? "yes" : "no") << std::endl; // 输出 "yes"
std::cout << "Size: " << map.Size() << std::endl; // 输出 0
map.Insert(1, "one");
map.Insert(2, "two");
std::cout << "Empty: " << (map.Empty() ? "yes" : "no") << std::endl; // 输出 "no"
std::cout << "Size: " << map.Size() << std::endl; // 输出 2
相关文档
- HashMap 总览 - 返回类总览