caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <brian.hurt@qlogic.com>
To: Wheeler Ruml <ruml@parc.com>
Cc: John Gerard Malecki <johnm@artisan.com>, <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: Wanted - General Purpose "Glue Logic" Data-Structures
Date: Tue, 8 Apr 2003 10:07:16 -0500 (CDT)	[thread overview]
Message-ID: <Pine.LNX.4.33.0304080956380.2225-100000@eagle.ancor.com> (raw)
In-Reply-To: <16018.7894.703716.797621@katsura.parc.xerox.com>

On Mon, 7 Apr 2003, Wheeler Ruml wrote:

> I saw Brian's recommendation of a priority queue, but wanted to
> mention that a resizable array would do here as well.  Eg, something
> like

It actually sounds like a simple tree is what he needs.  The problem with 
a resizeable array is that removing anything except the last element is 
O(n)- remember that you have to copy all the higher elements down.  He 
specified fast deletion of arbitrary elements.

> Brian's
> queue may well do this underneath, 

Actually, my PSQueue is built ontop of a red-black tree.  And it's mainly 
usefull when you need both the behaviors of a priority queue and a search 
tree.  Otherwise it is a little heavy/

> but there's no reason to suffer
> O(log n) insertion and removal time if you don't really care about the
> order.  Just add to the end and swap with a random element in constant
> time.  Or remove from a random place and copy in the last element.
> The only tricky thing is to be careful to fill any "empty" cells in
> the array with the same dummy value (which needs to be supplied at
> creation time) so you don't prevent objects from being GC'ed.

This was the problem I ran into trying to do an arbitrary resizeable
array- I ended up doing a Some of/None trick to handle empty array
elements.  Which, of course, added a whole second layer of references.  
Although requiring the user to supply a null item isn't as bad as I first
thought- it's the same thing that Array.make does...

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


  parent reply	other threads:[~2003-04-08 15:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-20  2:33 [Caml-list] " John Gerard Malecki
2003-03-20 16:53 ` Brian Hurt
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 [this message]
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.0304080956380.2225-100000@eagle.ancor.com \
    --to=brian.hurt@qlogic.com \
    --cc=caml-list@inria.fr \
    --cc=johnm@artisan.com \
    --cc=ruml@parc.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).