[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: AW: function hash for prolog terms?

From: Daniel Jimenez Gentil
Subject: RE: AW: function hash for prolog terms?
Date: Mon, 16 Feb 2004 16:57:23 +0100

Thank you very much for your help, but I have a problem when the prolog
term is a variable not unified.

For example:

 :-isinto(X,1,5), hash_term(X,N).

the variable X is not unified, and it returns me an error.

Could you help me?

-----Mensaje original-----
De: Daniel Diaz [mailto:address@hidden 
Enviado el: miercoles, 11 de febrero de 2004 23:43
Para: ibl
CC: Daniel Jimenez Gentil; address@hidden
Asunto: Re: AW: function hash for prolog terms?


You'll find as an attachment another Prolog solution to compute a hash 
code from a term.

>>I am working using the interface of GNU-Prolog for C.
>>I need a function that returns me an unique number for each
>>prolog term. Up
>>to now I am using the following one
>>int hash(PlTerm termino_prolog) {
>>  return abs (Rd_Code (termino_prolog));
>>But there are cases in those that it stops oneself prolog term it
>>returns me
>>different values.
>>Thank you for your help.
> Daniel,
> while I don't know about the semantics of "Rd_Code", I suspect, that
> returned information might be not unique to a specific term.
> For a true hash you need a guaranteed unique function however.
> So I would suggest, that you implement it as follows:
> term_hash(Term,Hash) :-
>       write_canonical_to_atom(CanonicalAtom,Term),
>       my_md5_digest(CanonicalAtom,Hash).
> Of course, this would involve an implementation of "my_md5_digest".
> You can easily wrap a "stock" MD5 function, written in C, to perform
> task.
> Regards
> Ingo

reply via email to

[Prev in Thread] Current Thread [Next in Thread]