+/* Inserts NODE before or after node P in ABT, depending on the
+ value of AFTER.
+ If P is null, then the node is inserted as the first node in
+ the tree, if AFTER is true, or the last node, if AFTER is
+ false. */
+static inline void
+insert_relative (struct abt *abt, const struct abt_node *p, bool after,
+ struct abt_node *node)
+{
+ node->down[0] = NULL;
+ node->down[1] = NULL;
+ node->level = 1;
+
+ if (abt->root == NULL)
+ {
+ assert (p == NULL);
+ abt->root = node;
+ node->up = NULL;
+ abt_reaugmented (abt, node);
+ }
+ else
+ {
+ int dir = after;
+ if (p == NULL)
+ {
+ p = abt->root;
+ dir = !after;
+ }
+ while (p->down[dir] != NULL)
+ {
+ p = p->down[dir];
+ dir = !after;
+ }
+ CONST_CAST (struct abt_node *, p)->down[dir] = node;
+ node->up = CONST_CAST (struct abt_node *, p);
+ abt_reaugmented (abt, node);
+ }
+
+ while ((node = node->up) != NULL)
+ {
+ node = skew (abt, node);
+ node = split (abt, node);
+ }
+}
+
+/* Inserts NODE after node P in ABT.
+ If P is null, then the node is inserted as the first node in
+ the tree.
+ This function may be used only if ABT lacks a comparison
+ function. */
+void
+abt_insert_after (struct abt *abt,
+ const struct abt_node *p, struct abt_node *node)
+{
+ assert (abt->compare == NULL);
+ insert_relative (abt, p, true, node);
+}
+
+/* Inserts NODE before node P in ABT.
+ If P is null, then the node is inserted as the last node in
+ the tree.
+ This function may be used only if ABT lacks a comparison
+ function. */
+void
+abt_insert_before (struct abt *abt,
+ const struct abt_node *p, struct abt_node *node)
+{
+ assert (abt->compare == NULL);
+ insert_relative (abt, p, false, node);
+}
+