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);
 }
}


From: Willy Tarreau
Date: 2011-11-02 06:34
To: wsq003
CC: haproxy
Subject: Re: trying to use ebtree to store key-value paires
Hi,

On Tue, Nov 01, 2011 at 03:25:05PM +0800, wsq003 wrote:
> hi,
> 
> I found ebtree works in a good manner, so want to use it in other places.
> Dose ebtree support key-value pair? I would like to use it to replace 
> std::map at some specific condition.

it's mainly used for that. The principle is that you store a key in a
node and you store this node into a larger struct which contains all
your values. Then when you lookup the key, you find the node so you
know the struct holding the key. That's how it's used in haproxy. Look
at task.c for instance, the timer queue is scanned to wake up all tasks
with an expired timer. The key here is the timer and the "value" is the
task.

Willy

Reply via email to