Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] removing an item from a list efficiently
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oleg Trott <oleg_trott@c...>
Subject: Re: [Caml-list] removing an item from a list efficiently
On Saturday 08 November 2003 03:49 am, Dustin Sallings wrote:
> On Nov 7, 2003, at 4:46, Stefano Zacchiroli wrote:
> > 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).
>
> 	This is really what I was asking, whether ocaml lists could be
> appropriate.
>
> 	I'm having difficulty figuring out how to implement a double linked
> list, though.  I want something like this:
>
> type 'a link = Nothing | Link of 'a t;;
>
> type 'a t = {
>      data: 'a;
>      mutable prev: 'a link;
>      mutable next: 'a link;
> };;
>
> 	But, link and t don't know about each other.  How does one go about
> doing this kind of thing in ocaml?

I've read your mind, and I think what you are trying to do is

type 'a t = {data: 'a; mutable prev: 'a option; mutable next: 'a option};;

or you can just do a web search for "doubly-linked list". It's out there.
-- 
Oleg Trott <oleg_trott@columbia.edu>

-------------------
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