caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nick Lucaroni <nicholas.r.lucaroni@gmail.com>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: Jean-Baptiste Jeannin <jeannin@cs.cornell.edu>,
	Edgar Friendly <thelema314@gmail.com>,
	 "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Hash function: complexity and circular structures
Date: Fri, 18 Jan 2013 15:11:13 -0500	[thread overview]
Message-ID: <CAADdkeKekiKqpLXpNKk9Eo3AhGSdnH1aMq58xsSc+60gE5_5VQ@mail.gmail.com> (raw)
In-Reply-To: <CAPFanBGqAdTe2uujQGtxYVrj-W5Y_Ez0Xu0_fgrY2OttekYzgw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1639 bytes --]

Calling find from the values ones and ones2 work because the compare
function does a physical comparison before structural comparison and both
of these values are derived from the same list you used as the key. So as
the structural comparison affirms the physical differences between the two
types, a physical comparison ends the loop of the recursive structure. And
this is also why looking up ones3 will result in an infinite loop of
comparisons.

You can implement your own comparison algorithm in the equal function of
the Hashtbl.HashedType module for the Hashtbl.Make functor if you must
proceed with cyclic lists in this fashion as keys. But as Gabriel has said,
you should look at a different data-structures.


On Fri, Jan 18, 2013 at 1:27 PM, Gabriel Scherer
<gabriel.scherer@gmail.com>wrote:

> A blunt point of view: comparing implicitly circular structures is a
> sure road to hell, and you should use an explicit representation of
> circularity (eg. with a element that just means "nothing here, you
> should rewind to the other side") that will not blow up at each
> occasion it gets -- and is generally much more flexible.
>
> On Fri, Jan 18, 2013 at 6:46 PM, Jean-Baptiste Jeannin
> <jeannin@cs.cornell.edu> wrote:
> >
> > I would be curious to know if this is by design (it is supposed not to
> > work), or if it is a problem with the implementation of compare, or of
> > Hashtbl.find. In particular, if it is by design, why have updated the
> hash
> > function to support circular lists?
> > I am also now stuck on creating an (efficient) hashtable supporting
> circular
> > data structures as keys. Any idea on this?
>

[-- Attachment #2: Type: text/html, Size: 2142 bytes --]

      reply	other threads:[~2013-01-18 20:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-17 15:35 Jean-Baptiste Jeannin
2013-01-17 15:46 ` Nicholas Lucaroni
2013-01-17 16:41   ` Edgar Friendly
2013-01-17 17:05     ` Nicholas Lucaroni
2013-01-18 17:46       ` Jean-Baptiste Jeannin
2013-01-18 18:27         ` Gabriel Scherer
2013-01-18 20:11           ` Nick Lucaroni [this message]

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

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

  git send-email \
    --in-reply-to=CAADdkeKekiKqpLXpNKk9Eo3AhGSdnH1aMq58xsSc+60gE5_5VQ@mail.gmail.com \
    --to=nicholas.r.lucaroni@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=gabriel.scherer@gmail.com \
    --cc=jeannin@cs.cornell.edu \
    --cc=thelema314@gmail.com \
    /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 NNTP newsgroup(s).