caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Wheeler Ruml <ruml@parc.com>
To: John Gerard Malecki <johnm@artisan.com>
Cc: caml-list@inria.fr
Subject: [Caml-list] Re: Wanted - General Purpose "Glue Logic" Data-Structures
Date: Mon, 7 Apr 2003 17:59:02 PDT	[thread overview]
Message-ID: <16018.7894.703716.797621@katsura.parc.xerox.com> (raw)
In-Reply-To: <15993.10380.206589.498703@barrow.artisan.com>

>   - fast computation of cardinality
> 
>   - fast addition of single elements
> 
>   - fast addition of lists of elements
> 
>   - fast removal of single elements in random order
> 
>   - not choking on a large data size

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

type rarray = {
   a : 'a array;
   end : int;
}

where you allocate more space than you need (or allocate to the
correct size at the start, if you know it), doubling the size when
necessary, and only look at those elements before the end.  Brian's
queue may well do this underneath, 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.


Wheeler
-- 
Wheeler Ruml, Palo Alto Research Center, Rm 1522, 650-812-4329 voice
http://www.parc.com/ruml                          650-812-4334 fax

-------------------
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  9:01 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 ` Wheeler Ruml [this message]
2003-04-08  9:12   ` [Caml-list] " 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=16018.7894.703716.797621@katsura.parc.xerox.com \
    --to=ruml@parc.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).