This commit is contained in:
Lenyiin 2024-09-24 04:43:00 +08:00
parent 7abc18bfce
commit 73408f4b11
27 changed files with 92 additions and 37 deletions

View File

@ -3,20 +3,20 @@
"WorkspaceRootPath": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\", "WorkspaceRootPath": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\",
"Documents": [ "Documents": [
{ {
"AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}", "AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" "RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Map.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
},
{
"AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\RBTree.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:RBTree.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
}, },
{ {
"AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}", "AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Set.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" "RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Set.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
}, },
{ {
"AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}", "AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\RBTree.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Map.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" "RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:RBTree.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
},
{
"AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
} }
], ],
"DocumentGroupContainers": [ "DocumentGroupContainers": [
@ -26,7 +26,7 @@
"DocumentGroups": [ "DocumentGroups": [
{ {
"DockedWidth": 267, "DockedWidth": 267,
"SelectedChildIndex": 3, "SelectedChildIndex": 6,
"Children": [ "Children": [
{ {
"$type": "Bookmark", "$type": "Bookmark",
@ -42,20 +42,20 @@
}, },
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 0, "DocumentIndex": 3,
"Title": "Main.cpp", "Title": "Main.cpp",
"DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp", "DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp",
"RelativeDocumentMoniker": "Main.cpp", "RelativeDocumentMoniker": "Main.cpp",
"ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp*", "ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp",
"RelativeToolTip": "Main.cpp*", "RelativeToolTip": "Main.cpp",
"ViewState": "AgIAAF4BAAAAAAAAAAAswHEBAAABAAAAAAAAAA==", "ViewState": "AgIAAHoBAAAAAAAAAAAswIUBAAAUAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-09-23T15:54:15.721Z", "WhenOpened": "2024-09-23T15:54:15.721Z",
"EditorCaption": "" "EditorCaption": ""
}, },
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 1, "DocumentIndex": 2,
"Title": "RBTree.hpp", "Title": "RBTree.hpp",
"DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\RBTree.hpp", "DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\RBTree.hpp",
"RelativeDocumentMoniker": "RBTree.hpp", "RelativeDocumentMoniker": "RBTree.hpp",
@ -68,26 +68,26 @@
}, },
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 2, "DocumentIndex": 1,
"Title": "Set.hpp", "Title": "Set.hpp",
"DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp", "DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp",
"RelativeDocumentMoniker": "Set.hpp", "RelativeDocumentMoniker": "Set.hpp",
"ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp", "ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp",
"RelativeToolTip": "Set.hpp", "RelativeToolTip": "Set.hpp",
"ViewState": "AgIAAC4AAAAAAAAAAAAswDYAAAAjAAAAAAAAAA==", "ViewState": "AgIAADkAAAAAAAAAAAAswEQAAAAJAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
"WhenOpened": "2024-09-23T15:53:53.08Z", "WhenOpened": "2024-09-23T15:53:53.08Z",
"EditorCaption": "" "EditorCaption": ""
}, },
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 3, "DocumentIndex": 0,
"Title": "Map.hpp", "Title": "Map.hpp",
"DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp", "DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp",
"RelativeDocumentMoniker": "Map.hpp", "RelativeDocumentMoniker": "Map.hpp",
"ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp", "ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp",
"RelativeToolTip": "Map.hpp", "RelativeToolTip": "Map.hpp",
"ViewState": "AgIAAC4AAAAAAAAAAAAswEEAAAABAAAAAAAAAA==", "ViewState": "AgIAAD4AAAAAAAAAAAAswEgAAAAUAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
"WhenOpened": "2024-09-23T15:53:43.888Z", "WhenOpened": "2024-09-23T15:53:43.888Z",
"EditorCaption": "" "EditorCaption": ""

View File

@ -3,20 +3,20 @@
"WorkspaceRootPath": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\", "WorkspaceRootPath": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\",
"Documents": [ "Documents": [
{ {
"AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}", "AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" "RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Map.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
},
{
"AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\RBTree.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:RBTree.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
}, },
{ {
"AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}", "AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Set.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" "RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Set.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
}, },
{ {
"AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}", "AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\RBTree.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Map.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" "RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:RBTree.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
},
{
"AbsoluteMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{2827E392-69FE-4ABC-84E6-BF5E25017C39}|Windows_Set_Map.vcxproj|solutionrelative:Main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
} }
], ],
"DocumentGroupContainers": [ "DocumentGroupContainers": [
@ -26,7 +26,7 @@
"DocumentGroups": [ "DocumentGroups": [
{ {
"DockedWidth": 267, "DockedWidth": 267,
"SelectedChildIndex": 3, "SelectedChildIndex": 6,
"Children": [ "Children": [
{ {
"$type": "Bookmark", "$type": "Bookmark",
@ -42,20 +42,20 @@
}, },
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 0, "DocumentIndex": 3,
"Title": "Main.cpp", "Title": "Main.cpp",
"DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp", "DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp",
"RelativeDocumentMoniker": "Main.cpp", "RelativeDocumentMoniker": "Main.cpp",
"ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp", "ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Main.cpp",
"RelativeToolTip": "Main.cpp", "RelativeToolTip": "Main.cpp",
"ViewState": "AgIAAF4BAAAAAAAAAAAswGgBAAATAAAAAAAAAA==", "ViewState": "AgIAAHoBAAAAAAAAAAAswIUBAAAUAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-09-23T15:54:15.721Z", "WhenOpened": "2024-09-23T15:54:15.721Z",
"EditorCaption": "" "EditorCaption": ""
}, },
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 1, "DocumentIndex": 2,
"Title": "RBTree.hpp", "Title": "RBTree.hpp",
"DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\RBTree.hpp", "DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\RBTree.hpp",
"RelativeDocumentMoniker": "RBTree.hpp", "RelativeDocumentMoniker": "RBTree.hpp",
@ -68,26 +68,26 @@
}, },
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 2, "DocumentIndex": 1,
"Title": "Set.hpp", "Title": "Set.hpp",
"DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp", "DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp",
"RelativeDocumentMoniker": "Set.hpp", "RelativeDocumentMoniker": "Set.hpp",
"ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp", "ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Set.hpp",
"RelativeToolTip": "Set.hpp", "RelativeToolTip": "Set.hpp",
"ViewState": "AgIAAC4AAAAAAAAAAAAswDYAAAAjAAAAAAAAAA==", "ViewState": "AgIAADkAAAAAAAAAAAAswEQAAAAJAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
"WhenOpened": "2024-09-23T15:53:53.08Z", "WhenOpened": "2024-09-23T15:53:53.08Z",
"EditorCaption": "" "EditorCaption": ""
}, },
{ {
"$type": "Document", "$type": "Document",
"DocumentIndex": 3, "DocumentIndex": 0,
"Title": "Map.hpp", "Title": "Map.hpp",
"DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp", "DocumentMoniker": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp",
"RelativeDocumentMoniker": "Map.hpp", "RelativeDocumentMoniker": "Map.hpp",
"ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp", "ToolTip": "E:\\Git \u4ED3\u5E93\\\u516C\u5F00\u4ED3\u5E93\\9_Set_Map\\Windows_Set_Map\\Map.hpp",
"RelativeToolTip": "Map.hpp", "RelativeToolTip": "Map.hpp",
"ViewState": "AgIAAC4AAAAAAAAAAAAswEEAAAABAAAAAAAAAA==", "ViewState": "AgIAAD4AAAAAAAAAAAAswEYAAAAJAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
"WhenOpened": "2024-09-23T15:53:43.888Z", "WhenOpened": "2024-09-23T15:53:43.888Z",
"EditorCaption": "" "EditorCaption": ""

Binary file not shown.

View File

@ -354,6 +354,33 @@ void test_Map2()
cout << "IsRBTree? " << (countMap.IsRBTree() ? "true" : "false") << endl; cout << "IsRBTree? " << (countMap.IsRBTree() ? "true" : "false") << endl;
} }
void test_Map3()
{
Lenyiin::Map<int, std::string> map;
// 插入键值对
map.Insert(std::make_pair(1, "one"));
map.Insert(std::make_pair(2, "two"));
map.Insert(std::make_pair(3, "three"));
// 通过 operator[] 访问或插入
map[4] = "four";
std::cout << "Key 4: " << map[4] << std::endl;
// 查找元素
auto it = map.Find(2);
if (it != map.end())
{
std::cout << "Found: " << it->first << " -> " << it->second << std::endl;
}
// 删除元素
map.Erase(1);
// 验证红黑树
cout << "IsRBTree? " << (map.IsRBTree() ? "true" : "false") << endl;
}
int main() int main()
{ {
// test_set(); // test_set();
@ -365,6 +392,7 @@ int main()
test_Set(); test_Set();
test_Map1(); test_Map1();
test_Map2(); test_Map2();
test_Map3();
return 0; return 0;
} }

View File

@ -4,31 +4,37 @@
namespace Lenyiin namespace Lenyiin
{ {
// Map 容器的实现,依赖于红黑树
template <class K, class V> template <class K, class V>
class Map class Map
{ {
// 用于从节点中获取键值的仿函数
struct MapKeyOfT struct MapKeyOfT
{ {
const K& operator()(const std::pair<K, V>& kv) const K& operator()(const std::pair<K, V>& kv)
{ {
return kv.first; return kv.first; // 返回键作为红黑树的比较依据
} }
}; };
public: public:
// 定义迭代器类型,支持遍历和访问集合中的元素
typedef typename RBTree<K, std::pair<K, V>, MapKeyOfT>::iterator iterator; typedef typename RBTree<K, std::pair<K, V>, MapKeyOfT>::iterator iterator;
typedef typename RBTree<K, std::pair<K, V>, MapKeyOfT>::const_iterator const_iterator; typedef typename RBTree<K, std::pair<K, V>, MapKeyOfT>::const_iterator const_iterator;
// 返回指向第一个元素的迭代器
iterator begin() iterator begin()
{ {
return _tree.begin(); return _tree.begin();
} }
// 返回指向尾后位置的迭代器
iterator end() iterator end()
{ {
return _tree.end(); return _tree.end();
} }
// const 版本的迭代器
const_iterator begin() const const_iterator begin() const
{ {
return _tree.begin(); return _tree.begin();
@ -39,22 +45,32 @@ namespace Lenyiin
return _tree.end(); return _tree.end();
} }
// 插入元素,返回插入结果
std::pair<iterator, bool> Insert(const std::pair<K, V>& kv) std::pair<iterator, bool> Insert(const std::pair<K, V>& kv)
{ {
return _tree.Insert(kv); return _tree.Insert(kv);
} }
// 删除元素,返回是否删除成功
bool Erase(const K& key) bool Erase(const K& key)
{ {
return _tree.Erase(key); return _tree.Erase(key);
} }
// 查找元素,返回指向该元素的迭代器
iterator Find(const K& key)
{
return _tree.Find(key);
}
// [] 下标运算符
V& operator[](const K& key) V& operator[](const K& key)
{ {
std::pair<iterator, bool> ret = _tree.Insert(std::make_pair(key, V())); std::pair<iterator, bool> ret = _tree.Insert(std::make_pair(key, V()));
return ret.first->second; return ret.first->second;
} }
// 校验红黑树的合法性
bool IsRBTree() bool IsRBTree()
{ {
return _tree.IsRBTree(); return _tree.IsRBTree();

View File

@ -646,7 +646,7 @@ namespace Lenyiin
} }
// 查找节点 // 查找节点
iterator& Find(const K& key) iterator Find(const K& key)
{ {
KOfT koft; KOfT koft;
Node* cur = _root; Node* cur = _root;

View File

@ -4,9 +4,11 @@
namespace Lenyiin namespace Lenyiin
{ {
// Set 容器的实现,依赖于红黑树
template <class K> template <class K>
class Set class Set
{ {
// 用于从节点中获取键值的仿函数
struct SetKeyOfT struct SetKeyOfT
{ {
const K& operator()(const K& k) const K& operator()(const K& k)
@ -16,20 +18,24 @@ namespace Lenyiin
}; };
public: public:
// 定义迭代器类型,支持遍历和访问集合中的元素
// 这里RBTree<K, K, SetKeyOfT>::iterator还没有实例化, 系统找不到, typename告诉编译器现在先不着急找 // 这里RBTree<K, K, SetKeyOfT>::iterator还没有实例化, 系统找不到, typename告诉编译器现在先不着急找
typedef typename RBTree<K, K, SetKeyOfT>::iterator iterator; typedef typename RBTree<K, K, SetKeyOfT>::iterator iterator;
typedef typename RBTree<K, K, SetKeyOfT>::const_iterator const_iterator; typedef typename RBTree<K, K, SetKeyOfT>::const_iterator const_iterator;
// 返回指向第一个元素的迭代器
iterator begin() iterator begin()
{ {
return _tree.begin(); return _tree.begin();
} }
// 返回指向尾后位置的迭代器
iterator end() iterator end()
{ {
return _tree.end(); return _tree.end();
} }
// const 版本的迭代器
const_iterator begin() const const_iterator begin() const
{ {
return _tree.begin(); return _tree.begin();
@ -40,27 +46,32 @@ namespace Lenyiin
return _tree.end(); return _tree.end();
} }
// 插入元素,返回插入结果
std::pair<iterator, bool> Insert(const K& key) std::pair<iterator, bool> Insert(const K& key)
{ {
return _tree.Insert(key); return _tree.Insert(key);
} }
// 删除元素,返回是否删除成功
bool Erase(const K& key) bool Erase(const K& key)
{ {
return _tree.Erase(key); return _tree.Erase(key);
} }
iterator& Find(const K& key) // 查找元素,返回指向该元素的迭代器
iterator Find(const K& key)
{ {
return _tree.Find(key); return _tree.Find(key);
} }
// 校验红黑树的合法性
bool IsRBTree() bool IsRBTree()
{ {
return _tree.IsRBTree(); return _tree.IsRBTree();
} }
private: private:
// 底层红黑树实例
RBTree<K, K, SetKeyOfT> _tree; RBTree<K, K, SetKeyOfT> _tree;
}; };
} }