From: David House <dhouse@janestreet.com>
To: Malcolm Matalka <mmatalka@gmail.com>
Cc: 沈胜宇 <syshen@nudt.edu.cn>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] [OCAML]:: the cost of List.length
Date: Mon, 15 Apr 2013 07:29:21 +0100 [thread overview]
Message-ID: <CAK=fH+iayL1PmbZnu4MS4t68cgm0G-7k0i4QVR410N1dtBYNqg@mail.gmail.com> (raw)
In-Reply-To: <CAKziXDVh8MMddwK85NG9piX4tdiXQnqTA7_32jNPLyn_pyuxOw@mail.gmail.com>
Lists are naive linked lists, i.e. either the empty list or a pair of
an element and a list. Finding the length means walking to the end of
the list.
There is probably a better data structure than lists for your
purposes. What operations do you need, and which ones need to be fast?
On 14 April 2013 14:32, Malcolm Matalka <mmatalka@gmail.com> wrote:
> O(n)
>
> Den 14 apr 2013 15:27 skrev "沈胜宇" <syshen@nudt.edu.cn>:
>
>> Dear all:
>>
>> I have a program that run very fast.
>>
>> Recently, I add a call to List.length to this old program's inner loop,
>> which make it significantly slower.
>>
>> So what is the cost of List.length, is it liner to the size of the list?
>> or is a const?
>>
>> Shen
next prev parent reply other threads:[~2013-04-15 6:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-14 13:23 沈胜宇
2013-04-14 13:32 ` Malcolm Matalka
2013-04-15 6:29 ` David House [this message]
2013-04-15 11:05 ` 沈胜宇
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='CAK=fH+iayL1PmbZnu4MS4t68cgm0G-7k0i4QVR410N1dtBYNqg@mail.gmail.com' \
--to=dhouse@janestreet.com \
--cc=caml-list@inria.fr \
--cc=mmatalka@gmail.com \
--cc=syshen@nudt.edu.cn \
/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