caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Francois Berenger <berenger@riken.jp>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Fwd: interval trees
Date: Thu, 16 Feb 2012 11:48:07 +0900	[thread overview]
Message-ID: <4F3C6E67.6080109@riken.jp> (raw)
In-Reply-To: <CAL-jcAnOxmW0OE7j+5g0y17URnMAYz8MKszZH3MXVcGo_5FpVA@mail.gmail.com>

On 02/16/2012 02:22 AM, Edgar Friendly wrote:
> I struggled with this too, but if you read the wikipedia page
> http://en.wikipedia.org/wiki/Interval_tree, he's implemented a centered
> interval tree.  Yes, there's a lot of complications needed to insert and
> remove, but what he's done works for static interval trees.
>
> His lookup function is `int -> interval list`

Precisely, it is:
type: interval_tree -> float -> interval list

 > , not `int -> bool`, so he
> must keep all the intervals that overlap the center point so he can
> return them.  It's useful to have them sorted by left endpoint as well
> as right endpoint.  I might have used arrays for them instead of lists
> so that binary search is doable,

That would be a nice optimization for queries indeed.

At the moment, I'm more concerned about the program blowing up
during tree construction.

Regards,
F.

 > but if they're small, it doesn't matter
> much.
>
> E.
>
> On Wed, Feb 15, 2012 at 10:21 AM, Goswin von Brederlow
> <goswin-v-b@web.de <mailto:goswin-v-b@web.de>> wrote:
>
>     Francois Berenger <berenger@riken.jp <mailto:berenger@riken.jp>> writes:
>
>      > Hello,
>      >
>      > I did a naive implementation of interval trees for float intervals.
>      >
>      > It is available here:
>      > https://github.com/HappyCrow/interval-tree
>      >
>      > I wonder if it is possible to construct the trees in a tail recursive
>      > fashion. Maybe I knew how to do this when I was still at university.
>      >
>      > Regards,
>      > Francois.
>
>     | Node of
>        (* x_mid left_list right_list left_tree right_tree *)
>           float * interval list * interval list * interval_tree *
>     interval_tree
>
>     Why interval list? You only need a single interval in leafes and none in
>     other nodes (although it can help to store min and max in each node).
>
>     You are also missing insert and remove operations, which is the actually
>     hard part in this. Inserting an interval might require merging the
>     rightmost interval left of the root and the leftmost interval right of
>     the root. So you would have 2 removals and one insertion of a combined
>     interval, which complicates balancing the whole thing efficiently.
>
>     That is the part I'm struggling with.
>
>     MfG
>             Goswin
>
>     --
>     Caml-list mailing list.  Subscription management and archives:
>     https://sympa-roc.inria.fr/wws/info/caml-list
>     Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>     Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>


  reply	other threads:[~2012-02-16  2:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10  1:07 Francois Berenger
2012-02-10 18:29 ` Richard W.M. Jones
2012-02-11 17:38   ` Goswin von Brederlow
2012-02-11 17:49     ` Eliot Handelman
2012-02-13  9:13       ` Sebastien Ferre
2012-02-15  1:28         ` Francois Berenger
2012-02-15 15:21           ` Goswin von Brederlow
2012-02-15 17:22             ` Edgar Friendly
2012-02-16  2:48               ` Francois Berenger [this message]
2012-02-16  2:32             ` Francois Berenger
2012-02-16  2:42               ` Francois Berenger
2012-02-16  8:34                 ` Goswin von Brederlow
2012-02-16 12:20                   ` John Carr
2012-02-16 10:21                 ` Gabriel Scherer
2012-02-17  0:59                   ` Francois Berenger
2012-02-17  8:11                     ` Christophe Raffalli
2012-02-11 20:49     ` Edgar Friendly
2012-02-11 23:54       ` Philippe Veber
2012-02-11 10:54 ` Philippe Veber
2012-02-11 17:33   ` Goswin von Brederlow

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=4F3C6E67.6080109@riken.jp \
    --to=berenger@riken.jp \
    --cc=caml-list@inria.fr \
    /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).