From: Heng Li Date: Thu, 17 Sep 2015 23:28:11 +0000 (-0400) Subject: added new kbtree traversal X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=4d007752bf4948ef16326c1baa6ea85aae5c769a;p=klib.git added new kbtree traversal --- diff --git a/index.html b/index.html index a7824eb..6834bbc 100644 --- a/index.html +++ b/index.html @@ -5767,7 +5767,7 @@ pre .xml .cdata {
lh3
-
+

 
@@ -6052,7 +6052,7 @@ as type-specific code. A generic library written with `void*` will not get such performance boost.
-
+
!!Synopsis
 * Functionality: generic balanced search tree based on B-tree.
 * Library source code: [[kbtree.h|https://github.com/attractivechaos/klib/blob/master/kbtree.h]]
@@ -6088,8 +6088,14 @@ int main(int argc, char *argv[])
         else ++p->count;
     }
     // ordered tree traversal
-    #define traverse_func(p) printf("%d\t%s\n", (p)->count, (p)->key);
-    __kb_traverse(elem_t, b, traverse_func);
+    if (kb_size(b) > 0) { // not working on empty trees
+        kbitr_t itr;
+        kb_itr_first(str, b, &itr); // get the first iterator
+        do {
+            p = &kb_itr_key(elem_t, &itr); // get pointer to the key
+            printf("%d\t%s\n", p->count, p->key);
+        } while (kb_itr_next(str, b, &itr)); // move on
+    }
     kb_destroy(str, b);
     return 0;
 }