Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use libavl?

I'm trying to use GNU libavl (http://adtinfo.org/) for one of my academic projects. I need a simple enough tutorial on how to use the BST(Binary search tree) implementation provided by the library. What I need to do is sort a (key,value) pair(about 30000 strings and there frequencies) using a BST according to the value. Although the library is well documented, it doesn't give any straight foreword answer to my question and I don't have the time to read trough all the documentation and test code. I would like to know if there is much faster way to do the sorting.

like image 432
Madushan Avatar asked Mar 03 '14 07:03

Madushan


2 Answers

The accepted answer is wrong since it points to a different library instead of GNU libavl. Also it doesn't answer the original inquiry.

I need a simple enough tutorial

I'm not aware about any tutorials for this library. You also say that

I don't have the time to read trough all the documentation and test code.

But while there is no better option I think reading tests is the best possible recommendation for people who are interested in understanding GNU libavl. Also the accepted answer is even further by relevance from what I'm about to write.

GNU libavl contains tests which can be read as usage examples. But since the library is written in TexiWEB language, in order to get the C source code you have to compile the original source first.

Clone the source code:

$ git clone git://git.savannah.gnu.org/avl.git

Then inside the avl directory run:

$ make programs

After the compilation you'll see the C source code and compiled binaries.

Now you can read the tests and find out from there how to use the library. Test sources have -test.c suffix. For example tests for AVL trees are in the avl-test.c file.

Also note, that GNU libavl is not intended to be used as a shared library so you'll have to include the C source files to your project.

like image 168
senya Avatar answered Sep 29 '22 11:09

senya


int main(int argc, char **argv)
{
    tree *avl_tree = NULL;
    struct data tmp;
    unsigned result;

    (void) argc;
    (void) argv;

    // Initialize a new tree with our three previously defined
    // functions to store data structure.
    avl_tree = init_dictionnary(data_cmp, data_print, data_delete, data_copy);

    tmp.key = 42;
    tmp.value = 4242;

    // Add element {42, 4242} in our tree.
    result = insert_elmt(avl_tree, &tmp, sizeof(struct data));
like image 38
Arun Avatar answered Sep 29 '22 11:09

Arun