<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/11/1b659ba377258e8559706506c2db6f58"
  from="Stefano Zacchiroli &lt;zack@b...&gt;"
  author="Stefano Zacchiroli"
  date="2003-11-07T12:46:23"
  subject="Re: [Caml-list] removing an item from a list efficiently"
  prev="2003/11/e1bad687e478861296fd916bf372c385"
  next="2003/11/7ec5b0a474c6574105aed93a0b8e4678"
  prev-in-thread="2003/11/35bb4778a8df1590c7a455f7ccde6d41"
  next-in-thread="2003/11/abff800f267cf8fbd094693a8b321bf2"
  prev-thread="2003/11/140c9fadd8e2355539503a016bc1e217"
  next-thread="2003/11/810f9d2fb53a5d64dcf1e65d5252ea26"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] removing an item from a list efficiently">
<msg 
  url="2003/11/8bac1133214edc5aaff0c5dae8053b9e"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-11-07T09:32:27"
  subject="[Caml-list] removing an item from a list efficiently">
<msg 
  url="2003/11/35bb4778a8df1590c7a455f7ccde6d41"
  from="jrouquie@e..."
  author="jrouquie@e..."
  date="2003-11-07T09:49:13"
  subject="Re: [Caml-list] removing an item from a list efficiently">
</msg>
<msg 
  url="2003/11/1b659ba377258e8559706506c2db6f58"
  from="Stefano Zacchiroli &lt;zack@b...&gt;"
  author="Stefano Zacchiroli"
  date="2003-11-07T12:46:23"
  subject="Re: [Caml-list] removing an item from a list efficiently">
<msg 
  url="2003/11/abff800f267cf8fbd094693a8b321bf2"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-11-08T08:50:00"
  subject="Re: [Caml-list] removing an item from a list efficiently">
<msg 
  url="2003/11/c7d99f81f6a9a73503416cb0a2eae8ff"
  from="Stefano Zacchiroli &lt;zack@b...&gt;"
  author="Stefano Zacchiroli"
  date="2003-11-08T09:16:09"
  subject="Re: [Caml-list] removing an item from a list efficiently">
<msg 
  url="2003/11/46359372e8c3fe20eb2053f0ae783117"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-11-09T01:13:50"
  subject="Re: [Caml-list] removing an item from a list efficiently">
</msg>
</msg>
<msg 
  url="2003/11/32140dc8d0aefcc1084f7d71249259ed"
  from="Oleg Trott &lt;oleg_trott@c...&gt;"
  author="Oleg Trott"
  date="2003-11-08T10:59:15"
  subject="Re: [Caml-list] removing an item from a list efficiently">
<msg 
  url="2003/11/084dc18069992dc2bb611418ba46e2c0"
  from="Oleg Trott &lt;oleg_trott@c...&gt;"
  author="Oleg Trott"
  date="2003-11-08T11:02:32"
  subject="Re: [Caml-list] removing an item from a list efficiently">
</msg>
</msg>
<msg 
  url="2003/11/c3c337dbb5441234608baefc94d522c1"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-11-08T18:00:04"
  subject="Re: [Caml-list] removing an item from a list efficiently">
</msg>
</msg>
</msg>
<msg 
  url="2003/11/184f6a940f38b467106a0ab10f62e65d"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-11-07T15:51:55"
  subject="Re: [Caml-list] removing an item from a list efficiently">
</msg>
</msg>
</thread>

<contents>
On Fri, Nov 07, 2003 at 01:32:19AM -0800, Dustin Sallings wrote:
&gt; 	I'm trying to implement an LRU cache and I'm using a list to keep up 
&gt; with the accesses.  I'm using filter to remove the item for 
&gt; 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

</contents>

</message>

