Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Brian Hurt <brian.hurt@qlogic.com>
To: Alessandro Baretta <alex@baretta.com>
Cc: Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Map module
Date: Thu, 5 Jun 2003 11:25:52 -0500 (CDT)	[thread overview]
Message-ID: <Pine.LNX.4.33.0306051107230.2857-200000@eagle.ancor.com> (raw)
In-Reply-To: <3EDF64F9.5020905@baretta.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1126 bytes --]

On Thu, 5 Jun 2003, Alessandro Baretta wrote:

> Hello folks. I've been away for a while. I hope everyone is 
> well. Long live the Caml!
> 
> Now to the question?
> 
> How well is the Map module supposed to scale into the tens 
> of thousands of entries? I'm getting a stack overflow when 
> trying to insert some 80k key-value pairs in a Map. My 
> function is tail recursive, so I should not be responsibile 
> for this.
> 

Glancing at the code, it appears to be a height-balanced tree.  So 
operations should use only O(log N) stack frames- call it something less 
than 32 stack frames for 80K elements.  Which means either there is a bug 
in that code, or your insert routine is not tail-recursive.

Attached is a little test program I whipped up to test the map module.  I 
insert 800K elements into a map in the two worst ways I can think of- 
increasing key order and decreasing key order.  I'm actually rather 
impressed with the performance- running this code only takes a couple of 
seconds.  Which makes me more suspicious that your insert routine isn't 
tail recursive.

Got a code sample you can share?

Brian


[-- Attachment #2: Type: TEXT/PLAIN, Size: 722 bytes --]


module Int =
    struct
       type t = int
       let compare (a: t) (b: t) = if a < b then -1 else if a > b then 1 else 0
    end

module IntMap = Map.Make(Int)

let max = 800000

let _ =
    let rec loop map a b i =
        if i < max then
            loop (IntMap.add i a map) (a+b) a (i+1)
        else
            map
    in
    loop (IntMap.empty) 1 1 0

let _ =
    let rec fib a b i =
        if i < max then
            fib (a+b) a (i+1)
        else
            a, b
    in
    let rec loop map a b i =
        if i > 0 then
            loop (IntMap.add i a map) b (a-b) (i-1)
        else
            map
    in
    let a, b = fib 1 1 0 in
    loop (IntMap.empty) a b max


  parent reply	other threads:[~2003-06-05 16:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-05 15:42 Alessandro Baretta
2003-06-05 15:53 ` Dominique Quatravaux
2003-06-05 15:58 ` james woodyatt
2003-06-05 16:25 ` Brian Hurt [this message]
2003-06-05 18:02   ` Alessandro Baretta
2003-06-05 18:13     ` jeanfrancois.monin
2003-06-05 18:15     ` Fred Smith
2003-06-05 18:24       ` Alessandro Baretta

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=Pine.LNX.4.33.0306051107230.2857-200000@eagle.ancor.com \
    --to=brian.hurt@qlogic.com \
    --cc=alex@baretta.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