Example Trace of Kruse's Insert Routine for B_Trees

Note:  This e.g. follows the picture of an order 5 B-tree drawn and passed out in class.

Global variable       newint

        39

       

In the following: param = parameter, lv = local variable,  out=output,  in = input, ret addr= return address, fn ret= value the function returns, ptr=pointer, ref= call by reference.

Also note - values in parentheses (  ) are values that eventually are placed in the memory cell in question, by a function which follows later in the stack.

The following is what the environment stack that is built  when insert(newint) is called in a main program.......

Environment of Function: Status - when popped off stack - Local variables, parameters, return addresses, return values......
insert last of all that follow

newentry(param)

ptr back to newint

 new_root(lv)

(node w/ 30)

median(lv)

(30)

right_branch(lv)

(node w/ 37, 40)

result(lv)

 

fn insert ret

 

insert ret addr

addr where called in main or ?

root

(node with 10,20)

push_down, 1st call right before insert above is popped or 2nd to last

current(in param)

address of root with 10,20,30,40

new_entry(in param)

ptr to newint

median(out param)

ptr to median up above in insert

right_branch(out param)

ptr to right_branch up above in insert

result(lv)

 

position(lv)

 

fn push_down ret

 

push_down ret addr

the line where push_down is called in insert

extra_entry(lv)

(ptr to cell w/ 37)

extra_branch(lv)

(ptr to node w/ 38,39)

search_node popped before the next (2nd) call to push_down, below current(in param)

root node w/10,20,30,40

target(in param)

ptr to newint or new_entry

position(out param)

0 then 3

fn search_node ret

not_present

search_node ret addr

 line with test  if == success, not so go to else clause in push_down

push_down, 2nd call right after the 3rd call to pushdown is popped

current(in param)

address of node with 33,35,37,38

(later has 33, 35 only)

new_entry(in param)

ptr to newint

median(out param)

ptr to extra_entry in the 1st call to push_down

right_branch(out param)

ptr to extra_branch in the 1st call to push_down

result(lv)

overflow

position(lv)

3

fn push_down ret

overflow

push_down ret addr

the line where push_down is called in 1st env of push_down, above (recursion)

extra_entry(lv)

(ptr to cell w/ 39)

extra_branch(lv)

(null)

search_node popped before the next (3rd) call to push_down, below current(in param)

address of 33,35,37,38

target(in param)

ptr to newint

position(out param)

0 then 4

fn search_node ret

not_present

search_node ret addr

 line with test  if == success, not so go to else clause in push_down

push_down, 3rd call right after search_node, above is called and before split_node, below is called

current(in param)

null

new_entry(in param)

ptr to newint

median(out param)

ptr to extra_entry in the 2nd call to push_down

right_branch(out param)

ptr to extra_branch in the 2nd call to push_down

result(lv)

overflow

position(lv)

4

fn push_down ret

overflow

push_down ret addr

the line where push_down is called in 2nd env of push_down, above (recursion)

extra_entry(lv)

 

extra_branch(lv)

 

split_node called in 2nd env of push_down, above, popped and returns to 2nd env of push_down current(param)

ptr to 33,35,37,38

extra_entry(out param)

ptr to push_down extra_entry

extra_branch(param)

ptr to push_down extra_branch

position(in param)

4

right_half(out param)

ptr to right_branch in 2nd push_down

median(out param)

ptr to median in 2nd push_down

fn split_node ret.

void

split_node ret. addr.

to call in 2nd push_down env.

mid(lv)

(3)

i(lv)

loop control var.

push_in puts 39 into  extra_branch in 2nd call to push_down skipping trace

details, here

Note: now push_in (above) is popped split_node(above) is popped 2nd call to push_down is popped! We are back in the 1st call to push_down right after the 2nd push_down call returns
split_node called in 1st env of push_down, above, popped and returns to 1st env of push_down current(param)

ptr to 10,20,30,40

(later just 10,20 remain in the node)

extra_entry(out param)

ptr to push_down extra_entry

extra_branch(param)

ptr to push_down extra_branch

position(in param)

3

right_half(out param)

ptr to right_branch in 1st push_down

median(out param)

ptr to median in 1st push_down

fn split_node ret.

void

split_node ret. addr.

to call in 1st push_down env.

mid(lv)

(3)

i(lv)

loop control var.

push_in puts 37 into  extra_branch in 1st call to push_down skipping trace

details, here

Note: when this last call to split_node completes... The 1st call to pushdown completes... Then insert completes by creating a new root node which will contain the value 30!