From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 679EFBB91 for ; Sat, 23 Jul 2005 21:59:54 +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 j6NJxrwj015566 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Sat, 23 Jul 2005 21:59:54 +0200 Received: from localhost (unknown [127.0.0.1]) by mail.physik.uni-muenchen.de (Postfix) with ESMTP id 8391F2000D; Sat, 23 Jul 2005 21:59:53 +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 04757-01; Sat, 23 Jul 2005 21:59:51 +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 DCBA02000B; Sat, 23 Jul 2005 21:59:51 +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 33A3926E87; Sat, 23 Jul 2005 21:59:51 +0200 (CEST) Received: by katrin.cip.physik.uni-muenchen.de (Postfix, from userid 3092) id 0288716BBA; Sat, 23 Jul 2005 21:59:50 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by katrin.cip.physik.uni-muenchen.de (Postfix) with ESMTP id F166722135; Sat, 23 Jul 2005 21:59:50 +0200 (CEST) Date: Sat, 23 Jul 2005 21:59:50 +0200 (CEST) From: Thomas Fischbacher To: Stephane Glondu Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] How to do this properly with OCaml? In-Reply-To: <200507231250.45778.Stephane.Glondu@crans.org> Message-ID: References: <200507231218.13166.Stephane.Glondu@crans.org> <200507231250.45778.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 42E2A1B9.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 heap:01 heap:01 garbage:01 bookkeeping:01 2005,:98 cip:98 cip:98 lambda:01 lambda:01 wrote:01 underlying:01 debian:02 physik:02 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: > > 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, > > When you want to "remove" an element, you can put another (random) value > from the same array at its place so that it can be garbage collected. If > the remaining heap is empty (i.e. there is no other value to pick), you > replace the Fill a with Empty n. I think that this will not work. If I duplicate entries to fill up holes, and later on remove a legitimate entry whose duplicates fill holes from the heap, I have to introduce extra bookkeeping so that the other placeholder copies of that entry are replaced as well - otherwise it could not be reclaimed by GC. > > and (2) that removing a single > > element from the heap does not require copying the underlying Array? > > This is a matter of algorithmics, isn't it? To some extent, it is a matter of the type system getting in the way of algorithmics, I fear. -- 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)