On Wed, Nov 02, 2011 at 02:05:44PM +0800, wsq003 wrote:
>
> Thank you Willy. It works.
>
> Following is an example how to use ebtree to store key-value pairs:
>
> struct relation {
> struct eb64_node cbm;
> long long key;
> struct proxy* be;
> };
>
> void test()
> {
> struct eb_root root;
> memset(&root, 0, sizeof(root));
>
> struct relation* rel = calloc(1, sizeof(struct relation));
> rel->cbm.key = 123;
> rel->key = 123;
> rel->be = 0;
> eb64i_insert(&root, &rel->cbm);
>
> struct eb64_node* nd = eb64i_lookup(&root, 123);
> if (nd) {
> rel = eb64_entry(nd, struct relation, cbm);
> }
> }
Note that you don't even need rel->key, you can store the key in
rel->cbm.key only. In haproxy, the tasks have their timers duplicated
as an optimization : the timer may be changed without updating the
tree, and this is detected by the fact that the tree's key does not
match the timer. If you don't need to do ugly things like this, you
simply don't need rel->key and you can safely use rel->cbm.key
everywhere. You just need to ensure you won't modify the key when
the node is in the tree (need to delete it first).
Regards,
Willy