Skip to content

A light reproduction of the std::vector, std::stack, std::map and std::set provided with custom container rbt

License

Notifications You must be signed in to change notification settings

nyuuuukie/containers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

containers

Description

The aim of this project is to reproduce some of basic STL-containers:

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.

#include "rbt.hpp"

int main() {

    ft::rbt<int> 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

#include "rbt.hpp"
#include "rbt_visualizer.hpp"

int main() {

    ft::rbt<int> 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 GitHub-Mark-Dark

⚠️ 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:

clang++ test.cpp -I ~/Desktop/STL-containers

Tests

Use 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 name

Run 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.

About

A light reproduction of the std::vector, std::stack, std::map and std::set provided with custom container rbt

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published