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

35 lines
759 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# HashMap::HashMap
```cpp
HashMap();
explicit HashMap(size_t bucketCount, Memory::IAllocator* allocator = nullptr);
```
构造哈希表实例。
**参数:**
- `bucketCount` - 初始桶的数量,默认为 16。若传入 0则自动调整为 16。
- `allocator` - 内存分配器指针,默认为 `nullptr`(使用默认分配器)。
**返回:**
**复杂度:** O(bucketCount),需要初始化所有桶
**线程安全:** ❌ 非线程安全
**异常:**
**示例:**
```cpp
XCEngine::Containers::HashMap<int, const char*> map1;
XCEngine::Containers::HashMap<int, const char*> map2(32);
XCEngine::Containers::HashMap<int, const char*> map3(64, nullptr);
```
## 相关文档
- [HashMap 总览](hashmap.md) - 返回类总览