[mercury-users] Inst problem with hash tables

Ralph Becket rafe at csse.unimelb.edu.au
Mon Sep 22 12:27:07 AEST 2008


Paul Bone, Saturday, 20 September 2008:
> On Fri, Sep 19, 2008 at 05:32:09PM +0200, andrea bini wrote:
> > Hi all,
> > I have a problem with insts when reading from a file a hash table, created using new_default function from hash_table.m, previously saved with io.write_binary. Maybe is a silly question but when I read the hash table using io.read_binary the instantiation state of it is ground and is not compatible with inst hash_table used by all the predicates and functions in hash_table.m. Indeed I cannot call any predicate on it.
> > 
> > How can I use mercury libraries to save an hash_table on a file and use it again after it has been read?
> > 
> > Thanks a lot!
> 
> Hi Andrea,
> 
> The simplest way I can imagine to do this is to use the to_assoc_list
> and from_assoc_list functions defined in the hash_table module, and
> writing the associated list out to disk.  You will need to provide the
> hashing function to from_assoc_list so it can recompute the hashes and
> fill the table.

No, don't do that!  For large hash tables it would be a disaster.

What you need is something like this:

:- func unsafe_promise_unique_hash_table(hash_table(K, V)::in) = 
	(hash_table(K, V)::hash_table_uo) is det.

:- pragma foreign_proc("C",
	unsafe_promise_unique_hash_table(HT0::in) = (HT::hash_table_uo),
	[promise_pure, will_not_call_mercury],
"
	HT = HT0;
").

I'm just testing a version of this which I've added to the hash_table
module.  I'll let you know once it's been reviewed.

Cheers,
-- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list