Leopold Toetsch <[EMAIL PROTECTED]> writes:

> Juergen Boemmels <[EMAIL PROTECTED]> wrote:
> > Hi,
> 
> > the latest changes of HASH in src/hash.c makes t/src/hash.t fail
> > badly.
> 
> Oops, sorry (but at least it isn't the only broken test currently :)

I committed a partial fix. Now the tests are at least compiling.

> > But I still have one problem: hash_put and hash_get are not
> > symmetric. hash_put puts a void *value, but hash_get returns a
> > HASHBUCKET. This looks wrong to me.
> 
> When returning the value directly, we couldn't have NULL value's - or
> better NULL values and no entry at all would have the same return
> result.

Yes this is a problem. I did a little research how other libraries
solve this problem. Oh man, there are many of them. Far the most
libraries return the value directly [1], some of them use a function
to check if the key exists and set the value part as a side effect [2]
and a third group uses an approach were creation is a side effect of
lookup (sometimes controlled with a flag) and always return an
key/value pair [3]. Glib for example use approaches [1] and [2].

Our current approach looks like a mixture of all these 3 cases.

>From the principle of least surprise, I suggest to let hash_get return
a value pointer directly and have the ambiguity of NULL value and no
entry, and have a hash_get_bucket which returns a pointer to the
bucket.

void * hash_get(Interp * interpreter, HASH *hash, void *key);
HASHBUCKET * hash_get_bucket(Interp * interpreter, HASH *hash, void *key);

Some other note. Didn't we decided some time ago to use only ALLCAPS
types in cases were they are abbreviations. So the name would better
be Hash and HashBucket.

> Additionally the returned bucket has the key inside, which could be
> useful.

In cases where two keys compare equal but are not equal bitwise this
is indeed nice.

bye
boe

[1]
http://oss.software.ibm.com/cvs/icu/icu/source/common/uhash.h?rev=1.24
http://developer.gnome.org/doc/API/2.0/glib/glib-Hash-Tables.html 
http://apr.apache.org/docs/apr/group__apr__hash.html
http://www.w3.org/Library/src/HTHash.html
http://mission.base.com/peter/source/pbl/doc/
http://judy.sourceforge.net/JudySL_3x.htm
http://www.ipd.bth.se/ska/sim_home/libghthash_mk2_doc/ght__hash__table_8h.html
http://dodgysoftware.net/ht/
http://chilli.degnet.de/~e_decker/hashtable/

[2]
http://developer.gnome.org/doc/API/2.0/glib/glib-Hash-Tables.html 
http://www-2.cs.cmu.edu/~bwolen/fmcad98/packages/tiger/tgrlib/utilhash.html
http://www.ohse.de/uwe/strhash/libstrhash.html
http://www.stalphonsos.com/~attila/libgram/docs/hash_8h.html

[3]
http://www.gnu.org/manual/bfd-2.9.1/html_node/bfd_43.html
http://www.gnu.org/software/libc/manual/html_node/Hash-Search-Function.html
http://www.tcl.tk/man/tcl8.2.3/TclLib/Hash.htm
-- 
Juergen Boemmels                        [EMAIL PROTECTED]
Fachbereich Physik                      Tel: ++49-(0)631-205-2817
Universitaet Kaiserslautern             Fax: ++49-(0)631-205-3906
PGP Key fingerprint = 9F 56 54 3D 45 C1 32 6F  23 F6 C7 2F 85 93 DD 47

Reply via email to