caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Loup Vaillant" <loup.vaillant@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Vec: a functional implementation of extensible arrays
Date: Fri, 20 Jul 2007 09:35:39 +0200	[thread overview]
Message-ID: <6f9f8f4a0707200035l4351c6b6g585b4edd2c51faa6@mail.gmail.com> (raw)
In-Reply-To: <28fa90930707190959g66cb2e6wc7a446af2a6dfb72@mail.gmail.com>

2007/7/19, Luca de Alfaro <luca@dealfaro.org>:
>
> For get/set, the worst case and the average case are both logarithmic: it's
> a balanced tree (if you are lucky, you can find your answer at the root!

I did. :)

> ;-).  I am open to new ideas.  In part, I wanted a simple data structure
> (easier to extend, among other things).  Also, I use Set, Map, etc, quite
> often, and those are also balanced trees: I thought that if I can live with
> those, I can probably live with Vec as well.

So can I. Your current implementation is already very attractive, and
looks very usable. For the new idea, have you thought of making (or
specifying) syntactic sugar to use your array?

About improving performance, here is my guess : there is no way to
lower the bounds on get and set. However, the average cost of insert
may already be O(1), provided you use your array the same way you
would use an imperative version of it (more accurately, not inserting
an element to an old version of your array). The same may be true for
remove.

Therefore, if I guess right, to take advantage of persistence AND have
insert perform in O(1) average, you would have to use (and pay for)
lazy evaluation. How, I don't know (yet).

(Note that I have stolen this idea from Okasaki's book)

> For an iterator, the worst case is as follows, where n is the size of the
> Vec:
>
> if you iterate on the whole Vec, then O(n)
> if you iterate over m elements (you can iterate on a subrange), then O(m +
> log n).
> That's why I have iterators: you can also iterate via a for loop, using get
> to access the elements, but then the time becomes O(n log n) for the first
> case, and O(m log n) for the second case.

That is why I wondered if lazy evaluation was worth the trouble at all
: most of the time, we iterate rather than insert or remove elements.
I only regret the absence of filter. Is there a way to obtain a
efficient filter? (Well, if my guess above is right, a naive
implementation of filter would already be quite efficient...)

Regards,
Loup


  reply	other threads:[~2007-07-20  7:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-18 17:32 Luca de Alfaro
2007-07-19  7:45 ` [Caml-list] " Loup Vaillant
2007-07-19  8:17   ` Hugo Ferreira
2007-07-19 16:51     ` Luca de Alfaro
2007-07-19 17:13     ` Luca de Alfaro
2007-07-19 16:59   ` Luca de Alfaro
2007-07-20  7:35     ` Loup Vaillant [this message]
2007-07-20  8:14       ` Jon Harrop
2007-07-20 15:42         ` Luca de Alfaro
2007-07-20 16:45           ` Brian Hurt

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=6f9f8f4a0707200035l4351c6b6g585b4edd2c51faa6@mail.gmail.com \
    --to=loup.vaillant@gmail.com \
    --cc=caml-list@yquem.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).