From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA23193; Thu, 15 Aug 2002 00:17:00 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA22780 for ; Thu, 15 Aug 2002 00:17:00 +0200 (MET DST) Received: from mail1.tpgi.com.au (mail.tpgi.com.au [203.12.160.57]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7EMGv513010 for ; Thu, 15 Aug 2002 00:16:58 +0200 (MET DST) Received: from ozemail.com.au (syd-ts13-2600-070.tpgi.com.au [203.213.81.70]) (authenticated (0 bits)) by mail1.tpgi.com.au (8.11.6/8.11.6) with ESMTP id g7EMGmw09950; Thu, 15 Aug 2002 08:16:49 +1000 Message-ID: <3D5AD6CF.7030603@ozemail.com.au> Date: Thu, 15 Aug 2002 08:16:47 +1000 From: John Max Skaller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: yann@lrde.epita.fr CC: caml-list@inria.fr Subject: Re: [Caml-list] sorting Hashtbl.t References: <200208120108.VAA16373@dewberry.cc.columbia.edu> <20020812101020.GV6002@barcelona.lrde.epita.fr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > From an algorithmic point of view, there is no way to sort an > hash table since there is no order attached to items. Ocaml has a polymorphic comparison function (which works on all non-cyclic data structures). Therefore, any collection of (non-cyclic) data elements can be sorted, and the request actually makes sense. It is also something I wish to do often. However, I would ask for different function(s): Hastbl.to_list Hashtbl.to_lista Hashtbl.to_sorted_list compar Hashtbl.to_sorted_lista compar which creates association list(s), the standard version(s) producing unique keys, and the 'a' version(s) an entry for every element in the hashtable, with duplicate keys in reverse order of entry into the table. (so a sequential search finds the same value that a Hashtbl.find would). Of course I can write this function myself, it's just inconvenient to have to keep doing so. By the way: how can I make a hashtable that uses addresses as keys? I.e. computes the hash value on an address, not on a value. (for collecting terms). Hmmm. What happens if the key is a reference? (or otherwise contains a mutable value?) -- John Max Skaller, mailto:skaller@ozemail.com.au snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners