summaryrefslogtreecommitdiff
path: root/doc/aapl/ex_avlmel.cpp
blob: 7e63d59d94689564878b466e77c8a3d2ae970588 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "avlmel.h"

/* Forward the element struct so we can pass it to AvlTreeEl. */
struct CustomEl;

/* Make two base structures that will be used by 
 * the tree to resolve ambiguites. */
struct CustomElBase1 : public AvlTreeEl<CustomEl> {};
struct CustomElBase2 : public AvlTreeEl<CustomEl> {};

struct CustomEl :
        public CustomElBase1,
        public CustomElBase2,
        public CmpOrd<int>
{
    /* For our purposes. */
    CustomEl(int key, const char *data) : key(key), data(data) { }

    const int getKey() { return key; }
    int key;
    const char *data;
};

int main()
{
    /* Specify to AvlMel which base to use. */
    AvlMel< CustomEl, int, CustomElBase1 > avltree1;
    AvlMel< CustomEl, int, CustomElBase2 > avltree2;

    /* With AvlMel it makes the most sense to new the element ourseves
     * rather than letting the tree do it for use. */
    CustomEl *avlElement = new CustomEl( 1, "CustomEl" );

    /* These two calls are completely independant and safe. */
    avltree1.insert( avlElement );
    avltree2.insert( avlElement );

    return 0;
}