* Re: [Caml-list] removing an item from a list efficiently
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 18:57 ` Brian Hurt
2 siblings, 1 reply; 10+ messages in thread
From: Stefano Zacchiroli @ 2003-11-08 9:16 UTC (permalink / raw)
To: Caml Mailing List
[ Please don't Cc:-me, I'm subscribed to this list, as my
Mail-Followup-To header can confirm ]
On Sat, Nov 08, 2003 at 12:49:48AM -0800, Dustin Sallings wrote:
> 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:
I still think that lists, no matter if single or doubly linked aren't a
good structure for your cache, anyway ...
> 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?
What do you mean? The above declaration isn't correct just because you
have to use an "and" instead of a "type" for the second declaration to
have two mutual recursive types. I don't know if this is really what
you're asking ...
Cheers.
--
^Stefano Zacchiroli -- Master in Computer Science @ Uni. Bologna, Italy$
^zack@{cs.unibo.it,debian.org,bononia.it} -- http://www.bononia.it/zack$
^Frequentando il mio maestro mi ero reso conto [.] che la logica poteva$
^servire a molto a condizione di entrarci dentro e poi di uscirne -Adso$
-------------------
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] removing an item from a list efficiently
2003-11-08 9:16 ` Stefano Zacchiroli
@ 2003-11-09 1:13 ` Dustin Sallings
0 siblings, 0 replies; 10+ messages in thread
From: Dustin Sallings @ 2003-11-09 1:13 UTC (permalink / raw)
To: Caml Mailing List
On Nov 8, 2003, at 1:16, Stefano Zacchiroli wrote:
> I still think that lists, no matter if single or doubly linked aren't a
> good structure for your cache, anyway ...
I'm using a Hashtbl for indexing the linked list which is used for
maintaining the sequence. It should be O(1).
>> 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?
>
> What do you mean? The above declaration isn't correct just because you
> have to use an "and" instead of a "type" for the second declaration to
> have two mutual recursive types. I don't know if this is really what
> you're asking ...
It is, thank you. The ``and'' thing was not obvious to me. Still
learning.
--
Dustin Sallings
-------------------
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] removing an item from a list efficiently
2003-11-08 8:49 ` Dustin Sallings
2003-11-08 9:16 ` Stefano Zacchiroli
@ 2003-11-08 10:59 ` Oleg Trott
2003-11-08 11:02 ` Oleg Trott
2003-11-08 18:57 ` Brian Hurt
2 siblings, 1 reply; 10+ messages in thread
From: Oleg Trott @ 2003-11-08 10:59 UTC (permalink / raw)
To: Dustin Sallings; +Cc: Caml Mailing List
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] removing an item from a list efficiently
2003-11-08 10:59 ` Oleg Trott
@ 2003-11-08 11:02 ` Oleg Trott
0 siblings, 0 replies; 10+ messages in thread
From: Oleg Trott @ 2003-11-08 11:02 UTC (permalink / raw)
To: Dustin Sallings; +Cc: Caml Mailing List
On Saturday 08 November 2003 05:59 am, Oleg Trott wrote:
> 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.
I meant
type 'a t = {data: 'a; mutable prev: 'a t option; mutable next: 'a t option};;
--
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] removing an item from a list efficiently
2003-11-08 8:49 ` Dustin Sallings
2003-11-08 9:16 ` Stefano Zacchiroli
2003-11-08 10:59 ` Oleg Trott
@ 2003-11-08 18:57 ` Brian Hurt
2 siblings, 0 replies; 10+ messages in thread
From: Brian Hurt @ 2003-11-08 18:57 UTC (permalink / raw)
To: Dustin Sallings; +Cc: Stefano Zacchiroli, Caml Mailing List
On Sat, 8 Nov 2003, Dustin Sallings wrote:
> 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?
>
Use and:
type 'a link = Nothing | Something of 'a t
and 'a t = { data: 'a; mutable next: 'a link; mutable prev: 'a link }
The other alternative is to not redefine option:
type 'a t =
{ data: 'a; mutable next: 'a t option; mutable prev: 'a t option }
Brian
--
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
- Gene Spafford
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
^ permalink raw reply [flat|nested] 10+ messages in thread