users-prolog
[Top][All Lists]
Advanced

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

AW: function hash for prolog terms?


From: ibl
Subject: AW: function hash for prolog terms?
Date: Tue, 10 Feb 2004 13:47:29 +0100


> -----Ursprüngliche Nachricht-----
> Von: address@hidden
> [mailto:address@hidden Auftrag von
> Daniel Jiménez Gentil
> Gesendet: Dienstag, 10. Februar 2004 12:18
> An: address@hidden
> Betreff: function hash for prolog terms?
>
>
> Hello,
>
> 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 the
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 this
task.


HTH
Regards
Ingo

>
> _________________________________________________________________
> Deja tu CV y recibe ofertas personalizadas de trabajo en tu buzón.
> http://www.msn.es/Empleo/
>
>
>
> _______________________________________________
> Users-prolog mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/users-prolog





reply via email to

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