Files
XCEngine/docs/api/containers/hashmap/contains.md

778 B

HashMap::Contains

bool Contains(const Key& key) const;

检查哈希表中是否包含指定的键。

参数:

  • key - 要检查的键

返回: 如果键存在返回 true,否则返回 false

复杂度: O(1) 平均,最坏 O(n)

线程安全: 非线程安全

异常:

示例:

XCEngine::Containers::HashMap<int, const char*> map;
map.Insert(1, "one");
map.Insert(2, "two");

if (map.Contains(1)) {
    std::cout << "Key 1 exists" << std::endl; // 输出 "Key 1 exists"
}

if (!map.Contains(99)) {
    std::cout << "Key 99 does not exist" << std::endl; // 输出 "Key 99 does not exist"
}

相关文档