{"id":13441640,"url":"https://github.com/zouxiaohang/TinySTL","last_synced_at":"2025-03-20T12:32:05.330Z","repository":{"id":20793990,"uuid":"24079195","full_name":"zouxiaohang/TinySTL","owner":"zouxiaohang","description":"TinySTL is a subset of STL(cut some containers and algorithms) and also a superset of STL(add some other containers and algorithms)","archived":false,"fork":false,"pushed_at":"2018-10-27T04:26:50.000Z","size":641,"stargazers_count":2257,"open_issues_count":23,"forks_count":620,"subscribers_count":113,"default_branch":"master","last_synced_at":"2024-08-01T03:35:12.798Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zouxiaohang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-16T00:25:25.000Z","updated_at":"2024-07-31T01:21:23.000Z","dependencies_parsed_at":"2022-07-12T15:17:54.261Z","dependency_job_id":null,"html_url":"https://github.com/zouxiaohang/TinySTL","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouxiaohang%2FTinySTL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouxiaohang%2FTinySTL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouxiaohang%2FTinySTL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouxiaohang%2FTinySTL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zouxiaohang","download_url":"https://codeload.github.com/zouxiaohang/TinySTL/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221760086,"owners_count":16876350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:36.413Z","updated_at":"2025-03-20T12:32:05.325Z","avatar_url":"https://github.com/zouxiaohang.png","language":"C++","funding_links":[],"categories":["HarmonyOS","C++"],"sub_categories":["Windows Manager"],"readme":"TinySTL\n=======\n采用C++11实现一款简易的STL标准库，既是C++STL的一个子集（裁剪了一些容器和算法）又是一个超集（增加了一些容器和算法）\n\n目的：练习数据结构与算法和C++ Template编程\n\n编译环境：VS2013及以上版本\n\n##开发计划：\n  * STL的几大基本组件，如string、vector、list、deque、set、map、unordered_\\*等\n  * STL算法库中的大部分算法\n  * circular buffer\n  * bitmap\n  * skip list\n  * binary search tree\n  * AVL tree\n  * rbtree\n  * segment tree\n  * splay tree\n  * rope\n  * Van Emde Boas tree\n  * treap\n  * B-tree\n  * trie\n  * suffix array/tree\n  * Disjoint-set data structure\n  * k-d tree\n  * R-tree\n  * Matrix\n  * Graph\n  * bloom filter\n\n##完成进度：\n* STL的几大基本组件\n    * type traits：100%  \n    * 空间配置器：100%\n    * iterator traits：100%\n    * reverse_iterator：100%\n    * vector：100%\n    * string：100%\n    * priority_queue：100%\n    * stack：100%\n    * deque：100%\n    * queue：100%\n    * pair：100%\n    * list：100%\n\t* unordered_set：100%\n\t* unique_ptr：100%\n\t* shared_ptr：100%\n\t* cow_ptr：100%\n* STL Algorithms:  \n    * fill：100% \n    * fill_n：100% \n    * find：100%\n    * is_heap：100%\n    * min、max：100%\n    * make_heap：100%\n    * pop_heap：100%\n    * push_heap：100%\n    * sort_heap：100%\n    * swap：100%\n    * all_of：100%\n    * any_of：100%\n    * none_of：100%\n    * find_if：100%\n    * find_if_not：100%\n    * adjacent_find：100%\n    * count：100%\n    * count_if：100%\n    * mismatch：100%\n    * equal：100%\n\t* is_permutation：100%\n\t* search：100%\n\t* advance：100%\n\t* sort：100%\n\t* generate：100%\n\t* generate_n：100%\n\t* distance：100%\n\t* copy：100%\n* 其他组件：\n    * circular_buffer：100%   \n    * bitmap：100%\n    * binary_search_tree：100%\n    * avl_tree：100%\n\t* suffix_array：100%\n\t* directed_graph：100%\n\t* trie tree：100%\n\t* Disjoint-set data structure：100%\n\n##TinySTL单元测试(原单元测试代码逐步)：\n  * pair：100%\n  * algorithm：20%\n  * vector：100%\n  * string：100%\n  * priority_queue：100%\n  * suffix_array：100%\n  * queue：100%\n  * stack：100%\n  * bitmap：100%\n  * circular_buffer：100%\n  * deque：100%\n  * list：100%\n  * binary_search_tree：100%\n  * avl_tree：100%\n  * unordered_set：100%\n  * directed_graph：100%\n  * trie tree：100%\n  * unique_ptr：100%\n  * shared_ptr：100%\n  * Disjoint-set data structure：100%\n\n#TinySTL性能测试:\n###测试环境：Windows 7 \u0026\u0026 VS2013 \u0026\u0026 release模式\n###测试结果：\n####(1):vector\u0026lt;int\u003e\n\n    //std::vector\u003cint\u003e vec;\n    TinySTL::vector\u003cint\u003e vec;\n\tProfilerInstance::start();\n\tint i = 0;\n\tfor (; i != 10000; ++i){\n\t\tvec.push_back(i);\n\t}\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n    \n|container|quantity|time(ms)|  \n|---------|--------|--------|  \n|TinySTL::vector\u0026lt;int\u003e|10万|2|  \n|TinySTL::vector\u0026lt;int\u003e|100万|11|  \n|TinySTL::vector\u0026lt;int\u003e|1000万|129|  \n|std::vector\u0026lt;int\u003e|10万|6|  \n|std::vector\u0026lt;int\u003e|100万|16|  \n|std::vector\u0026lt;int\u003e|1000万|210|    \n####(2):vector\u0026lt;string\u003e\n\n    //std::vector\u003cstd::string\u003e vec;\n    TinySTL::vector\u003cstd::string\u003e vec;\n\tProfilerInstance::start();\n\tint i = 0;\n\tfor (; i != 100000; ++i){\n\t\tvec.push_back(std::string(\"zouxiaohang\"));\n\t}\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n    \n|container|quantity|time(ms)|  \n|---------|--------|--------|  \n|TinySTL::vector\u0026lt;string\u003e|10万|18|  \n|TinySTL::vector\u0026lt;string\u003e|100万|181|  \n|TinySTL::vector\u0026lt;string\u003e|1000万|2372|  \n|std::vector\u0026lt;string\u003e|10万|29|  \n|std::vector\u0026lt;string\u003e|100万|232|  \n|std::vector\u0026lt;string\u003e|1000万|1972|\n####(3):circular_buffer\u0026lt;int, N\u003e\n\n    TinySTL::circular_buffer\u003cint, 10000\u003e cb(10000, 0);\n    //boost::circular_buffer\u003cint\u003e cb(10000, 0);\n\tProfilerInstance::start();\n\tfor (int i = 0; i != 10000000; ++i){\n\t\tcb.push_back(i);\n\t}\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n    \n|container|quantity|time(ms)|  \n|---------|--------|--------|  \n|TinySTL::circular_buffer|1000万|75|  \n|TinySTL::circular_buffer|10000万|604|  \n|TinySTL::circular_buffer|100000万|5936|  \n|boost::circular_buffer|1000万|22|  \n|boost::circular_buffer|10000万|252|  \n|boost::circular_buffer|100000万|2241|  \n####(4):题目：利用bitmap找出str中未出现的字母  \n\n    std::string str(\"abcdefghijklmnpqrstuvwxyz\");\n    TinySTL::bitmap\u003c26\u003e bm;\n\tfor (auto it = str.cbegin(); it != str.cend(); ++it){\n\t\tbm.set(*it - 'a');\n\t}\n\tcout \u003c\u003c bm \u003c\u003c endl;\n\tcout \u003c\u003c bm.size() \u003c\u003c endl;\n\tfor (int i = 0; i != 26; ++i){\n\t\tif (!bm.test(i))\n\t\t\tcout \u003c\u003c \"字母\" \u003c\u003c (char)('a' + i) \u003c\u003c \"没出现！！！\" \u003c\u003c endl;\n\t}\n输出结果：  \n\n    111111111111110111111111111000000\n    32  \n    字母o没出现！！！\n    \n####(5):string\n\n    //std::string str;\n    TinySTL::string str;\n\tProfilerInstance::start();\n\tint i = 0;\n\tfor (; i != 1000000; ++i){\n\t\tstr.push_back('x');\n\t}\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n    \n|container|quantity|time(ms)|  \n|---------|--------|--------|  \n|TinySTL::string|100万|7|  \n|TinySTL::string|1000万|39|  \n|TinySTL::string|10000万|484|  \n|std::string|100万|37|  \n|std::string|1000万|229|  \n|std::string|10000万|1965|  \n\n####(6):priority_queue\u0026lt;int\u003e\n\n    //std::priority_queue\u003cint\u003e pq;\n    TinySTL::priority_queue\u003cint\u003e pq;\n\tProfilerInstance::start();\n\tint i = 0;\n\tfor (; i != 100000; ++i){\n\t\tpq.push(i);\n\t}\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n    \n|container|quantity|time(ms)|  \n|---------|--------|--------|  \n|TinySTL::priority_queue\u0026lt;int\u003e|10万|13|  \n|TinySTL::priority_queue\u0026lt;int\u003e|100万|97|  \n|TinySTL::priority_queue\u0026lt;int\u003e|1000万|1032|  \n|std::priority_queue\u0026lt;int\u003e|10万|12|  \n|std::priority_queue\u0026lt;int\u003e|100万|67|  \n|std::priority_queue\u0026lt;int\u003e|1000万|752|  \n\n    TinySTL::vector\u003cint\u003e v;\n    int i = 0;\n\tfor (; i != 100000; ++i){\n\t\tv.push_back(i);\n\t}\n\t//std::priority_queue\u003cint\u003e pq(v.begin(), v.end());\n\tTinySTL::priority_queue\u003cint\u003e pq(v.begin(), v.end());\n\tProfilerInstance::start();\n\tfor (i = 0; i != 100000; ++i){\n\t\tpq.pop();\n\t}\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n    \n|container|quantity|time(ms)|  \n|---------|--------|--------|  \n|TinySTL::priority_queue\u0026lt;int\u003e|10万|19|  \n|TinySTL::priority_queue\u0026lt;int\u003e|100万|137|  \n|TinySTL::priority_queue\u0026lt;int\u003e|1000万|1532|  \n|std::priority_queue\u0026lt;int\u003e|10万|7|  \n|std::priority_queue\u0026lt;int\u003e|100万|92|  \n|std::priority_queue\u0026lt;int\u003e|1000万|1214|  \n\n####(7):binary_search_tree\u0026lt;string\u003e\n\n    ifstream f;\n\t//char buff[256] = { 0 };\n\tstd::string word;\n\tf.open(\"C:\\\\Users\\\\zxh\\\\Desktop\\\\text.txt\");\n\tTinySTL::vector\u003cTinySTL::string\u003e v;\n\twhile (f.good()){\n\t\tf \u003e\u003e word;\n\t\t//std::copy(word.begin(), word.end(), buff);\n\t\t//v.push_back(TinySTL::string(buff, buff + word.size()));\n\t\tv.push_back(word);\n\t}\n\tTinySTL::binary_search_tree\u003cTinySTL::string\u003e sbst;\n\tProfilerInstance::start();\n\tfor (const auto\u0026 word : v){\n\t\tsbst.insert(word);\n\t}\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n\tf.close();\n    \n|container|quantity|time(ms)|  \n|---------|--------|--------|  \n|TinySTL::binary_search_tree\u0026lt;string\u003e|44067|16|  \n|TinySTL::binary_search_tree\u0026lt;string\u003e|169664|64|  \n|TinySTL::binary_search_tree\u0026lt;string\u003e|438230|277|   \n\n####(8):deque\u0026lt;int\u003e\n\n    //std::deque\u003cint\u003e dq;\n    TinySTL::deque\u003cint\u003e dq;\n\tProfilerInstance::start();\n\tconst int max = 10000000;\n\tint i = 0;\n\tfor (; i != max / 2; ++i){\n\t\tdq.push_front(i);\n\t}\n\tfor (; i != max; ++i){\n\t\tdq.push_back(i);\n\t}\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n    \n|container|quantity|time(ms)|  \n|---------|--------|--------|  \n|TinySTL::deque\u0026lt;int\u003e|10万|15|  \n|TinySTL::deque\u0026lt;int\u003e|100万|78|  \n|TinySTL::deque\u0026lt;int\u003e|1000万|1186|  \n|std::deque\u0026lt;int\u003e|10万|90|  \n|std::deque\u0026lt;int\u003e|100万|1087|  \n|std::deque\u0026lt;int\u003e|1000万|4835|  \n#####ps：这个性能差距的原因1是内部实现的机制不同，我的deque是预先分配内存因此相同条件下占用的内存更多，而stl的deque是需要的时候再分配，更加节省内存；2是stl的deque实现了更多更灵活的插入删除操作，我只是实现了在头尾的插入和删除\n\n####(9):avl_tree\u0026lt;int\u003e \n    TinySTL::binary_search_tree\u003cint\u003e bst;\n    TinySTL::avl_tree\u003cint\u003e avlt;\n\tfor (int i = 0; i != 10000; ++i){\n\t\tavlt.insert(i);\n\t\tbst.insert(i);\n\t}\n\tcout \u003c\u003c \"binary_search_tree height = \" \u003c\u003c bst.height() \u003c\u003c endl;\n\tcout \u003c\u003c \"avl_tree height = \" \u003c\u003c avlt.height() \u003c\u003c endl;\n输出结果：  \n\n    binary_search_tree height = 10000\n    avl_tree height = 14\n\n\n####(10):list\u0026lt;int\u003e\n\n    TinySTL::list\u003cint\u003e list;\n    //std::list\u003cint\u003e list;\n\tconst size_t max = 100000;\n\tProfilerInstance::start();\n\tfor (size_t i = 0; i != max; ++i)\n\t\tlist.push_back(i);\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n    \n|container|quantity|time(ms)|  \n|---------|--------|--------|  \n|TinySTL::list\u0026lt;int\u003e|10万|4|  \n|TinySTL::list\u0026lt;int\u003e|100万|33|  \n|TinySTL::list\u0026lt;int\u003e|1000万|286|  \n|std::list\u0026lt;int\u003e|10万|189|  \n|std::list\u0026lt;int\u003e|100万|1774|  \n|std::list\u0026lt;int\u003e|1000万|17571|  \n\n\n####(11):list\u0026lt;int\u003e::sort()\n\n    TinySTL::list\u003cint\u003e list1;\n    std::list\u003cint\u003e list2;\n\tstd::default_random_engine dre;\n\tstd::uniform_int_distribution\u003cint\u003e id;\n\tconst size_t max = 10000;\n\tfor (int i = 0; i != max; ++i){\n\t\tauto n = id(dre);\n\t\tlist1.push_back(n);\n\t\tlist2.push_back(n);\n\t}\n\tdouble cost1 = 0.0, cost2 = 0.0;\n\tfor (int i = 0; i != 100; ++i){\n\t\tProfilerInstance::start();\n\t\tlist1.sort();//TinySTL::list\u003cint\u003e\n\t\tProfilerInstance::finish();\n\t\tcost1 += ProfilerInstance::millisecond();\n\n\t\tProfilerInstance::start();\n\t\tlist2.sort();//std::list\u003cint\u003e\n\t\tProfilerInstance::finish();\n\t\tcost2 += ProfilerInstance::millisecond();\n\t}\n\tcout \u003c\u003c \"TinySTL time: \" \u003c\u003c cost1 / 100 \u003c\u003c \"ms\" \u003c\u003c endl;\n\tcout \u003c\u003c \"std time: \" \u003c\u003c cost2 / 100 \u003c\u003c \"ms\" \u003c\u003c endl;\n    \n|container|quantity|time(ms)|  \n|---------|--------|--------|  \n|TinySTL::list\u0026lt;int\u003e|1万|0.88|  \n|TinySTL::list\u0026lt;int\u003e|10万|17.621|  \n|TinySTL::list\u0026lt;int\u003e|100万|591.354|  \n|std::list\u0026lt;int\u003e|1万|1.25|  \n|std::list\u0026lt;int\u003e|10万|35.692|  \n|std::list\u0026lt;int\u003e|100万|665.128|  \n\n\n####(12):suffix_array\n\n    char arr[] = { 'a', 'a', 'b', 'a', 'a', 'a', 'a', 'b' };\n    TinySTL::suffix_array sa(arr, 8);\n\tauto suffixArray = sa.suffixArray();\n\tauto rankArray = sa.rankArray();\n\tauto heightArray = sa.heightArray();\n\n\tTinySTL::Test::print_container(suffixArray, \"suffixArray\");\n\tTinySTL::Test::print_container(rankArray, \"rankArray\");\n\tTinySTL::Test::print_container(heightArray, \"heightArray\");\n    \n![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/suffix_array.png)\n\n\n\n\n####(13):unordered_set\u0026lt;int\u003e\n\n    TinySTL::Unordered_set\u003cint\u003e ust(10);\n\t//std::unordered_set\u003cint\u003e ust(10);\n\tconst size_t insert_count = 1000000;\n\tconst uint64_t query_count = 100000000;\n\t//calculate total insert time\n\tProfilerInstance::start();\n\tfor (size_t i = 0; i != insert_count; ++i){\n\t\tust.insert(i);//per insert time\n\t}\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n\n\t//calculate total query time\n\tProfilerInstance::start();\n\tfor (uint64_t i = 0; i != query_count; ++i){\n\t\tust.count(i);//per query time\n\t}\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n    \n|container|quantity|insert time(ms)|query time(ms)|    \n|---------|--------|--------|--------|    \n|TinySTL::unordered_set\u0026lt;int\u003e|1万/1亿|8|97|      \n|TinySTL::unordered_set\u0026lt;int\u003e|10万/10亿|139|1000|    \n|TinySTL::unordered_set\u0026lt;int\u003e|100万/100亿|1214|9546|    \n|std::unordered_set\u0026lt;int\u003e|1万/1亿|64|101|    \n|std::unordered_set\u0026lt;int\u003e|10万/10亿|884|953|    \n|std::unordered_set\u0026lt;int\u003e|100万/100亿|2781|9682|   \n\n\n\n\n####(14):sort\n\n    std::random_device rd;\n\tconst int len = 10000000;\n\tint arr[len];\n\tstd::generate(std::begin(arr), std::end(arr), [\u0026rd](){return rd(); });\n\tProfilerInstance::start();\n\tTinySTL::sort(std::begin(arr), std::end(arr));\n\t//std::sort(std::begin(arr), std::end(arr));\n\tProfilerInstance::finish();\n\tProfilerInstance::dumpDuringTime();\n    \n|algorithm|quantity|time(ms)|  \n|---------|--------|--------|  \n|TinySTL::sort|10万|11|  \n|TinySTL::sort|100万|133|  \n|TinySTL::sort|1000万|1547|  \n|std::sort|10万|13|  \n|std::sort|100万|147|  \n|std::sort|1000万|1730| \n\n\n\n\n####(15):directed_graph\n\n    template\u003cclass Index, class Value\u003e\n\tusing dGraph = TinySTL::directed_graph \u003c Index, Value \u003e ;\n\tdGraph\u003cint, int\u003e g;\n\tdGraph\u003cint, int\u003e::nodes_set_type set1, set2, set3;\n\tset1.push_back(g.make_node(1, 11));\n\tset1.push_back(g.make_node(2, 22));\n\tset1.push_back(g.make_node(3, 33));\n\tg.add_node(g.make_node(0, 0), set1);\n\n\tset2.push_back(g.make_node(5, 55));\n\tset2.push_back(g.make_node(6, 66));\n\tset2.push_back(g.make_node(7, 77));\n\tg.add_node(g.make_node(1, 11), set2);\n\n\tset3.push_back(g.make_node(12, 1212));\n\tset3.push_back(g.make_node(13, 1313));\n\tset3.push_back(g.make_node(14, 1414));\n\tg.add_node(7, set3);\n\n\tg.make_edge(12, 2);\n\tg.make_edge(12, 3);\n\tg.make_edge(12, 0);\n\tstd::cout \u003c\u003c \"graph after add nodes:\" \u003c\u003c std::endl;\n\tstd::cout \u003c\u003c g.to_string();\n\n\tauto func = [](const dGraph\u003cint, int\u003e::node_type\u0026 node){\n\t\tstd::cout \u003c\u003c \"[\" \u003c\u003c node.first \u003c\u003c \",\" \u003c\u003c node.second \u003c\u003c \"]\" \u003c\u003c std::endl;\n\t};\n\tstd::cout \u003c\u003c \"graph DFS from node(1, 11):\" \u003c\u003c std::endl;\n\tg.DFS(1, func);\n\tstd::cout \u003c\u003c \"graph BFS from node(1, 11):\" \u003c\u003c std::endl;\n\tg.BFS(1, func);\n\n\tstd::cout \u003c\u003c \"graph after delete node(7, 77):\" \u003c\u003c std::endl;\n\tg.delete_node(dGraph\u003cint, int\u003e::node_type(7, 77));\n\tstd::cout \u003c\u003c g.to_string();\n    \n![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/graph1.png)  \n![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/graph_dfs.png)  \n![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/graph_bfs.png)  \n![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/graph2.png)\n\n\n\n\n\n####(16):trie tree\n\n    TinySTL::trie_tree t;\n\tstd::ifstream in;\n\tin.open(\"C:\\\\Users\\\\zxh\\\\Desktop\\\\trie_tree_test.txt\");\n\tstd::vector\u003cstd::string\u003e v;\n\tstd::string s;\n\twhile (in){\n\t\tin \u003e\u003e s;\n\t\tv.push_back(s);\n\t}\n\tProfilerInstance::start();\n\tfor (const auto\u0026 str : v){\n\t\tt.insert(TinySTL::string(str.data()));\n\t}\n\tProfilerInstance::finish();\n\tstd::cout \u003c\u003c \"build trie tree costs \" \u003c\u003c ProfilerInstance::millisecond() \u003c\u003c \"ms\" \u003c\u003c std::endl;\n\n\tProfilerInstance::start();\n\tauto res = t.get_word_by_prefix(\"v\");\n\tProfilerInstance::finish();\n\tstd::cout \u003c\u003c \"get word by prefix \\\"v\\\" costs \" \u003c\u003c ProfilerInstance::millisecond() \u003c\u003c \"ms\" \u003c\u003c std::endl;\n\tauto i = 0;\n\tfor (const auto\u0026 str : res){\n\t\t++i;\n\t\tif (i % 10 == 0) std::cout \u003c\u003c std::endl;\n\t\tstd::cout \u003c\u003c str \u003c\u003c \" \";\n\t}\n\tstd::cout \u003c\u003c std::endl;\n    \n![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/trie_tree.png)  \n\n\n\n####(17):shared_ptr\n\n    shared_ptr\u003cstring\u003e sp1(new string(\"hello\"));\n\tassert(sp1.use_count() == 1);\n\tassert(*sp1 == \"hello\");\n\tsp1-\u003eappend(\" world\");\n\tassert(*sp1 == \"hello world\");\n\n\t{\n\t\tauto sp2 = sp1;\n\t\tassert(sp1.use_count() == 2);\n\t}\n\tassert(sp1.use_count() == 1);\n\n\n\n####(18):unique_ptr\n\n    auto up = make_unique\u003cstring\u003e(10, '0');\n\tup-\u003eappend(\"111\");\n\tassert(*up == \"0000000000111\");\n\n\tup.release();\n\tassert(up == nullptr);\n\n\tup.reset(new string(\"hello\"));\n\tassert(*up == \"hello\");\n\n\n\n####(19):cow_ptr\n\n    cow_ptr\u003cstring\u003e cp1 = make_cow\u003cstring\u003e(\"zouxiaohang\");\n\tauto cp2 = cp1, cp3 = cp1;\n\tassert(cp1 == cp2 \u0026\u0026 cp2 == cp3);\n\tassert(*cp1 == *cp2 \u0026\u0026 *cp2 == *cp3 \u0026\u0026 *cp3 == \"zouxiaohang\");\n\n\tstring s = *cp2;//read\n\tassert(s == \"zouxiaohang\");\n\tassert(cp1 == cp2 \u0026\u0026 cp2 == cp3);\n\tassert(*cp1 == *cp2 \u0026\u0026 *cp2 == *cp3 \u0026\u0026 *cp3 == \"zouxiaohang\");\n\n\t*cp2 = (\"C++\");//write\n\tassert(*cp1 == *cp3 \u0026\u0026 *cp3 == \"zouxiaohang\");\n\tassert(*cp2 == \"C++\");\n\n\n\n\n####(19):union-find set\n\n    uf_set\u003c10\u003e uf;\n\tuf.Union(0, 1);\n\tuf.Union(2, 3);\n\tuf.Union(3, 1);\n\tassert(uf.Find(0) == uf.Find(2));\n    \n \n    \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzouxiaohang%2FTinySTL","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzouxiaohang%2FTinySTL","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzouxiaohang%2FTinySTL/lists"}