From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA32071; Tue, 13 Aug 2002 19:26:39 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA32079 for ; Tue, 13 Aug 2002 19:26:38 +0200 (MET DST) Received: from viola.sinor.ru (viola.sinor.ru [217.70.106.9]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7DHQab12572 for ; Tue, 13 Aug 2002 19:26:37 +0200 (MET DST) Received: from sibnet.ru (tlg5-ppp21.sibnet.ru [217.70.116.21]) by viola.sinor.ru (8.12.3/8.12.3) with ESMTP id g7DHQVrY022777 for ; Wed, 14 Aug 2002 00:26:32 +0700 Received: by sibnet.ru id m17efHO-001EocC; Wed, 14 Aug 2002 00:16:26 +0700 (NOVST) Date: Wed, 14 Aug 2002 00:16:25 +0700 From: Max Kirillov To: caml-list@inria.fr Subject: Re: [Caml-list] Doubly-linked list Message-ID: <20020814001625.A4141@max.home> Mail-Followup-To: caml-list@inria.fr References: <200208131430.KAA23206@hickory.cc.columbia.edu> <012001c242db$ba4c9f90$2be213c3@youngkouzdra> <200208131611.MAA00208@dewberry.cc.columbia.edu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Qxx1br4bt0+wmkIi" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200208131611.MAA00208@dewberry.cc.columbia.edu>; from oleg_inconnu@myrealbox.com on Tue, Aug 13, 2002 at 12:12:45PM -0400 X-Sender: Max Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --Qxx1br4bt0+wmkIi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Aug 13, 2002 at 12:12:45PM -0400, Oleg wrote: > type 'a dlist = {mutable prev : 'a dlist option; > mutable next : 'a dlist option; > info : 'a} > Maybe I'll write it in the next few days. What kind of bothers me is the need > to have iterators (a la STL) as helper types. Unless you need thread-safe behavior, that could be just "'a dlist ref". I tried to do some fast things. See attachment. That's just an idea. Max. --Qxx1br4bt0+wmkIi Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="dlist.ml" type 'a t = {mutable prev : 'a t option; mutable next : 'a t option; info : 'a} type 'a dlist = {mutable front: 'a t; mutable back: 'a t} exception Bound next = function {next=Some obj1} -> obj1 | _ -> raise Bound prev = function {prev=Some obj1} -> obj1 | _ -> raise Bound takeNext objR = objR:=(next !objR) takePrev objR = objR:=(prev !objR) add_before v obj = let newObj = {prev=None;next=obj;info=v} in (match obj with {prev=Some obj1} -> (newObj.prev<-obj1; obj1.next<-newObj) | {prev=None} -> ()); obj.prev=newObj add_after v obj = let newObj = {next=None;prev=obj;info=v} in (match obj with {next=Some obj1} -> (newObj.next<-obj1; obj1.prev<-newObj) | {next=None} -> ()); obj.next=newObj (* Hmm... I'm not clear whether front is after back or before it. Depends on moving direction:) Let's suppose before *) push_back v ({back=obj} as data) = add_after v obj; data.back <- next obj push_front v ({front=obj} as data) = add_before v obj; data.front <- prev obj --Qxx1br4bt0+wmkIi-- ------------------- 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