{"id":15047243,"url":"https://github.com/t-h2o/containers","last_synced_at":"2026-04-01T17:16:54.831Z","repository":{"id":64958271,"uuid":"578315625","full_name":"t-h2o/containers","owner":"t-h2o","description":"The standard C++ containers have all a specific usage. To make sure you understand them, let’s re-implement them!","archived":false,"fork":false,"pushed_at":"2023-03-03T12:25:49.000Z","size":477,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-28T00:37:08.087Z","etag":null,"topics":["42","containers","cpp","cpp98","stl-containers"],"latest_commit_sha":null,"homepage":"https://t-h2o.github.io/containers","language":"HTML","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/t-h2o.png","metadata":{"files":{"readme":"README.adoc","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-14T19:03:56.000Z","updated_at":"2023-01-24T17:03:21.000Z","dependencies_parsed_at":"2024-09-28T23:40:27.703Z","dependency_job_id":"da0c3e04-42e7-4b78-8746-3cefc57b1c87","html_url":"https://github.com/t-h2o/containers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/t-h2o/containers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-h2o%2Fcontainers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-h2o%2Fcontainers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-h2o%2Fcontainers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-h2o%2Fcontainers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/t-h2o","download_url":"https://codeload.github.com/t-h2o/containers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-h2o%2Fcontainers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31290537,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["42","containers","cpp","cpp98","stl-containers"],"created_at":"2024-09-24T20:55:41.395Z","updated_at":"2026-04-01T17:16:54.812Z","avatar_url":"https://github.com/t-h2o.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"= Containers\n:nofooter:\n:toc: left\n:sectnums:\n:stylesheet: assets/my-stylesheet.css\n:stem:\n\nGitHub: https://github.com/t-h2o/containers[t-h2o/containers]\n\n== Subject\n\n42: https://cdn.intra.42.fr/pdf/pdf/60315/en.subject.pdf[subject]\n\n== Google test\n\nIn this project, I want inclure https://en.wikipedia.org/wiki/Unit_testing[unit testing] with the https://google.github.io/googletest/[Google test] framework.\n\n== Vector\n\nimage::assets/vector.svg[example]\n\n=== Resources\n\n.cplusplus.com\n* https://cplusplus.com/reference/vector/vector[`std::vector`]\n* https://cplusplus.com/reference/memory/allocator/[`std::allocator`]\n\n.The STL: on GNU/Linux\n* `/usr/include/c++/12.2.0/bits/stl_vector.h`\n\n=== Check list\n\n.Member functions\n* [x] https://cplusplus.com/reference/vector/vector/vector/[`constructor`]\n** [x] default\n** [x] fill\n** [x] range\n** [x] copy\n* [x] https://cplusplus.com/reference/vector/vector/~vector/[`destructor`]\n* [x] https://cplusplus.com/reference/vector/vector/operator=/[`operator=`]\n\n.Iterators\n\n* [x] https://cplusplus.com/reference/vector/vector/begin/[`begin`]\n* [x] https://cplusplus.com/reference/vector/vector/end/[`end`]\n* [ ] https://cplusplus.com/reference/vector/vector/rbegin/[`rbegin`]\n* [ ] https://cplusplus.com/reference/vector/vector/rend/[`rend`]\n* [ ] https://cplusplus.com/reference/vector/vector/cbegin/[`cbegin`]\n* [ ] https://cplusplus.com/reference/vector/vector/cend/[`cend`]\n* [ ] https://cplusplus.com/reference/vector/vector/crbegin/[`crbegin`]\n* [ ] https://cplusplus.com/reference/vector/vector/crend/[`crend`]\n\n.Capacity\n* [x] https://cplusplus.com/reference/vector/vector/size/[`size`]\n* [x] https://cplusplus.com/reference/vector/vector/max_size/[`max_size`]\n* [x] https://cplusplus.com/reference/vector/vector/resize/[`resize`]\n* [x] https://cplusplus.com/reference/vector/vector/capacity/[`capacity`]\n* [x] https://cplusplus.com/reference/vector/vector/empty/[`empty`]\n* [x] https://cplusplus.com/reference/vector/vector/reserve/[`reserve`]\n* [x] https://cplusplus.com/reference/vector/vector/shrink_to_fit/[`shrink_to_fit`]\n\n.Element access\n* [x] `operator[]`\n* [x] https://cplusplus.com/reference/vector/vector/at/[`at`]\n* [x] https://cplusplus.com/reference/vector/vector/front/[`front`]\n* [x] https://cplusplus.com/reference/vector/vector/back/[`back`]\n* [x] https://cplusplus.com/reference/vector/vector/data/[`data`]\n\n.Modifiers\n* [x] https://cplusplus.com/reference/vector/vector/assign/[`assign`]\n** [x] range\n** [x] fill\n* [x] https://cplusplus.com/reference/vector/vector/push_back/[`push_back`]\n* [x] https://cplusplus.com/reference/vector/vector/pop_back/[`pop_back`]\n* [x] https://cplusplus.com/reference/vector/vector/insert/[`insert`]\n** [x] single element\n** [x] fill\n** [x] range\n* [x] https://cplusplus.com/reference/vector/vector/erase/[`erase`]\n* [x] https://cplusplus.com/reference/vector/vector/swap/[`swap`]\n* [x] https://cplusplus.com/reference/vector/vector/clear/[`clear`]\n* [ ] https://cplusplus.com/reference/vector/vector/emplace/[`emplace`]\n* [ ] https://cplusplus.com/reference/vector/vector/emplace_back/[`emplace_back`]\n\n.Allocator\n* [ ] https://cplusplus.com/reference/vector/vector/get_allocator/[`get_allocator`]\n\n=== Reallocation\n\n[blockquote, cplusplus.com]\n____\nInternally, vectors use a dynamically allocated array to store their elements. This array may need to be reallocated in order to grow in size when new elements are inserted, which implies allocating a new array and moving all elements to it. This is a relatively expensive task in terms of processing time, and thus, vectors do not reallocate each time an element is added to the container.\n\nInstead, vector containers may allocate some extra storage to accommodate for possible growth, and thus the container may have an actual capacity greater than the storage strictly needed to contain its elements (i.e., its size). Libraries can implement different strategies for growth to balance between memory usage and reallocations, but in any case, reallocations should only happen at logarithmically growing intervals of size so that the insertion of individual elements at the end of the vector can be provided with amortized constant time complexity (see push_back).\n____\n\n[stem]\n++++\nz(x, y) = x * 2 ^ y\n++++\n\nimage::assets/gnuplot.svg[gnuplot]\n\n== Iterator\n\n.map and vector\n|===\n|Iterator | Map | vector\n\n|`iterator`\n|can change pair.second but not pair.first\n|can change the value\n\n|`const_iterator`\n|cannot change any things\n|cannot change the value\n\n|===\n\n.iterator\n|===\n|Iterator | set with `begin()` | set with `rbegin()`\n\n|`iterator`\n| yes\n| no\n\n|`const_iterator`\n| yes\n| no\n\n|`reverse_iterator`\n| yes\n| yes\n\n|`const_reverse_iterator`\n| yes\n| yes\n\n|===\n\n=== Resources\n\n.cplusplus.com\n* https://cplusplus.com/reference/iterator/[`\u003citerator\u003e`]\n* https://cplusplus.com/reference/iterator/iterator/[`std::iterator`]\n* https://cplusplus.com/reference/iterator/iterator_traits/[`std::iterator_traits`]\n\n== Pair\n\n=== Resources\n\n.cplusplus.com\n* https://cplusplus.com/reference/utility/pair/[`std::pair`]\n\n.The STL: on GNU/Linux\n* `/usr/include/c++/12.2.0/bits/stl_pair.h`\n\n=== Check-list\n\n.Member functions\n* [x] https://cplusplus.com/reference/utility/pair/pair/[`constructor`]\n** [x] default\n** [x] copy\n** [x] initialization\n* [ ] https://cplusplus.com/reference/utility/pair/operator=/[`operator=`]\n* [ ] https://cplusplus.com/reference/utility/pair/swap/[`swap`]\n\n== Map\n\nimage::assets/map_usecase.svg[map usecase]\n\n=== Resources\n\n.cplusplus.com\n* https://cplusplus.com/reference/map/map/[`std::map`]\n\n.wikipedia\n* https://en.wikipedia.org/wiki/Binary_search_tree[Binary search tree]\n** Nodes can have 2 subtrees\n** Items to the left of a given node are smaller\n** Items to the right of a given node are larger\n* https://en.wikipedia.org/wiki/Red%E2%80%93black_tree[Red–black tree]\n** A node is either red or black\n** The root adn leaves (NULL) are balck\n** If a node is red, then its children are black\n** All path from a node to its NULL descendants contain the same number of black nodes\n* https://en.wikipedia.org/wiki/Tree_rotation[Tree rotation]\n\n.YouTube @MisterCode\n* https://youtu.be/AN0axYeLue0[Red-Black Trees - Data Structures]\n* https://youtu.be/JwgeECkckRo[Insertion for Red-Black Trees ( incl. Examples )]\n* https://youtu.be/_c30ot0Kcis[Deletion for Red-Black Trees ( incl. Examples )]\n\n.YouTube @alenachang8071\n* https://youtu.be/eoQpRtMpA9I[Red-black tree deletion: steps + 10 examples]\n\n.other\n* https://www.cs.usfca.edu/~galles/visualization/RedBlack.html[red black tree visualization]\n\n=== Check-list\n\n.Member functions\n* [ ] https://cplusplus.com/reference/map/map/map/[`constructor`]\n* [ ] https://cplusplus.com/reference/map/map/~map/[`destructor`]\n* [ ] https://cplusplus.com/reference/map/map/operator=/[`operator=`]\n\n.Iterators:\n* [ ] https://cplusplus.com/reference/map/map/begin[`begin`]\n* [ ] https://cplusplus.com/reference/map/map/end[`end`]\n* [ ] https://cplusplus.com/reference/map/map/rbegin[`rbegin`]\n* [ ] https://cplusplus.com/reference/map/map/rend[`rend`]\n* [ ] https://cplusplus.com/reference/map/map/cbegin[`cbegin`]\n* [ ] https://cplusplus.com/reference/map/map/cend[`cend`]\n* [ ] https://cplusplus.com/reference/map/map/crbegin[`crbegin`]\n* [ ] https://cplusplus.com/reference/map/map/crend[`crend`]\n\n.Capacity:\n* [x] https://cplusplus.com/reference/map/map/empty[`empty`]\n* [x] https://cplusplus.com/reference/map/map/size[`size`]\n* [ ] https://cplusplus.com/reference/map/map/max_size[`max_size`]\n\n.Element access:\n* [ ] `operator[]`\n* [ ] https://cplusplus.com/reference/map/map/at[`at`]\n\n.Modifiers:\n* [ ] https://cplusplus.com/reference/map/map/insert[`insert`]\n* [ ] https://cplusplus.com/reference/map/map/erase[`erase`]\n* [ ] https://cplusplus.com/reference/map/map/swap[`swap`]\n* [ ] https://cplusplus.com/reference/map/map/clear[`clear`]\n* [ ] https://cplusplus.com/reference/map/map/emplace[`emplace`]\n* [ ] https://cplusplus.com/reference/map/map/emplace_hint[`emplace_hint`]\n\n.Observers:\n* [ ] https://cplusplus.com/reference/map/map/key_comp[`key_comp`]\n* [ ] https://cplusplus.com/reference/map/map/value_comp[`value_comp`]\n\n.Operations:\n* [ ] https://cplusplus.com/reference/map/map/find[`find`]\n* [ ] https://cplusplus.com/reference/map/map/count[`count`]\n* [ ] https://cplusplus.com/reference/map/map/lower_bound[`lower_bound`]\n* [ ] https://cplusplus.com/reference/map/map/upper_bound[`upper_bound`]\n* [ ] https://cplusplus.com/reference/map/map/equal_range[`equal_range`]\n\n.Allocator:\n* [ ] https://cplusplus.com/reference/map/map/get_allocator[`get_allocator`]\n\n=== Red black tree\n\n==== Deletion\n\nimage::assets/rbt_delete.svg[redblack delete]\n\n==== resolve double black\n\nimage::assets/resolve_double_black.svg[redblack delete]\n\n==== Rules\n\n* The root is always black\n* Not two consecutives node can be red\n\nFor a node:\n\nimage::assets/node.svg[redblack]\n\nHere an example of a red black tree\n\n. Case 0: Init, the first node is black\n+\nimage::assets/rbt00.svg[redblack]\n\n. Insert: Add a second node\n+\nThe key (5) is smaller than the node key (15), so we set it into the left\n+\nimage::assets/rbt10.svg[redblack]\n+\nWe recolor the new node (5) to red\n+\nimage::assets/rbt11.svg[redblack]\n\n. Add a third node\n+\nThe key (1) is smaller than the node key (15): go to the left. The key (1) is smaller than (5), so we set it into the left.\n+\nimage::assets/rbt20.svg[redblack]\n+\nThe uncle of the new node is NULL\n+\nimage::assets/rbt21.svg[redblack]\n+\nWe rotate\n+\nimage::assets/rbt22.svg[redblack]\n+\nWe recolor\n+\nimage::assets/rbt23.svg[redblack]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft-h2o%2Fcontainers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ft-h2o%2Fcontainers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft-h2o%2Fcontainers/lists"}