static inline avl_tree_node_t *node_prev(avl_tree_node_t *n) { if (!n) return n; /* n != NULL */ if (n->left) return node_rightmost(n->left); /* n->left = NULL */ if (node_is_right(n)) return n->parent; n = n->parent; while (n && node_is_left(n)) n = n->parent; if (n && !node_is_left(n)) n = n->parent; return n; }
/** * Print a single node and its children, siblings * @param d the dom in question * @param n the node to print */ static void dom_print_node( dom *d, node *n ) { node *c; int start,end; char *html_name = node_html_name(n); char *class_name = node_name(n); char attrs[128]; node_get_attributes( n, attrs, 128 ); if ( !node_empty(n) ) { if ( !node_is_root(n) ) dom_concat( d, "<%s%s class=\"%s\">", strlen(html_name) +strlen(class_name)+strlen(attrs)+11, html_name, attrs, class_name ); } c = node_first_child(n); start = node_offset(n); end = node_end(n); while ( c != NULL ) { int pos = node_offset( c ); if ( pos > start ) dom_print_text( d, start, pos-start ); dom_print_node( d, c ); start = node_end( c ); c = node_next_sibling( c ); } if ( end > start ) dom_print_text( d, start, end-start ); if ( !node_is_root(n) ) { if ( !node_empty(n) ) dom_concat(d, "</%s>",strlen(html_name)+3, html_name); else if ( node_rightmost(n) ) dom_concat(d,"<%s>",strlen(html_name)+2,html_name); } }
avl_tree_node_t *avl_tree_node_max(avl_tree_node_t *n) { return n ? node_rightmost(n) : NULL; }
static inline avl_tree_node_t *node_rightmost(avl_tree_node_t *n) { return n->right ? node_rightmost(n->right) : n; }