Ethereal-dev: Re: [Ethereal-dev] GHashTable

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

Date: Tue, 7 Feb 2006 19:04:51 +0100
the x_hash function should be very fast and yield a guint32 that will
be used to choose the primary node to be used.
the x_equal should test whether the key is equal (whatever equals
means in your application domain).

x_hash() will be used to select the node in the tree, once the node is
found every instance that has the same hash value will be sequantialy
checked for equality.

That comes to:

if x_hash() yields alway 1 (as an example) then the tree will have a
single node and the search will be sequential ( 1* x_hash + N/2 *
x_equal ).

if x_hash() does a perfect job discerning every diferent key with a
diferent value you'l then have a perfect binary serach ( log2(N) *
x_hash + 1 * x_equal ).

It's up to you to wheight what's best.

L.

On 2/7/06, fabio matturro <fabiomax3@xxxxxxxxxxx> wrote:
> Hello,
> I would like to attach different data structures  to the same conversation.
> This subject is not fully explained in the developer guide (par. 2.2.9) so
> I'd like you to
> give me some tips ;)
>
> Let's take the example on the guide (taken from packet_afs.c)
>
>
> Here a structure request_key  is being initialized and is used to look up
> into a hash table
>
> Now, how should I initialized this GHashTable structure?
> Taking packet_afs.c as an example I notice this line:
>
> afs_request_hash = g_hash_table_new(afs_hash, afs_equal);
>
> This is supposed to initialize the hash table
>
> Now, what are afs_hash & afs_equal for?
> I suppose that afs_equal contains the criterium to discern whether a key is
> contained
> in the table
> [...]
> static gint
> afs_equal(gconstpointer v, gconstpointer w)
> {
>   const struct afs_request_key *v1 = (const struct afs_request_key *)v;
>   const struct afs_request_key *v2 = (const struct afs_request_key *)w;
>
>   if (v1 -> conversation == v2 -> conversation &&
>       v1 -> service == v2 -> service &&
>       v1 -> callnumber == v2 -> callnumber ) {
>
>     return 1;
>   }
>
>   return 0;
> }
>
> [...]
>
> and afs_hash calculates a numeric key starting from the data structure
> pointer it is passed
>
> [...]
> static guint
> afs_hash (gconstpointer v)
> {
>         const struct afs_request_key *key = (const struct afs_request_key *)v;
>         guint val;
>
>         val = key -> conversation + key -> service + key -> callnumber;
>
>         return val;
> }
> [...]
>
> Can you confirm it?
>
> : - D Thanx
>
> _________________________________________________________________
> Scarica gratuitamente MSN Toolbar! http://toolbar.msn.it/
>
> _______________________________________________
> Ethereal-dev mailing list
> Ethereal-dev@xxxxxxxxxxxx
> http://www.ethereal.com/mailman/listinfo/ethereal-dev
>


--
This information is top security. When you have read it, destroy yourself.
-- Marshall McLuhan