Ethereal-dev: [Ethereal-dev] GHashTable

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

From: "fabio matturro" <fabiomax3@xxxxxxxxxxx>
Date: Tue, 07 Feb 2006 15:28:21 +0100
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/