- 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
2.1 KiB
2.1 KiB
HashMap
命名空间: XCEngine::Containers
类型: class (template)
描述: 模板哈希表容器,提供键值对存储和快速查找。
概述
HashMap<Key, Value> 是一个模板哈希表容器,使用动态数组作为桶来解决哈希冲突,支持键值对的插入、查找和删除操作。
公共类型
Pair
| 成员 | 类型 | 描述 |
|---|---|---|
first |
Key |
键 |
second |
Value |
值 |
迭代器
| 别名 | 类型 | 描述 |
|---|---|---|
Iterator |
typename Array<Pair>::Iterator |
迭代器类型 |
ConstIterator |
typename Array<Pair>::ConstIterator |
常量迭代器类型 |
公共方法
| 方法 | 描述 |
|---|---|
| Constructor | 构造哈希表实例 |
| Destructor | 析构函数 |
| operator= | 赋值运算符 |
| Copy/Move | 拷贝/移动构造 |
| operator[] | 下标访问(不存在时插入) |
| Find | 查找键对应的值指针 |
| Contains | 检查是否包含键 |
| Insert | 插入键值对 |
| Erase | 删除键对应的元素 |
| Clear | 清空所有元素 |
| Size/Empty | 获取元素数量 |
| begin/end | 获取迭代器 |
| SetAllocator | 设置内存分配器 |
使用示例
#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;
}