static JRB jrb_insert_b(JRB n, Jval key, Jval val) { JRB newleft, newright, newnode, p; if (ishead(n)) { if (n->parent == n) { /* Tree is empty */ mk_new_ext(newnode, key, val); insert(newnode, n); n->parent = newnode; newnode->parent = n; setroot(newnode); return newnode; } else { mk_new_ext(newright, key, val); insert(newright, n); newleft = newright->blink; setnormal(newleft); mk_new_int(newleft, newright, newleft->parent, isleft(newleft)); p = rprev(newright); if (!ishead(p)) setlext(p, newright); return newright; } } else { mk_new_ext(newleft, key, val); insert(newleft, n); setnormal(n); mk_new_int(newleft, n, n->parent, isleft(n)); p = lprev(newleft); if (!ishead(p)) setrext(p, newleft); return newleft; } }
Rb_node rb_insert_b(Rb_node n, char *key, char *val) { Rb_node newleft, newright, newnode, p; if (ishead(n)) { if (n->p.root == n) { /* Tree is empty */ mk_new_ext(newnode, key, val); insert(newnode, n); n->p.root = newnode; newnode->p.parent = n; setroot(newnode); return newnode; } else { mk_new_ext(newright, key, val); insert(newright, n); newleft = newright->c.list.blink; setnormal(newleft); mk_new_int(newleft, newright, newleft->p.parent, isleft(newleft)); p = rprev(newright); if (!ishead(p)) p->k.lext = newright; return newright; } } else { mk_new_ext(newleft, key, val); insert(newleft, n); setnormal(n); mk_new_int(newleft, n, n->p.parent, isleft(n)); p = lprev(newleft); if (!ishead(p)) p->v.rext = newleft; return newleft; } }