- Fix link resolution with proper relative/absolute path handling - Improve link styling with underline decoration - Hide leaf nodes from tree, only show directories - Fix log file path for packaged app
81 lines
2.1 KiB
Markdown
81 lines
2.1 KiB
Markdown
# HashMap
|
|
|
|
**命名空间**: `XCEngine::Containers`
|
|
|
|
**类型**: `class` (template)
|
|
|
|
**描述**: 模板哈希表容器,提供键值对存储和快速查找。
|
|
|
|
## 概述
|
|
|
|
`HashMap<Key, Value>` 是一个模板哈希表容器,使用动态数组作为桶来解决哈希冲突,支持键值对的插入、查找和删除操作。
|
|
|
|
## 公共类型
|
|
|
|
### Pair
|
|
|
|
| 成员 | 类型 | 描述 |
|
|
|------|------|------|
|
|
| `first` | `Key` | 键 |
|
|
| `second` | `Value` | 值 |
|
|
|
|
### 迭代器
|
|
|
|
| 别名 | 类型 | 描述 |
|
|
|------|------|------|
|
|
| `Iterator` | `typename Array<Pair>::Iterator` | 迭代器类型 |
|
|
| `ConstIterator` | `typename Array<Pair>::ConstIterator` | 常量迭代器类型 |
|
|
|
|
## 公共方法
|
|
|
|
| 方法 | 描述 |
|
|
|------|------|
|
|
| [Constructor](constructor.md) | 构造哈希表实例 |
|
|
| [Destructor](destructor.md) | 析构函数 |
|
|
| [operator=](operator-assign.md) | 赋值运算符 |
|
|
| [Copy/Move](copy-move.md) | 拷贝/移动构造 |
|
|
| [operator[]](operator-subscript.md) | 下标访问(不存在时插入) |
|
|
| [Find](find.md) | 查找键对应的值指针 |
|
|
| [Contains](contains.md) | 检查是否包含键 |
|
|
| [Insert](insert.md) | 插入键值对 |
|
|
| [Erase](erase.md) | 删除键对应的元素 |
|
|
| [Clear](clear.md) | 清空所有元素 |
|
|
| [Size/Empty](size.md) | 获取元素数量 |
|
|
| [begin/end](iterator.md) | 获取迭代器 |
|
|
| [SetAllocator](setallocator.md) | 设置内存分配器 |
|
|
|
|
## 使用示例
|
|
|
|
```cpp
|
|
#include <XCEngine/Containers/HashMap.h>
|
|
#include <iostream>
|
|
|
|
int main() {
|
|
XCEngine::Containers::HashMap<int, const char*> map;
|
|
|
|
map.Insert(1, "one");
|
|
map.Insert(2, "two");
|
|
map.Insert(3, "three");
|
|
|
|
if (const char* value = map.Find(1)) {
|
|
std::cout << "Key 1: " << value << std::endl;
|
|
}
|
|
|
|
std::cout << "Size: " << map.Size() << std::endl;
|
|
|
|
for (auto it = map.begin(); it != map.end(); ++it) {
|
|
std::cout << it->first << " -> " << it->second << std::endl;
|
|
}
|
|
|
|
map.Erase(2);
|
|
std::cout << "Contains 2: " << (map.Contains(2) ? "yes" : "no") << std::endl;
|
|
|
|
return 0;
|
|
}
|
|
```
|
|
|
|
## 相关文档
|
|
|
|
- [Array](../array/array.md) - 动态数组
|
|
- [Memory 模块](../../memory/memory.md) - 内存分配器
|