From: Ted Dennison<dennison@telepath.com>
Subject: Re: List container strawman 1.2
Date: Tue, 13 Nov 2001 15:54:32 GMT
Date: 2001-11-13T15:54:32+00:00 [thread overview]
Message-ID: <YmbI7.23093$xS6.36043@www.newsranger.com> (raw)
In-Reply-To: 3BF05337.75BE0A18@san.rr.com
In article <3BF05337.75BE0A18@san.rr.com>, Darren New says...
>
>Darren New wrote:
> function "&" (Left, Right : Element) return List;
> -- O(1)
I much prefer pre-comments to post-comments. The reason is that you read them
before you get to the source, rather than after you have already tried to read
the source and are perhaps already confused and/or misled. Forewarned is
forearmed. :-)
However, the bit about specifying the time behavior for the routines is a good
point.
> function "&" (Left : Element; Right : List) return List;
> -- O(Size(Right))
> function "&" (Left : List; Right : Element) return List;
> -- O(Size(Left))
> function "&" (Left, Right : List) return List;
> -- O(Size(Left)+Size(Right))
> function "+" (Initial_Element : Element) return List;
> -- O(1)
>
> -- List access
> -- These should all be obvious, except for error cases.
> -- All of these raise No_Item if the specified item doesn't exist.
> -- I.e., front and back raise No_Item if Has_Item(L) is empty.
> -- Item raises No_Item if Size(L)<I.
> No_Item : exception;
> function Front(L : List) return Element; -- O(1)
> function Back(L : List) return Element; -- O(1)
> function Front(L : List) return Location; -- O(1)
> function Back(L : List) return Location; -- O(1)
> function Item(L : List; I : Positive) return Element; -- O(I)
> function Item(L : List; I : Positive) return Location; -- O(I)
> function Size(L : List) return Natural; -- O(1)
> function Has_Item(L : List) return Boolean; -- O(1)
> -- Same as Size(L)/=0
> function Has_Item(L : List; I : Positive) return Boolean; -- O(1)
> -- Same as I<=Size(L)
> function List_Of(L : Location) return List; -- O(1)
> function Index_Of(L : Location) return Positive; --
>O(Size(List_Of(L))
> -- Raises No_Item if Has_Item(L)=False
> -- Item(List_Of(L),Index_Of(L))=Item(L)
> procedure Wipe(L : in out List); -- O(Size(L))
> -- Unlinks all links in List without affecting any elements
> -- After this, Size(L)=0
> procedure Copy(In_L : in List; Out_L : out List);
> -- Creates new list, puts copy of In_L into Out_L.
>
> -- Location manipulation
> function Has_Next(L : Location) return Boolean;
> -- Current location is not the last on the list and
> -- list is not empty. O(1)
> function Has_Previous(L : Location) return Boolean;
> -- Current location is not the first on the list and
> -- list is not empty. O(1)
> function Has_Item(L : Location) return Boolean;
> -- Current item has not been removed and list is not empty. O(1)
> procedure Next(L : in out Location);
> -- Raises No_Item if Has_Next(L) is false
> -- Ensures Has_Previous(L) is true if no exception
> -- May change Has_Next(L) and Has_Item(L)
> -- O(1)
> procedure Previous(L : in out Location);
> -- Raises No_Item if Has_Previous(L) is false
> -- Ensures Has_Next(L) if no exception thrown
> -- O(1)
> function Item(L : Location) return Element;
> -- Raises No_Item if Has_Item(L) is false
> -- O(1)
>
> -- List modification
> procedure Remove(L : in out Location);
> -- Raises No_Item if Has_Item(L) is false
> -- After this, Has_Item(L) will be false
> -- O(1)
> procedure Replace(L : in out Location;
> Item : in Element);
> -- Does the obvious. Raises No_Item if Has_Item(L)=False
> -- O(1)
>
> procedure Insert_Before(L : in out Location;
> Item : in Element);
> -- Inserts copy of Item into list at location L.
> -- Item(L) is not changed by this call.
> -- That is, Index_Of(L) increases by one.
> -- Works even on empty lists and even if not Has_Item(L)
> -- O(1)
> procedure Insert_After(L : in out Location;
> Item : in Element);
> -- Inserts a copy of Item into list after location L.
> -- Item(L) is not changed by this call.
> -- That is, Index_Of(L) remains the same,
> -- but Size(List_Of(L)) increases.
> -- Works even on empty lists and even if not Has_Item(L)
> -- O(1)
>
> procedure Insert_Before(L : in out Location;
> Other : in out List);
> -- Inserts contents of Other into list at location L.
> -- Item(L) is not changed by this call.
> -- That is, Index_Of(L) increases by Size(Other).
> -- Works even on empty lists and even if not Has_Item(L).
> -- After this, Size(Other)=0 -- Contents *moved*.
> -- O(1)
> procedure Insert_After(L : in out Location;
> Other : in out List);
> -- Inserts a copy of Item into list after location L.
> -- Item(L) is not changed by this call.
> -- That is, Index_Of(L) remains the same,
> -- but Size(List_Of(L)) increases by Size(Other).
> -- Works even on empty lists and even if not Has_Item(L)
> -- After this, Size(Other)=0 -- Contents *moved*.
> -- O(1)
>
> generic
> with function "<"(Left, Right : in Element) return Boolean;
> procedure Sort(L : in out List);
> -- Old Size(L)=new Size(L), but all elements are sorted
> -- such that Item(L) < Item(Next(L)) for all locations.
> -- OK, do we want a stable sort? Probably. I'm not sure if
> -- we need "<=" or "=" or what.
>
> generic
> with function "<"(Left, Right : in Element) return Boolean;
> procedure Insert_Sorted(L : in out List; I : in Element);
> -- Inserts I into list L such that
>
> -- I can also see a number of operations if "=" is defined
> -- for elements, such as "count the number of elements equal
> -- to this" or "give a Location where Item(L)=I" and such.
>
> -- Iterating would look something like this:
> -- Li : List; Lo : Location;
> -- Lo := Front(Li);
> -- while Has_Item(Lo) loop
> -- if Item(Lo) = George then
> -- Replace(Lo, Sally);
> -- end if;
> -- Next(Lo);
> -- end while;
>
>private
> type Link;
> type Link_Access is access Link;
> type Link is record
> Next, Prev : Link_Access;
> Elem : Element;
> end record;
>
> type List is record
> Head, Tail : Link_Access;
> Size : Natural;
> end record;
> -- Size=0 -> head=null and tail=null
> -- Size=1 -> head=tail
> -- Size>1 -> head/=tail
> type List_Access is access List;
>
> type Location is record
> L : List_Access; -- What am I pointing into?
> Next, Prev : Link_Access; -- prev and next
> Curr : Link_Access; -- Do I have a current?
> end record;
> -- L.Size=0 -> next, prev, curr=nul
> -- Has_Item(this) -> Curr/=null
> -- Has_Next(this) -> Next/=null
> -- Has_Previous(this) -> Prev/=null
>
> -- It is possible by to add Invalid_Change to all Location
> -- operations that will catch using two locations into the
> -- same list and modifying them in ways that they invalidate
> -- the other, but that's additional overhead we might not want.
> -- It consists of basically adding a "change counter" to each
> -- location and list, incrementing both with each change, and
> -- then revalidating each location that refers to a list whose
> -- change counter doesn't match, eliminating most of the
> -- overhead for the normal case of only one location being
> -- manipulated at a time.
>end AdaLists;
>
>
>--
>Darren New
>San Diego, CA, USA (PST). Cryptokeys on demand.
> You will soon read a generic fortune cookie.
---
T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html
No trees were killed in the sending of this message.
However a large number of electrons were terribly inconvenienced.
next prev parent reply other threads:[~2001-11-13 15:54 UTC|newest]
Thread overview: 189+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-10 3:51 List container strawman 1.2 Ted Dennison
2001-11-10 4:20 ` Jeffrey Carter
2001-11-10 4:59 ` Ted Dennison
2001-11-10 11:14 ` Florian Weimer
2001-11-10 16:24 ` Ted Dennison
2001-11-10 17:39 ` Florian Weimer
2001-11-10 18:31 ` Ted Dennison
2001-11-10 18:45 ` Jean-Marc Bourguet
2001-11-10 22:44 ` Ted Dennison
2001-11-11 3:59 ` Steven Deller
2001-11-11 11:29 ` Jean-Marc Bourguet
2001-11-11 17:42 ` Steven Deller
2001-11-11 12:36 ` Jean-Marc Bourguet
2001-11-10 22:07 ` Jeffrey Carter
2001-11-11 17:28 ` Jeffrey Carter
2001-11-10 14:51 ` Ehud Lamm
2001-11-10 16:08 ` Larry Kilgallen
2001-11-10 16:23 ` List container: Insert and Delete Nick Roberts
2001-11-10 17:13 ` Ted Dennison
2001-11-10 21:20 ` Nick Roberts
2001-11-10 22:15 ` Ehud Lamm
2001-11-10 22:48 ` Ted Dennison
2001-11-10 22:40 ` Jeffrey Carter
2001-11-11 4:00 ` Nick Roberts
2001-11-11 17:37 ` Jeffrey Carter
2001-11-11 19:29 ` Steven Deller
2001-11-12 0:20 ` Nick Roberts
2001-11-12 3:48 ` Steven Deller
2001-11-12 13:54 ` Nick Roberts
2001-11-12 15:21 ` Larry Kilgallen
2001-11-13 1:19 ` Nick Roberts
2001-11-12 17:27 ` Jeffrey Carter
2001-11-13 1:28 ` Nick Roberts
2001-11-13 1:37 ` Darren New
2001-11-13 15:58 ` John English
2001-11-13 17:53 ` Pascal Obry
2001-11-12 15:42 ` Marin David Condic
2001-11-12 5:23 ` Ted Dennison
2001-11-12 13:04 ` Nick Roberts
2001-11-12 16:36 ` Ted Dennison
2001-11-12 17:20 ` Jeffrey Carter
2001-11-12 18:55 ` Marin David Condic
2001-11-12 19:56 ` Larry Kilgallen
2001-11-12 20:36 ` Marin David Condic
2001-11-12 21:14 ` Darren New
2001-11-13 7:31 ` Simon Wright
2001-11-13 21:31 ` Marin David Condic
2001-11-14 4:43 ` Nick Roberts
2001-11-13 2:16 ` Jeffrey Carter
2001-11-13 14:18 ` Marin David Condic
2001-11-13 15:03 ` Ted Dennison
2001-11-13 15:28 ` Marin David Condic
2001-11-13 16:16 ` Jeffrey Carter
2001-11-13 19:59 ` Ted Dennison
2001-11-13 20:18 ` Marin David Condic
2001-11-13 21:26 ` Ted Dennison
2001-11-13 21:39 ` Marin David Condic
2001-11-13 22:16 ` Map container (was: List container: Insert and Delete) Ted Dennison
2001-11-14 15:07 ` Marin David Condic
2001-11-13 22:22 ` List container: Insert and Delete Jeffrey Carter
2001-11-13 17:46 ` Darren New
2001-11-13 19:25 ` Steven Deller
2001-11-13 19:40 ` Darren New
2001-11-13 20:53 ` Ted Dennison
2001-11-13 20:10 ` Ted Dennison
2001-11-13 21:31 ` Darren New
2001-11-13 22:37 ` Ted Dennison
2001-11-13 22:44 ` Ted Dennison
2001-11-13 23:00 ` Darren New
2001-11-14 14:31 ` Ted Dennison
2001-11-13 14:20 ` Steven Deller
2001-11-13 15:48 ` John English
2001-11-13 20:22 ` Ted Dennison
2001-11-14 12:59 ` John English
2001-11-14 14:55 ` Ted Dennison
2001-11-14 15:34 ` Marin David Condic
2001-11-15 16:35 ` John English
2001-11-14 16:41 ` Jeffrey Carter
2001-11-13 20:22 ` Ehud Lamm
2001-11-13 21:33 ` Simon Wright
2001-11-14 12:54 ` John English
2001-11-14 16:43 ` Ehud Lamm
2001-11-14 18:19 ` Marin David Condic
2001-11-15 4:29 ` List container: Sawdust woman 43 Jeffrey Carter
2001-11-15 15:25 ` Marin David Condic
2001-11-16 1:59 ` Jeffrey Carter
2001-11-15 20:30 ` List container: Insert and Delete Simon Wright
2001-11-15 17:01 ` John English
2001-11-19 17:40 ` Ted Dennison
2001-11-20 10:52 ` John English
2001-11-13 21:07 ` Ted Dennison
2001-11-12 17:18 ` Jeffrey Carter
2001-11-12 17:13 ` Jeffrey Carter
2001-11-11 23:34 ` Nick Roberts
2001-11-12 16:33 ` Jeffrey Carter
2001-11-12 17:28 ` Ted Dennison
2001-11-13 2:27 ` Jeffrey Carter
2001-11-13 14:21 ` Ted Dennison
2001-11-14 4:16 ` Nick Roberts
2001-11-14 15:03 ` Ted Dennison
2001-11-13 0:51 ` Nick Roberts
2001-11-12 16:51 ` Ted Dennison
2001-11-13 0:44 ` Nick Roberts
2001-11-13 14:18 ` Ted Dennison
2001-11-14 4:17 ` Nick Roberts
2001-11-10 16:12 ` List container strawman 1.2 Ted Dennison
2001-11-10 18:49 ` Jean-Marc Bourguet
2001-11-10 19:29 ` Ehud Lamm
2001-11-11 10:46 ` Jean-Marc Bourguet
2001-11-11 13:07 ` Larry Kilgallen
2001-11-10 19:07 ` Jacob Sparre Andersen
2001-11-10 22:53 ` Ted Dennison
2001-11-12 16:45 ` Jacob Sparre Andersen
2001-11-13 0:55 ` Nick Roberts
2001-11-13 15:11 ` Ted Dennison
2001-11-10 22:17 ` Jeffrey Carter
2001-11-11 22:04 ` Simon Wright
2001-11-12 16:53 ` Ted Dennison
2001-11-13 7:25 ` Simon Wright
2001-11-13 22:04 ` Ted Dennison
2001-11-10 17:43 ` Florian Weimer
2001-11-10 16:46 ` Ted Dennison
2001-11-10 18:50 ` Steven Deller
2001-11-12 9:25 ` Martin Dowie
2001-11-12 12:57 ` Nick Roberts
2001-11-12 15:32 ` Marin David Condic
2001-11-12 16:58 ` Martin Dowie
2001-11-12 18:44 ` Marin David Condic
2001-11-13 7:18 ` Simon Wright
2001-11-13 21:26 ` Marin David Condic
2001-11-15 23:53 ` martin.m.dowie
2001-11-12 17:35 ` Ted Dennison
2001-11-12 18:39 ` Martin Dowie
2001-11-12 19:58 ` Ted Dennison
2001-11-12 18:39 ` Steven Deller
2001-11-12 20:05 ` Ted Dennison
2001-11-13 19:12 ` Stephen Leake
2001-11-12 16:37 ` Jeffrey Carter
2001-11-12 18:50 ` Marin David Condic
2001-11-13 1:07 ` Nick Roberts
2001-11-13 15:13 ` Ted Dennison
2001-11-15 23:54 ` martin.m.dowie
2001-11-13 19:10 ` Stephen Leake
[not found] ` <3BF0247D.4500975E@san.rr.com>
2001-11-12 20:30 ` Ehud Lamm
2001-11-12 21:57 ` Ted Dennison
2001-11-12 22:53 ` Darren New
2001-11-12 22:55 ` Darren New
2001-11-13 15:54 ` Ted Dennison [this message]
2001-11-13 19:17 ` Stephen Leake
2001-11-13 22:37 ` Jeffrey Carter
2001-11-13 15:49 ` Ted Dennison
2001-11-13 16:38 ` Martin Dowie
2001-11-13 19:06 ` Ted Dennison
2001-11-13 19:43 ` Marin David Condic
2001-11-13 20:50 ` Ted Dennison
2001-11-13 21:08 ` Marin David Condic
2001-11-14 4:34 ` Nick Roberts
2001-11-14 14:58 ` Marin David Condic
2001-11-13 17:36 ` Darren New
2001-11-14 4:40 ` Nick Roberts
2001-11-13 22:34 ` Jeffrey Carter
2001-11-14 13:39 ` John English
2001-11-14 15:09 ` Ted Dennison
2001-11-14 16:04 ` Jeffrey Carter
2001-11-14 16:36 ` Ted Dennison
2001-11-15 16:31 ` John English
2001-11-19 17:59 ` Ted Dennison
2001-11-19 21:08 ` Stephen Leake
2001-11-20 10:43 ` John English
2001-11-21 19:40 ` ramatthews
2001-11-22 3:01 ` Nick Roberts
2001-11-22 9:28 ` John English
2001-11-24 3:52 ` Nick Roberts
2001-11-23 2:21 ` Ted Dennison
2001-11-24 0:27 ` John English
2001-11-27 20:04 ` Marin David Condic
2001-11-28 8:10 ` Thomas Wolf
2001-11-28 14:29 ` Marin David Condic
2001-11-28 17:34 ` Ted Dennison
2001-11-28 18:01 ` Marin David Condic
2001-11-28 18:53 ` Ted Dennison
2001-11-28 19:08 ` Overriding 'Class'Input (was: List container strawman 1.1) Ted Dennison
2001-11-28 19:19 ` Ted Dennison
2001-11-28 20:40 ` Marin David Condic
2001-11-28 21:21 ` Ted Dennison
2001-11-28 21:50 ` Marin David Condic
2001-11-29 5:12 ` Nick Roberts
2001-11-29 20:04 ` List container strawman 1.2 Thomas Wolf
2001-11-16 0:01 ` martin.m.dowie
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox