fixes that cx_tree_search() did not investigate subtrees with equally good distance

Sat, 12 Apr 2025 21:32:31 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 12 Apr 2025 21:32:31 +0200
changeset 1286
5492e8ef05f4
parent 1285
7acbaa74fbd0
child 1287
3a3ffc27813f

fixes that cx_tree_search() did not investigate subtrees with equally good distance

fixes #632

CHANGELOG file | annotate | diff | comparison | revisions
docs/Writerside/topics/about.md file | annotate | diff | comparison | revisions
src/tree.c file | annotate | diff | comparison | revisions
--- a/CHANGELOG	Fri Apr 11 16:48:58 2025 +0200
+++ b/CHANGELOG	Sat Apr 12 21:32:31 2025 +0200
@@ -5,6 +5,7 @@
  * changes grow strategy for the mempory pool to reduce reallocations
  * fixes implementation of cxBufferTerminate()
  * fixes allocator arguments for some printf.h functions not being const
+ * fixes that cx_tree_search() did not investigate subtrees with equally good distance
 
 Version 3.1 - 2025-02-11
 ------------------------
--- a/docs/Writerside/topics/about.md	Fri Apr 11 16:48:58 2025 +0200
+++ b/docs/Writerside/topics/about.md	Sat Apr 12 21:32:31 2025 +0200
@@ -31,7 +31,8 @@
 * adds cxMempoolTransfer() and cxMempoolTransferObject()
 * changes grow strategy for the mempory pool to reduce reallocations
 * fixes implementation of cxBufferTerminate()
-* fixes allocator arguments for some printf.h functions not being const 
+* fixes allocator arguments for some printf.h functions not being const
+* fixes that cx_tree_search() did not investigate subtrees with equally good distance
 
 ### Version 3.1 - 2025-02-11 {collapsible="true"}
 
--- a/src/tree.c	Fri Apr 11 16:48:58 2025 +0200
+++ b/src/tree.c	Sat Apr 12 21:32:31 2025 +0200
@@ -226,14 +226,14 @@
         int ret_elem = sfunc(elem, node);
         if (ret_elem == 0) {
             // if found, exit the search
-            *result = (void *) elem;
+            *result = elem;
             ret = 0;
             break;
         } else if (ret_elem > 0 && ret_elem < ret) {
             // new distance is better
             *result = elem;
             ret = ret_elem;
-        } else {
+        } else if (ret_elem < 0 || ret_elem > ret) {
             // not contained or distance is worse, skip entire subtree
             cxTreeIteratorContinue(iter);
         }

mercurial