# CLinkedMap **Repository Path**: chacebai/CLinkedMap ## Basic Information - **Project Name**: CLinkedMap - **Description**: A C++ header-only LinkedMap is a map that maintains insertion order, designed based on Java LinkedHashMap. Keywords: linkmap linkhashmap linkedmap linkedhashmap. - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-09-23 - **Last Updated**: 2023-09-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Introduction A C++ header-only LinkedMap is a map that maintains insertion order, designed based on Java LinkedHashMap. Keywords: linkmap linkhashmap linkedmap linkedhashmap clinkmap clinkhashmap clinkedmap clinkedhashmap. ## How to use Just include the header file in your project ## For example: `helloworld.cpp` ``` #include #include #include #include #include #include #include #include #include "CLinkedMap.hpp" class Base { public: int age; std::string name; }; int main() { std::cout << "original order: 2 1 4 5 3" << std::endl; std::chrono::time_point start = std::chrono::steady_clock::now(); CLinkedMap linkedHashMap; for (int i = 0; i < 100 * 10000; i++) { linkedHashMap["2"].age = 2; linkedHashMap["2"].name = "a2"; linkedHashMap["1"].age = 1; linkedHashMap["1"].name = "a1"; linkedHashMap["4"].age = 4; linkedHashMap["4"].name = "a4"; linkedHashMap["5"].age = 5; linkedHashMap["5"].name = "a5"; linkedHashMap["3"].age = 3; linkedHashMap["3"].name = "a3"; } std::chrono::time_point end = std::chrono::steady_clock::now(); std::chrono::duration elapsed = end - start; std::cout << "CLinkedMap Elapsed time: " << elapsed.count() << "s" << std::endl; for (auto it = linkedHashMap.begin(); it != linkedHashMap.end(); ++it) { std::cout << it->first << ":" << it->second.name << " " << it->second.age << std::endl; } return 0; } ``` ## Compile `g++ helloworld.cpp -o helloworld -g -static -Wall -std=c++11` ## Run `./helloworld` ``` original order: 2 1 4 5 3 CLinkedMap Elapsed time: 0.810576s 2:a2 2 1:a1 1 4:a4 4 5:a5 5 3:a3 3 ``` ## 介绍 只需包含头文件的LinkedMap.hpp是一个可以保持插入顺序的map,它是基于Java LinkedHashMap设计的 ## 如何使用 只需在项目中包含头文件 ## 案例 `helloworld.cpp` ``` #include #include #include #include #include #include #include #include #include "CLinkedMap.hpp" class Base { public: int age; std::string name; }; int main() { std::cout << "original order: 2 1 4 5 3" << std::endl; std::chrono::time_point start = std::chrono::steady_clock::now(); CLinkedMap linkedHashMap; for (int i = 0; i < 100 * 10000; i++) { linkedHashMap["2"].age = 2; linkedHashMap["2"].name = "a2"; linkedHashMap["1"].age = 1; linkedHashMap["1"].name = "a1"; linkedHashMap["4"].age = 4; linkedHashMap["4"].name = "a4"; linkedHashMap["5"].age = 5; linkedHashMap["5"].name = "a5"; linkedHashMap["3"].age = 3; linkedHashMap["3"].name = "a3"; } std::chrono::time_point end = std::chrono::steady_clock::now(); std::chrono::duration elapsed = end - start; std::cout << "CLinkedMap Elapsed time: " << elapsed.count() << "s" << std::endl; for (auto it = linkedHashMap.begin(); it != linkedHashMap.end(); ++it) { std::cout << it->first << ":" << it->second.name << " " << it->second.age << std::endl; } return 0; } ``` ## 编译 `g++ helloworld.cpp -o helloworld -g -static -Wall -std=c++11` ## 运行 `./helloworld` ``` original order: 2 1 4 5 3 CLinkedMap Elapsed time: 0.810576s 2:a2 2 1:a1 1 4:a4 4 5:a5 5 3:a3 3 ```