caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <brian.hurt@qlogic.com>
To: John Gerard Malecki <johnm@artisan.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Wanted - General Purpose "Glue Logic" Data-Structures
Date: Thu, 20 Mar 2003 10:53:08 -0600 (CST)	[thread overview]
Message-ID: <Pine.LNX.4.33.0303201034180.2164-100000@eagle.ancor.com> (raw)
In-Reply-To: <15993.10380.206589.498703@barrow.artisan.com>

On Wed, 19 Mar 2003, John Gerard Malecki wrote:

> The program broke down in 2 places.  First, List.concat was used to
> convert the output of the fracturer from 'a list list to 'a list.  Not
> only is List.concat not tail-recursive but @ (Pervasives.append) is
> also not tail-recursive.  I modified the fracturer to directly produce
> 'a list.

I have a tail-recursive version of the entire list library, including 
append, kicking around- I'll send it to you.  That fixes this problem.  
But thank you for proving me right- this *is* a problem :-).

As for producing the tree, I'd recommend using a self-balancing tree- 
perhaps a Red-Black tree (which is surprisingly easy to implement in 
Ocaml.  It's annoying that the standard library's set doesn't *quite* do 
what you need).  Inserting an element should be O(log n), meaning you 
should be able to build the whole tree in O(n * log n).

Hmm.  Alternatively, you might also look at my Priority Search Queue 
implementation.  This probably does more than you need, but that's better 
than doing less than you need :-).  With PSQueue:

>    - fast computation of cardinality

Cardinality is, or should be, O(1) (if all else, I just keep a running 
count of elements in the tree).

>  
>    - fast addition of single elements

PSQueue is O(log n) addition.

>  
>    - fast addition of lists of elements

Adding a list of k elements to a n-element PSQueue is O(k * log n).

>  
>    - fast removal of single elements in random order

PSQueue is O(log n) removal of any element.  Also, finding any given 
element given it's key is O(log n).

>  
>    - not choking on a large data size

PSQueue is not tail recursive, but it only uses O(log n) stack space (it's 
a balanced tree).  I'll send the code on and you can look at it.

Brian


-------------------
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-03-20 16:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-20  2:33 John Gerard Malecki
2003-03-20 16:53 ` Brian Hurt [this message]
2003-03-20 17:36 ` Matthew W. Boyd
2003-03-24  6:08 ` Nicolas Cannasse
2003-04-08  0:59 ` [Caml-list] " Wheeler Ruml
2003-04-08  9:12   ` Markus Mottl
2003-04-08 12:03     ` Yaron M. Minsky
2003-04-09  6:51       ` Jean-Christophe Filliatre
2003-04-09 18:12         ` Brian Hurt
2003-04-10  8:12           ` Jean-Christophe Filliatre
2003-04-10 10:35             ` Markus Mottl
2003-04-10 15:30               ` David Brown
2003-04-10 15:03             ` Brian Hurt
2003-04-08 15:07   ` Brian Hurt
2003-04-08 16:38     ` John Gerard Malecki

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.0303201034180.2164-100000@eagle.ancor.com \
    --to=brian.hurt@qlogic.com \
    --cc=caml-list@inria.fr \
    --cc=johnm@artisan.com \
    /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).