caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Stefano Zacchiroli <zack@bononia.it>
To: Caml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] removing an item from a list efficiently
Date: Fri, 7 Nov 2003 13:46:19 +0100	[thread overview]
Message-ID: <20031107124619.GA14374@fistandantilus.takhisis.org> (raw)
In-Reply-To: <483F0AC5-1105-11D8-AC71-000393CFE6B8@spy.net>

On Fri, Nov 07, 2003 at 01:32:19AM -0800, Dustin Sallings wrote:
> 	I'm trying to implement an LRU cache and I'm using a list to keep up 
> with the accesses.  I'm using filter to remove the item for 
> repositioning it.  That's very slow.

List.filter will scan the entire list anyway. In the LRU case you can
stop the list traversal after finding the first (i.e. only) element you
want to remove. Still you have to traverse the list at least until the
element you want to remove.

IMHO to implement an LRU policy, lists are not the best structures due
to the O(n) limit above. You can consider standard heaps (assuming you
have an upper bound on the number of entries) or binomial heaps (you can
find an implementation in Okasaki's book).

Cheers.

-- 
Stefano Zacchiroli  --  Master in Computer Science @ Uni. Bologna, Italy
zack@{cs.unibo.it,debian.org,bononia.it}  -  http://www.bononia.it/zack/
"  I know you believe you understood what you think I said, but I am not
sure you realize that what you heard is not what I meant!  " -- G.Romney

-------------------
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-11-07 12:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-07  9:32 Dustin Sallings
2003-11-07  9:49 ` jrouquie
2003-11-07 12:46 ` Stefano Zacchiroli [this message]
2003-11-08  8:49   ` Dustin Sallings
2003-11-08  9:16     ` Stefano Zacchiroli
2003-11-09  1:13       ` Dustin Sallings
2003-11-08 10:59     ` Oleg Trott
2003-11-08 11:02       ` Oleg Trott
2003-11-08 18:57     ` Brian Hurt
2003-11-07 16:50 ` Brian Hurt

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=20031107124619.GA14374@fistandantilus.takhisis.org \
    --to=zack@bononia.it \
    --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;
as well as URLs for NNTP newsgroup(s).