From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id C8D6BBB91 for ; Sat, 23 Jul 2005 21:35:16 +0200 (CEST) Received: from mail.physik.uni-muenchen.de (mail.physik.uni-muenchen.de [192.54.42.129]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j6NJZG8q014053 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Sat, 23 Jul 2005 21:35:16 +0200 Received: from localhost (unknown [127.0.0.1]) by mail.physik.uni-muenchen.de (Postfix) with ESMTP id 0CD5320007; Sat, 23 Jul 2005 21:35:16 +0200 (CEST) Received: from mail.physik.uni-muenchen.de ([127.0.0.1]) by localhost (mail.physik.uni-muenchen.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 02419-01-19; Sat, 23 Jul 2005 21:35:14 +0200 (CEST) Received: from mailhost.cip.physik.uni-muenchen.de (kaiser.cip.physik.uni-muenchen.de [141.84.136.1]) by mail.physik.uni-muenchen.de (Postfix) with ESMTP id 44F4320004; Sat, 23 Jul 2005 21:35:14 +0200 (CEST) Received: from katrin.cip.physik.uni-muenchen.de (katrin.cip.physik.uni-muenchen.de [141.84.136.12]) by mailhost.cip.physik.uni-muenchen.de (Postfix) with ESMTP id 8E55B26E87; Sat, 23 Jul 2005 21:35:13 +0200 (CEST) Received: by katrin.cip.physik.uni-muenchen.de (Postfix, from userid 3092) id 674D416BBA; Sat, 23 Jul 2005 21:35:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by katrin.cip.physik.uni-muenchen.de (Postfix) with ESMTP id 6268C22135; Sat, 23 Jul 2005 21:35:13 +0200 (CEST) Date: Sat, 23 Jul 2005 21:35:13 +0200 (CEST) From: Thomas Fischbacher To: Stephane Glondu Cc: caml-list@yquem.inria.fr, Berke Durak Subject: Re: [Caml-list] How to do this properly with OCaml? In-Reply-To: <200507231218.13166.Stephane.Glondu@crans.org> Message-ID: References: <200507230936.47352.Stephane.Glondu@crans.org> <20050723182709.GA4076@ara.zapto.org> <200507231218.13166.Stephane.Glondu@crans.org> X-BOFH: Daemons did it MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: amavisd-new at physik.uni-muenchen.de X-Miltered: at concorde with ID 42E29BF4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 berke:01 durak:01 heap:01 heap:01 sig:01 val:01 val:01 struct:01 2005,:98 cip:98 cip:98 lambda:01 lambda:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_FAIL autolearn=disabled version=3.0.3 On Sat, 23 Jul 2005, Stephane Glondu wrote: > On Saturday 23 July 2005 11:27, Berke Durak wrote: > > That was my point. You could cleanly initialize your heap with that > > "any" value. > > I was thinking about sth you could adjust to your purpose: > > module type HEAP = sig > type 'a t > val create : int -> 'a t > val set : 'a t -> int -> 'a -> unit > val get : 'a t -> int -> 'a > end > > module Heap : HEAP = struct > type 'a cell = Fill of 'a array | Empty of int > type 'a t = 'a cell ref > > let create n = ref (Empty n) > > let set h i e = match !h with > Empty n -> h := Fill (Array.create n e) > | Fill a -> a.(i) <- e > > let get h n = match !h with > Empty _ -> raise Not_found > | Fill a -> a.(n) > end > > No Obj.magic here. Does this suit you? This seems to be equivalent to the idea of using an array option, which I mentioned earlier. Problems: What if I have operations that add and remove elements on the heap in random order (so that the heap sometimes has to shrink), and I want (1) that every element which was removed from the heap and is otherwise inaccessible can be reclaimed by GC, and (2) that removing a single element from the heap does not require copying the underlying Array? -- regards, tf@cip.physik.uni-muenchen.de (o_ Thomas Fischbacher - http://www.cip.physik.uni-muenchen.de/~tf //\ (lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y) V_/_ (if (= x 0) y (g g (- x 1) (* x y)))) n 1)) (Debian GNU)