From 7ac870e986d747880307f071ec0465604f299c24 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 14 Aug 2023 19:33:04 -0700 Subject: tree: bug: tree-delete-specific-node doesn't use key fun * tree.c (tr_delete_specific): We cant' juse use key(node) as the search key; we must apply the tree's key function to the node key field to retrieve the correct search key. * tests/010/tree.tl: New test case which fails without this bugfix: a node which is the left subtree of the root node doesn't get deleted since the search is led astray by the wrong key object. --- tests/010/tree.tl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests/010/tree.tl') diff --git a/tests/010/tree.tl b/tests/010/tree.tl index 56d04fa9..9d00fda6 100644 --- a/tests/010/tree.tl +++ b/tests/010/tree.tl @@ -166,7 +166,7 @@ (tree-delete tr 18) 18 (tree-delete tr 19) 19) -(set *tree-fun-whitelist* [list* '= '< *tree-fun-whitelist*]) +(set *tree-fun-whitelist* [list* '= '< 'to *tree-fun-whitelist*]) (let ((tr [tree '(1 2 3) identity < =])) (mtest @@ -256,3 +256,9 @@ (tree-del-min tr) 10 (tree-count tr) 0 (tree-del-min tr) nil)) + +(let* ((tr [tree '(#R(1 10) #R(11 20) #R(21 30)) to]) + (node (tree-lookup-node tr 10))) + (test node #N(#R(1 10) nil nil)) + (tree-delete-specific-node tr node) + (test tr #T((to) #R(11 20) #R(21 30)))) -- cgit v1.2.3