From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 5ECDCBBCA for ; Mon, 12 May 2008 00:45:24 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvcCACETJ0jRVcivc2dsb2JhbACSDAEMAwQECQ+Se4QC X-IronPort-AV: E=Sophos;i="4.27,470,1204498800"; d="scan'208";a="26058856" Received: from wf-out-1314.google.com ([209.85.200.175]) by mail4-smtp-sop.national.inria.fr with ESMTP; 12 May 2008 00:45:23 +0200 Received: by wf-out-1314.google.com with SMTP id 28so2648051wfa.15 for ; Sun, 11 May 2008 15:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=TxDiatby+GbbpAO46xop5DZ1TgE1C0HUQWvbUSu2kiY=; b=ZK0ZNau+F7DUJDVWecGj0xkpvCATEKxv+KUos4ns6dtHqra0fRji6VX4X2DCbTIMTd77T/VTxbsMsaZ5QyzFY57gCVysWq7rJz3oIjS9WJNhVNsRTI7Ip5ij3CvooKVodccQZ3vxA24hZGYcL/GFFWqGxqIlknZXnwkuQB0vCSM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=PCFpZm6kDs6SoZGFMgYRs9I7PgKGmVhEg21OhMizw4c34PP0YRowwWEATkz53TAHrZIfBhsbPn488s62bvPeVzF0CrYKq9Hy4hy2HiYhJXxYTvbSkd64J8ZZV6druwX0rUHzgJJZkMJzxngaEBILrcUo0fGIdrXQ5eqy5n3t9T0= Received: by 10.142.242.8 with SMTP id p8mr2980919wfh.24.1210545921603; Sun, 11 May 2008 15:45:21 -0700 (PDT) Received: by 10.142.115.3 with HTTP; Sun, 11 May 2008 15:45:21 -0700 (PDT) Message-ID: <9d3ec8300805111545y34eccd27mb00187f23e779610@mail.gmail.com> Date: Sun, 11 May 2008 23:45:21 +0100 From: "Till Varoquaux" To: "Florent Monnier" Subject: Re: [Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table? Cc: caml-list@yquem.inria.fr In-Reply-To: <200805111710.06994.fmonnier@linux-nantes.fr.eu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <87tzh5kxhl.fsf@linux-france.org> <200805111642.14164.fmonnier@linux-nantes.fr.eu.org> <9d3ec8300805110746s3b4ad089p9d6572a491403384@mail.gmail.com> <200805111710.06994.fmonnier@linux-nantes.fr.eu.org> X-Spam: no; 0.00; hashtbl:01 hashtbl:01 iter:01 hash:01 iter:01 ocaml's:01 arrays:01 associative:01 iterating:01 bindings:01 unspecified:01 beginner's:01 ocaml:01 bug:01 beginners:01 Indeed. The answer you got was, however, based on the actual implementation not on the documentation. This means that, at some point, this might evolve and not be valid anymore. If you want to be on the safe side you should do a fold instead of an iter and collect all of the items to remove and then remove them in a second pass. The performance hit shouldn't be as bad as you could expect (ie: I wouldn't bother unless performance really is critical). I see it as very unlikely that ocaml's implementation of hashtbl would evolve in such a way that it would break any code removing previously visited items during a traversal. Your call. Till On 5/11/08, Florent Monnier wrote: >> Hatables are arrays of associative lists. When you are iterating over >> them removing any element you have already visited should be ok. >> Removing elements you haven't visited yet could cause you to encounter >> them anyhow. > > which means that it is dependent to the order in which the content is > itered, > while the manual says : > "The order in which the bindings are passed to f is unspecified." > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- http://till-varoquaux.blogspot.com/