Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nyuuuukie/containers
A light reproduction of the std::vector, std::stack, std::map and std::set provided with custom container rbt
https://github.com/nyuuuukie/containers
21school 42cursus 42projects containers ft-containers
Last synced: 4 days ago
JSON representation
A light reproduction of the std::vector, std::stack, std::map and std::set provided with custom container rbt
- Host: GitHub
- URL: https://github.com/nyuuuukie/containers
- Owner: nyuuuukie
- License: mit
- Created: 2021-10-24T18:03:28.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-05T09:47:17.000Z (about 2 years ago)
- Last Synced: 2023-09-17T19:35:49.917Z (about 1 year ago)
- Topics: 21school, 42cursus, 42projects, containers, ft-containers
- Language: C++
- Homepage:
- Size: 433 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# containers
## Description
The aim of this project is to reproduce some of basic STL-containers:
- [std::vector](http://www.cplusplus.com/reference/vector/vector)
- [std::stack](http://www.cplusplus.com/reference/stack/stack)
- [std::map](http://www.cplusplus.com/reference/map/map)
- [std::set](http://www.cplusplus.com/reference/set/set)All containers are located in the ft namespace
ft::map and ft::set implementations are using red-black tree under the hood.
## Red-black tree
ft::rbt implemented as a independent container and could be used separately from set or map.
```c++
#include "rbt.hpp"int main() {
ft::rbt tree;
for (int i = 1; i < 10; i++) {
tree.insert(i);
}
tree.erase(6);return 0;
}
```## Console red-black tree visualizer
The visualizer implemented as a separated template class, with the same value type as the tree.
### Usage
These lines
```c++
#include "rbt.hpp"
#include "rbt_visualizer.hpp"int main() {
ft::rbt tree;
for (int i = 1; i < 20; i++) {
tree.insert(rand() % 100);
}
tree.erase(65);ft::rbt_visualizer rbv(tree);
// or
// ft::rbt_visualizer rbv;
// rbv.visualize(tree);
return 0;
}
```will produce this output to stdout:
![GitHub-Mark-Light](https://github.com/mhufflep/STL-containers/blob/main/screenshots/visualize_dark.png#gh-dark-mode-only)
![GitHub-Mark-Dark](https://github.com/mhufflep/STL-containers/blob/main/screenshots/visualize_light.png#gh-light-mode-only):warning: `Large trees may not fit on the screen. In that case, zoom out to see the correct tree picture`
## Compile
To compile properly you need to explicitly specify the path to the main folder of this repo.
For example:
```bash
clang++ test.cpp -I ~/Desktop/STL-containers
```## Tests
Use [Makefile](https://github.com/mhufflep/STL-containers/blob/main/Makefile) to change following vars:
* `INCLUDE_DIR` to specify root folder of your containers
* `CONT_SRCS` to specify list of all **not** .hpp files of your container (if there are)
* `DEBUG` to compile tests with debug flag
* `CYCLES` to change amount of the test's runs
* `OUTPUT_FT` and `OUTPUT_STD` to set custom output filename
* `TESTER_FT` and `TESTER_STD` to set custom tester executable nameRun `make` and tester will compare the output from the stl containers to ft automatically.
If `no differences` found, output files and tester executables `will be removed`.
`Otherwise`, you can compare output files manually and find mismatches. Tester executables `won't be deleted` as well, so you could run them and debug by yourself.