takanobu> I think it's the best and cool to use some encoding
 takanobu> algorythms for those two elements(create hash value and key
 takanobu> predication), but I can't find any libraries such as md5
 takanobu> and so on.

You can compute SHA-1 hashes, which serve a similar purpose to MD5,
using the SHA-1-Digester class.  But normally no one uses a hashing
algorithm this complicated for hash tables.  HashTable-of only want a
32-bit int hash, not a full 160-bit very complicated and
cryptographically strong hash like SHA-1.

Usually you use a much simpler and faster function.  For example, if
you had a class MyClass with two String fields, and you wanted to map
those to ints, your hash table might look like this:

{define-proc public {MyClass-hash c:MyClass}:int
    {return {value-hash c.string1} * 37 + {value-hash c.string2}}

{define-proc public {MyClass-equal c1:MyClass, c2:MyClass}:bool
    {return c1.string1 == c2.string1 and c1.string2 == c2.string2}

{let public constant MyClassHashTable:Type =
    {HashTable-of MyClass, int,
        key-hash-proc = MyClass-hash,
        key-equality-proc = MyClass-equal

In general you can use "value-hash" to access Curl's default hash
function for something.  For most objects, this hash is just based on
its identity (i.e. their address).  But for a few classes that
override what == does, such as String, it actually looks at the
contents of the object (for String it mathematically combines the
characters of the String in a certain way to produce an int).

What's important when choosing a hash function is that if two objects
are equal, they must have the same hash.  It is OK (and unavoidable)
for two objects that are not equal to have the same hash (a "hash
collision").  The less often this happens, the better a hash function
you have chosen.


To unsubscribe from this list, send a mail to:
To contact a human list administrator, send a mail to:
To recieve a list of other options for this list, send a mail to:

Reply via email to