unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Alex Shinn <alexshinn@gmail.com>
Cc: "Ludovic Courtès" <ludo@gnu.org>, guile-devel@gnu.org
Subject: Re: Will guile support R7RS terminating "equal?" in the presence of cycle?
Date: Sat, 08 Sep 2012 23:41:26 -0400	[thread overview]
Message-ID: <504C0FE6.4030805@netris.org> (raw)
In-Reply-To: <CAMMPzYNrvO5A4L=zh6WcpijHUt66ZKGcr5ceAczw9+UaTKjAKQ@mail.gmail.com>

On 09/08/2012 09:35 PM, Alex Shinn wrote:
> On Sun, Sep 9, 2012 at 2:00 AM, Stefan Israelsson Tampe
> <stefan.itampe@gmail.com>  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



  reply	other threads:[~2012-09-09  3:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-01  3:08 Will guile support R7RS terminating "equal?" in the presence of cycle? David A. Wheeler
2012-09-01 13:30 ` Ludovic Courtès
2012-09-02 14:50 ` Ian Price
2012-09-02 15:17   ` David A. Wheeler
2012-09-02 18:43     ` Stefan Israelsson Tampe
2012-09-02 22:07       ` Ludovic Courtès
2012-09-03 13:55         ` Stefan Israelsson Tampe
2012-09-08 16:56           ` Mark H Weaver
2012-09-08 17:00             ` Stefan Israelsson Tampe
2012-09-09  1:35               ` Alex Shinn
2012-09-09  3:41                 ` Mark H Weaver [this message]
2012-09-10  9:21                   ` William ML Leslie
2012-09-09 17:14                 ` Stefan Israelsson Tampe
2012-09-03 17:56         ` Stefan Israelsson Tampe
2012-09-03 21:12           ` Ludovic Courtès
2012-09-04  5:35             ` Stefan Israelsson Tampe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=504C0FE6.4030805@netris.org \
    --to=mhw@netris.org \
    --cc=alexshinn@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).