0

I used the example (exactly that example) given here: https://man7.org/linux/man-pages/man3/tsearch.3.html

But I could not use LEFT macro or struct node_t struct. I just want to move left or right node by myself because I need to check the tree created by tsearch if it is full tree, or balanced or ccomplete etc.

While using LEFT, I am getting implicit declaration error, with struct node_t I am getting dereferencing pointer to incomplete type.

How can I move to left or right child by myself? Is there any way to check the tree created by tsearch is balanced or not (e.g.)

Thanks

I checked search.c source code, found some macros but cannot use them because of compiling errors

dogus yuksel
  • 111
  • 1
  • 5
  • Better to post your code here. – chux - Reinstate Monica Dec 08 '22 at 15:32
  • My code is the same with in the link O share. I could not add one line on it. Tried LEFT macro but I got implicit dec. compile error. Is this macro the correct method to reach left node? Or what. I did not do anything special on the code in the link I shared – dogus yuksel Dec 08 '22 at 15:46
  • Apperently you changed the code... we can't see exactly what you did! Anyway... Is that LEFT macro even available for you!? I doubt it. It seems even the node-structure is hidden. So you really need so deep-diving into your systems actual implementation to do what you wanna do... not that easy – Support Ukraine Dec 08 '22 at 15:52
  • A little search got me this: https://codebrowser.dev/glibc/glibc/misc/tsearch.c.html – Support Ukraine Dec 08 '22 at 15:54
  • Links go stale, hence posting here makes for a better long term Q & A. – chux - Reinstate Monica Dec 08 '22 at 16:02
  • 2
    The example code you link to doesn't mention left or right nodes, or macros. Using the public interface, you can't do what you want to do. If you want to go digging in the private implementation details, you need to find the code for the implementation on your system (or find an implementation and port it to your system) and then you can do what you want. The `twalk()` function looks like your best bet — but you would probably have to implement a parallel structure that would make using the `tsearch(3)` functions redundant. You have to take the algorithm provided by `tsearch(3)` at face value. – Jonathan Leffler Dec 08 '22 at 16:06
  • The answer is I cannot do what I want with the public iface of search library I believe. Thank you all, for your support – dogus yuksel Dec 08 '22 at 17:30

0 Answers0