caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Eray Ozkural <exa@kablonet.com.tr>
To: Lauri Alanko <la@iki.fi>, caml-list@inria.fr
Subject: Re: [Caml-list] Efficiency of 'a list
Date: Sun, 4 May 2003 01:03:03 +0300	[thread overview]
Message-ID: <200305040103.04121.exa@kablonet.com.tr> (raw)
In-Reply-To: <20030503211343.GC700@la.iki.fi>

On Sunday 04 May 2003 00:13, Lauri Alanko wrote:
> It's easy to commit performance genocide with any data structure if you
> use it for things for which it is not efficient. Singly linked immutable
> lists have some nice characteristics: O(1) for cons, head and tail, all
> purely functionally so you can safely share structure between multiple
> lists. For example, lists are perfect for representing several alternate
> paths in a path search.

OK. So as Mattias said it is the same thing as LISP lists.

>
> For the second line I think you mean either
> a.(i) <- x :: a.(i)
> or
> a.(i) <- [x] @ a.(i)
>

*blush* yes I meant the former.

> Both of these are O(1). The first allocates a single cell, the second
> theoretically two (one of which is discarded immediately) unless the
> compiler is smart.
>
> If you really need to add stuff to both ends of a data structure,
> ocaml's primitive lists aren't the thing. You might consider some sort
> of a deque.
>

Hmm. I'm just trying to understand if ocaml lists would be adequate for 
representing adjacency lists. I thought it'd be easier for programmers to 
deal with it than something else that I might write. [And since such a thing 
is likely to pervade my library I should decide early :) ]

I also wanted to learn if the compiler went to any length in optimization when 
it can determine that a mutable field is being overwritten like in a.(i) <- 
a.(i) @ [x]  --- Of course here it is obvious that there is no reference 
count associated with objects, and another structure might be sharing the 
list, etc. so there is probably no room for optimization.

BTW, we don't have imperative lists in the standard library...I wonder if 
something like a really simple doubly linked list or non-shared singly linked 
list would be worthwhile (wasn't that an exercise in ocaml book?)

> However, the copying garbage collector is quite likely to enhance
> locality of lists when it runs. Someone more knowledgeable can probably
> tell more on this.

I understand that garbage collectors are pretty smart nowadays. Maybe it might 
be attempting to compact memory in a way.

Happy hacking,

-- 
Eray Ozkural (exa) <erayo@cs.bilkent.edu.tr>
Comp. Sci. Dept., Bilkent University, Ankara  KDE Project: http://www.kde.org
www: http://www.cs.bilkent.edu.tr/~erayo  Malfunction: http://mp3.com/ariza
GPG public key fingerprint: 360C 852F 88B0 A745 F31B  EA0F 7C07 AE16 874D 539C

-------------------
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


      reply	other threads:[~2003-05-03 22:03 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-02 19:27 Eray Ozkural
2003-05-03  5:43 ` Mattias Waldau
2003-05-03  8:16   ` Ville-Pertti Keinonen
2003-05-03 14:12   ` Vitaly Lugovsky
2003-05-03 18:43     ` Mattias Waldau
2003-05-03 20:01       ` Eray Ozkural
2003-05-03 23:17       ` Eray Ozkural
2003-05-04  2:08       ` cashin
2003-05-04  4:08         ` alc
2003-05-04  5:32           ` Ed L Cashin
2003-05-04  6:46           ` [Caml-list] Two types of efficiency (Was Efficiency of 'a list) Mattias Waldau
2003-05-04  7:35             ` John Max Skaller
2003-05-04 11:52               ` Olivier Andrieu
2003-05-05 11:04                 ` John Max Skaller
2003-05-04 16:48               ` brogoff
2003-05-04  7:43             ` Ville-Pertti Keinonen
2003-05-04 12:50               ` Eray Ozkural
2003-05-04 12:48             ` Eray Ozkural
2003-05-05  7:31             ` Diego Olivier Fernandez Pons
2003-05-05 11:11               ` Mattias Waldau
2003-05-05 13:17                 ` John Max Skaller
2003-05-05 11:49               ` Eray Ozkural
2003-05-05 11:57               ` Yaron M. Minsky
2003-05-05 13:32                 ` John Max Skaller
2003-05-06  2:49                   ` Nicolas Cannasse
2003-05-06 12:30                     ` Diego Olivier Fernandez Pons
2003-05-07  2:05                       ` Nicolas Cannasse
2003-05-05 16:38                 ` Diego Olivier Fernandez Pons
2003-05-05 18:05                   ` Eray Ozkural
2003-05-06 13:28                     ` Diego Olivier Fernandez Pons
2003-05-13 11:35                   ` [Caml-list] Data Structure Libraries (was: Two types of efficiency) Oleg Trott
2003-05-04  7:55           ` [Caml-list] Efficiency of 'a list Ville-Pertti Keinonen
2003-05-04 10:56             ` Neel Krishnaswami
2003-05-04 12:56               ` Eray Ozkural
2003-05-04 13:35                 ` Falk Hueffner
2003-05-04 12:38           ` Eray Ozkural
2003-05-04  8:07         ` Ville-Pertti Keinonen
2003-05-04 15:54           ` Ed L Cashin
2003-05-05 23:52           ` Garry Hodgson
2003-05-03 20:03   ` Eray Ozkural
2003-05-03 21:13 ` Lauri Alanko
2003-05-03 22:03   ` Eray Ozkural [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=200305040103.04121.exa@kablonet.com.tr \
    --to=exa@kablonet.com.tr \
    --cc=caml-list@inria.fr \
    --cc=erayo@cs.bilkent.edu.tr \
    --cc=la@iki.fi \
    /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).