Re: [Libclc-developers] Need help with clc_map.
Status: Planning
Brought to you by:
augestad
|
From: Michael B.A. <mb...@io...> - 2003-03-19 20:17:31
|
On Wed, 19 Mar 2003 17:32:51 +0100
Bj=F8rn Augestad <bo...@me...> wrote:
> I'm trying to implement a map, but need some help/advice. Here's the=20
> problem.
>=20
> 1) The map should handle keys of different datatypes.
> 2) The C99 standard, in =A76.3.2.3 Pointers, paragraph 5 and 6, describe=
=20
> integer->void*->integer conversion rules. IMHO it rules out the use of=20
> void* as a general key parameter, which means that we cannot have just=20
> one clc_map_set(clc_map m, void* key, void* data). Is my interpretation=20
> correct?
It's a rare thing to need to use an integer (or real) as a hash key
directly. Usually the map implementation provides a mechanism for the user
to supply their own hash function in which case if they want to hash by
integer there is usually an opportunity to pass the struct to which it
is a member. So the user supplied hash function might just look like:
unsigned long
hash_foo(void *ptr)
{
struct foo *foo =3D ptr;
return foo->theint * LARGE_PRIME_NUMBER;
}
> 3) I ended up with this interface for set/get functions and need=20
> opinions. Please let me know how you all feel about it. Thanks in advance.
>=20
> int clc_map_set(clc_map m, const char* key, void* data);
<snip>
> void* clc_map_get(clc_map m, const char* key);
<snip>
That's all you need really. At the very least you don't really need
signed keys where the unsigned functions work fine.
Is NULL a permitted data value? Can anything go wrong in the get function
that would cause an error? If so how do you indicate to the caller that
an error occured?
Mike
--=20
A program should be written to model the concepts of the task it
performs rather than the physical world or a process because this
maximizes the potential for it to be applied to tasks that are
conceptually similar and, more important, to tasks that have not
yet been conceived.=20
|