/** * This creates a new node in the AVL then returns the created node * so that you might populate it with data. If the key already * exists, then the existing node is returned. * * @param avl the AVL to add a property to. * @param key the key to add to the AVL. * * @return the newly created AVL node. */ PropPtr new_prop(PropPtr *avl, char *key) { PropPtr ret; register PropPtr p = *avl; register int cmp; static short balancep; if (p) { cmp = strcasecmp(key, PropName(p)); if (cmp > 0) { ret = new_prop(&(p->right), key); } else if (cmp < 0) { ret = new_prop(&(p->left), key); } else { balancep = 0; return (p); } if (balancep) { *avl = balance_node(p); } return ret; } else { p = *avl = alloc_propnode(key); balancep = 1; return (p); } }
static PropPtr insert(char *key, PropPtr * avl) { PropPtr ret; register PropPtr p = *avl; register int cmp; static short balancep; if (p) { cmp = Comparator(key, PropName(p)); if (cmp > 0) { ret = insert(key, &(AVL_RT(p))); } else if (cmp < 0) { ret = insert(key, &(AVL_LF(p))); } else { balancep = 0; return (p); } if (balancep) { *avl = balance_node(p); } return ret; } else { p = *avl = alloc_propnode(key); balancep = 1; return (p); } }