caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Oleg <oleg_inconnu@myrealbox.com>
To: Brian Hurt <brian.hurt@qlogic.com>,
	Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Probably FAQ: Why is list-append (list :: elem) so expensive?
Date: Wed, 25 Sep 2002 11:42:08 -0400	[thread overview]
Message-ID: <200209251541.LAA26761@dewberry.cc.columbia.edu> (raw)
In-Reply-To: <Pine.LNX.4.33.0209250958520.1974-100000@eagle.ancor.com>

On Wednesday 25 September 2002 11:33 am, Brian Hurt wrote:
> I get that the cost of list concatenation is proportional to the length of
> the first list.  So (elem :: list) is O(1) no matter what the length of
> list is.  But (list :: elem) is O(n), with n being the length of the list.
>
> Why doesn't Ocaml keep a pointer to the last element of the list, as well
> as the first element?  This would make all list concatenation (in
> situations where you don't have to duplicate a list) an O(1) operation.  
> At the cost of increasing the size of a list object.

let a = [1; 2; 3; 4; 5; 6];;
let b = 0 :: a;;

the elements of "a" are _shared_. Now your suggestion regarding "efficient 
append" can not be used to append anything to one list, but not the other.

HTH
Oleg
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2002-09-25 15:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-25 15:33 Brian Hurt
2002-09-25 15:39 ` Noel Welsh
2002-09-25 15:42 ` Oleg [this message]
2002-09-25 16:17 ` Markus Mottl
2002-09-25 18:44   ` Brian Hurt
2002-09-25 19:22     ` Markus Mottl
2002-09-26  7:10     ` Florian Hars
2002-09-26 14:44 ` Kontra, Gergely

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=200209251541.LAA26761@dewberry.cc.columbia.edu \
    --to=oleg_inconnu@myrealbox.com \
    --cc=brian.hurt@qlogic.com \
    --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).