From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: Will guile support R7RS terminating "equal?" in the presence of cycle? Date: Sat, 08 Sep 2012 23:41:26 -0400 Message-ID: <504C0FE6.4030805@netris.org> References: <877gscbhsd.fsf@Kagami.home> <871uikoz7k.fsf@gnu.org> <504B78B5.2050203@netris.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1347162116 30922 80.91.229.3 (9 Sep 2012 03:41:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Sep 2012 03:41:56 +0000 (UTC) Cc: =?ISO-8859-1?Q?Ludovic_Court=E8s?= , guile-devel@gnu.org To: Alex Shinn Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Sep 09 05:41:58 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TAYPF-0004jT-Je for guile-devel@m.gmane.org; Sun, 09 Sep 2012 05:41:57 +0200 Original-Received: from localhost ([::1]:57201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAYPC-0004km-1T for guile-devel@m.gmane.org; Sat, 08 Sep 2012 23:41:54 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:34355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAYP8-0004kh-Fj for guile-devel@gnu.org; Sat, 08 Sep 2012 23:41:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TAYP7-0004lO-CX for guile-devel@gnu.org; Sat, 08 Sep 2012 23:41:50 -0400 Original-Received: from world.peace.net ([96.39.62.75]:37951) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAYP5-0004ky-KN; Sat, 08 Sep 2012 23:41:47 -0400 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=[192.168.1.176]) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1TAYOm-0003RV-HE; Sat, 08 Sep 2012 23:41:28 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.6esrpre) Gecko/20120817 Icedove/10.0.6 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:14870 Archived-At: On 09/08/2012 09:35 PM, Alex Shinn wrote: > On Sun, Sep 9, 2012 at 2:00 AM, Stefan Israelsson Tampe > wrote: >> You are right! That will only work for one thread! >> >> Remain to see how much the overhed there is to linearize the search and >> use tourtoues - hare, should be much less overhead then using a map to >> mark the objects though! > > See http://srfi.schemers.org/srfi-85/srfi-85.html > for a common implementation approach. > > The basic idea there is just to run equal? normally, > but keep a counter of how many objects have been > compared. If the count gets too high, there is a > decent chance you have a cycle, and only then do > you switch to a more expensive approach. > > You could of course use a modified hare and tortoise > with the same goal of just detecting when a cycle > has occurred and switching algorithms. You only > need to do this on one of the data structures, since > if either is non-cyclic equal? will terminate naturally. > This would be slightly more overhead than a counter, > and probably require heap allocation to keep the > search path in memory, but it removes the need to > choose a good limit. Small cycles will still be detected > right away, and very long straight lists won't switch > to the expensive algorithm. Another option is to use the method described in "Efficient Nondestructive Equality Checking for Trees and Graphs" by Adams and Dybvig. http://www.cs.indiana.edu/~dyb/pubs/equal.pdf Mark