GNU libavl 2.0.1
Author: Ben Pfaff

12.3 Insertion |

Insertion is, as usual, one of the operations that must be newly implemented for our new type of tree. There is nothing surprising in the function's outline:

    456. <RTRB item insertion function 456> =
    void **
    rtrb_probe (struct rtrb_table *tree, void *item)
    {
      struct rtrb_node *pa[RTRB_MAX_HEIGHT]; /* Nodes on stack. */
      unsigned char da[RTRB_MAX_HEIGHT];   /* Directions moved from stack nodes. */
      int k;                               /* Stack height. */

      struct rtrb_node *p; /* Current node in search. */
      struct rtrb_node *n; /* New node. */
      int dir;             /* Side of p on which p is located. */

      assert (tree != NULL && item != NULL);

      <Step 1: Search RTRB tree for insertion point 457>
      <Step 2: Insert RTRB node 458>
      <Step 3: Rebalance after RTRB insertion 459>

      return &n->rtrb_data;
    }

This code is included in 455.

Subsections:

- 12.3.1 Steps 1 and 2: Search and Insert
- 12.3.2 Step 3: Rebalance

12.2 Operations | 12 Right-Threaded Red-Black Trees | 12.3.1 Steps 1 and 2: Search and Insert