1. Subject

42: subject

2. Google test

In this project, I want inclure unit testing with the Google test framework.

3. Vector

example

3.1. Resources

cplusplus.com
The STL: on GNU/Linux
  • /usr/include/c++/12.2.0/bits/stl_vector.h

3.2. Check list

Member functions
Iterators
Capacity
Element access
Modifiers
Allocator

3.3. Reallocation

Internally, 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.

Instead, 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).

— cplusplus.com
\$z(x, y) = x * 2 ^ y\$
gnuplot

4. Iterator

Table 1. map and vector
Iterator Map vector

iterator

can change pair.second but not pair.first

can change the value

const_iterator

cannot change any things

cannot change the value

Table 2. iterator
Iterator set with begin() set with rbegin()

iterator

yes

no

const_iterator

yes

no

reverse_iterator

yes

yes

const_reverse_iterator

yes

yes

4.1. Resources

5. Pair

5.1. Resources

cplusplus.com
The STL: on GNU/Linux
  • /usr/include/c++/12.2.0/bits/stl_pair.h

5.2. Check-list

Member functions

6. Map

map usecase

6.1. Resources

cplusplus.com
wikipedia
  • Binary search tree

    • Nodes can have 2 subtrees

    • Items to the left of a given node are smaller

    • Items to the right of a given node are larger

  • Red–black tree

    • A node is either red or black

    • The root adn leaves (NULL) are balck

    • If a node is red, then its children are black

    • All path from a node to its NULL descendants contain the same number of black nodes

  • Tree rotation

6.2. Check-list

Member functions
Iterators:
Capacity:
Element access:
  • operator[]

  • at

Modifiers:
Observers:
Operations:
Allocator:

6.3. Red black tree

6.3.1. Deletion

redblack delete

6.3.2. resolve double black

redblack delete

6.3.3. Rules

  • The root is always black

  • Not two consecutives node can be red

For a node:

redblack

Here an example of a red black tree

  1. Case 0: Init, the first node is black

    redblack
  2. Insert: Add a second node

    The key (5) is smaller than the node key (15), so we set it into the left

    redblack

    We recolor the new node (5) to red

    redblack
  3. Add a third node

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

    redblack

    The uncle of the new node is NULL

    redblack

    We rotate

    redblack

    We recolor

    redblack