docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
# HashMap
|
|
|
|
|
|
|
|
|
|
**命名空间**: `XCEngine::Containers`
|
|
|
|
|
|
|
|
|
|
**类型**: `class` (template)
|
|
|
|
|
|
|
|
|
|
**描述**: 模板哈希表容器,提供键值对存储和快速查找。
|
|
|
|
|
|
|
|
|
|
## 概述
|
|
|
|
|
|
2026-03-19 00:43:16 +08:00
|
|
|
`HashMap<Key, Value>` 是一个模板哈希表容器,使用动态数组作为桶来解决哈希冲突,支持键值对的插入、查找和删除操作。
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
|
|
|
|
## 公共类型
|
|
|
|
|
|
|
|
|
|
### 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) | 拷贝/移动构造 |
|
2026-03-19 02:01:18 +08:00
|
|
|
| [operator[]](operator-subscript.md) | 下标访问(不存在时插入) |
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
| [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
|
2026-03-19 00:35:26 +08:00
|
|
|
#include <XCEngine/Containers/HashMap.h>
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
#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) - 内存分配器
|