Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /charles/src/ai302/

charles
Discussion topic

Back to topic list

CVS update: /charles/src/ai302/

Reply

Author matthewjheaney
Full name Matthew Heaney
Date 2004-05-16 10:37:57 PDT
Message User: matthewjheaney
Date: 04/05/16 10:37:57

Modified:
 /charles/src/ai302/
  ai302-containers-dou​bly_linked_lists.adb​

Log:
 fully sync'd with API release 2004-04-29 AI95-00302-03/03

File Changes:

Directory: /charles/src/ai302/
==============================

File [changed]: ai302-containers-dou​bly_linked_lists.adb​
Url: http://charles.tigri​s.org/source/browse/​charles/src/ai302/ai​302-containers-doubl​y_linked_lists.adb?r​1=1.12&r2=1.13
Delta lines: +263 -194
-----------------------
--- ai302-containers-dou​bly_linked_lists.adb​ 19 Mar 2004 04:04:15 -0000 1.12
+++ ai302-containers-dou​bly_linked_lists.adb​ 16 May 2004 17:37:54 -0000 1.13
@@ -39,9 +39,9 @@
       new Ada.Unchecked_Deallocation (Node_Type, Node_Access);
 
 
- function Is_Null (Position : Cursor) return Boolean is
+ function Has_Element (Position : Cursor) return Boolean is
    begin
- return Position = Null_Cursor;
+ return Position /= null;
    end;
 
 
@@ -149,46 +149,13 @@
    end Clear;
 
 
- procedure Assign
- (Target : in out List;
- Source : in List) is
-
- begin
-
- if Target'Address = Source'Address then
- return;
- end if;
-
- Clear (Target);
-
- declare
- procedure Process (C : in Cursor) is
- pragma Inline (Process);
- begin
- Append (Target, New_Item => C.Element);
- end;
-
- procedure Iterate is
- new Generic_Iteration (Process);
- begin
- Iterate (Source);
- end;
-
- end Assign;
-
-
- procedure Delete
- (Container : in out List;
+ procedure Delete_Internal (Container : in out List;
       Position : in out Cursor) is
 
       X : Node_Access := Node_Access (Position);
 
    begin
 
- if X = null then
- return;
- end if;
-
       Position := Cursor (X.Next);
 
       Container.Length := Container.Length - 1;
@@ -224,20 +191,42 @@
 
       Free (X);
 
+ end Delete_Internal;
+
+
+ procedure Delete (Container : in out List;
+ Position : in out Cursor;
+ Count : in Size_Type := 1) is
+
+ N : Size_Type'Base := Count;
+
+ begin
+
+ while Position /= No_Element
+ and then N > 0
+ loop
+ Delete_Internal (Container, Position);
+ N := N - 1;
+ end loop;
+
    end Delete;
 
 
- procedure Delete_First (Container : in out List) is
+ procedure Delete_First (Container : in out List;
+ Count : in Size_Type := 1) is
+
       Position : Cursor := First (Container);
    begin
- Delete (Container, Position);
+ Delete (Container, Position, Count);
    end;
 
 
- procedure Delete_Last (Container : in out List) is
+ procedure Delete_Last (Container : in out List;
+ Count : in Size_Type := 1) is
+
       Position : Cursor := Last (Container);
    begin
- Delete (Container, Position);
+ Delete (Container, Position, Count);
    end;
 
 
@@ -293,49 +282,86 @@
    end Insert_Internal;
 
 
- procedure Insert
- (Container : in out List;
+ procedure Insert (Container : in out List;
       Before : in Cursor;
       New_Item : in Element_Type;
- Position : out Cursor) is
+ Position : out Cursor;
+ Count : in Size_Type := 1) is
+
+ New_Node : Node_Access;
 
- New_Node : constant Node_Access := new Node_Type'(New_Item, null, null);
    begin
+
+ if Count = 0 then
+ Position := Before;
+ return;
+ end if;
+
+ New_Node := new Node_Type'(New_Item, null, null);
       Insert_Internal (Container, Node_Access (Before), New_Node);
+
       Position := Cursor (New_Node);
- end;
 
+ for I in Size_Type'(2) .. Count loop
+ New_Node := new Node_Type'(New_Item, null, null);
+ Insert_Internal (Container, Node_Access (Before), New_Node);
+ end loop;
+
+ end Insert;
 
- procedure Prepend
- (Container : in out List;
- New_Item : in Element_Type) is
 
- New_Node : constant Node_Access := new Node_Type'(New_Item, null, null);
+ procedure Insert (Container : in out List;
+ Before : in Cursor;
+ New_Item : in Element_Type;
+ Count : in Size_Type := 1) is
+
+ Position : Cursor;
    begin
- Insert_Internal (Container, Container.First, New_Node);
+ Insert (Container, Before, New_Item, Position, Count);
    end;
 
 
- procedure Append
- (Container : in out List;
- New_Item : in Element_Type) is
+ procedure Prepend (Container : in out List;
+ New_Item : in Element_Type;
+ Count : in Size_Type := 1) is
+ begin
+ Insert (Container, First (Container), New_Item, Count);
+ end;
 
- New_Node : constant Node_Access := new Node_Type'(New_Item, null, null);
+
+ procedure Append (Container : in out List;
+ New_Item : in Element_Type;
+ Count : in Size_Type := 1) is
    begin
- Insert_Internal (Container, null, New_Node);
+ Insert (Container, No_Element, New_Item, Count);
    end;
 
 
- procedure Insert
- (Container : in out List;
+ procedure Insert (Container : in out List;
       Before : in Cursor;
- Position : out Cursor) is
+ Position : out Cursor;
+ Count : in Size_Type := 1) is
+
+ New_Node : Node_Access;
 
- New_Node : constant Node_Access := new Node_Type;
    begin
+
+ if Count = 0 then
+ Position := Before;
+ return;
+ end if;
+
+ New_Node := new Node_Type;
       Insert_Internal (Container, Node_Access (Before), New_Node);
+
       Position := Cursor (New_Node);
- end;
+
+ for I in Size_Type'(2) .. Count loop
+ New_Node := new Node_Type;
+ Insert_Internal (Container, Node_Access (Before), New_Node);
+ end loop;
+
+ end Insert;
 
 
    procedure Generic_Delete (Container : in out List) is
@@ -344,7 +370,7 @@
 
    begin
 
- while I /= Null_Cursor loop
+ while I /= null loop
 
          if Predicate (I.Element) then
             Delete (Container, Position => I);
@@ -375,7 +401,7 @@
    end;
 
 
- procedure Reverse_Container (Container : in out List) is
+ procedure Reverse_List (Container : in out List) is
 
       procedure Swap (L, R : Node_Access) is
 
@@ -456,7 +482,7 @@
       pragma Assert (Container.First.Prev = null);
       pragma Assert (Container.Last.Next = null);
 
- end Reverse_Container;
+ end Reverse_List;
 
 
    function First
@@ -536,9 +562,9 @@
    end Generic_Reverse_Iteration;
 
 
- function Generic_Find
- (Container : List;
- Position : Cursor := Null_Cursor) return Cursor is
+ function Generic_Find (Container : List;
+ Position : Cursor := No_Element)
+ return Cursor is
 
       Node : Node_Access := Node_Access (Position);
 
@@ -558,15 +584,15 @@
 
       end loop;
 
- return Null_Cursor;
+ return No_Element;
 
    end Generic_Find;
 
 
- function Find
- (Container : List;
+ function Find (Container : List;
       Item : Element_Type;
- Position : Cursor := Null_Cursor) return Cursor is
+ Position : Cursor := No_Element)
+ return Cursor is
 
       function Predicate (Element : Element_Type) return Boolean is
          pragma Inline (Predicate);
@@ -585,13 +611,13 @@
      (Item : Element_Type;
       Container : List) return Boolean is
    begin
- return Find (Container, Item) /= Null_Cursor;
+ return Find (Container, Item) /= No_Element;
    end;
 
 
    function Generic_Reverse_Find
      (Container : List;
- Position : Cursor := Null_Cursor) return Cursor is
+ Position : Cursor := No_Element) return Cursor is
 
       Node : Node_Access := Node_Access (Position);
 
@@ -611,7 +637,7 @@
 
       end loop;
 
- return Null_Cursor;
+ return No_Element;
 
    end Generic_Reverse_Find;
 
@@ -619,7 +645,7 @@
    function Reverse_Find
      (Container : List;
       Item : Element_Type;
- Position : Cursor := Null_Cursor) return Cursor is
+ Position : Cursor := No_Element) return Cursor is
 
       function Predicate (Element : Element_Type) return Boolean is
          pragma Inline (Predicate);
@@ -635,42 +661,42 @@
 
 
    procedure Splice
- (Container : in out List;
+ (Target : in out List;
       Before : in Cursor;
       Source : in out List) is
 
    begin
 
- if Container'Address = Source'Address
+ if Target'Address = Source'Address
         or else Source.Length = 0
       then
          return;
       end if;
 
- if Container.Length = 0 then
+ if Target.Length = 0 then
 
- pragma Assert (Before = Null_Cursor);
+ pragma Assert (Before = No_Element);
 
- Container.First := Source.First;
- Container.Last := Source.Last;
+ Target.First := Source.First;
+ Target.Last := Source.Last;
 
- elsif Before = Null_Cursor then
+ elsif Before = No_Element then
 
- pragma Assert (Container.Last.Next = null);
+ pragma Assert (Target.Last.Next = null);
 
- Container.Last.Next := Source.First;
- Source.First.Prev := Container.Last;
+ Target.Last.Next := Source.First;
+ Source.First.Prev := Target.Last;
 
- Container.Last := Source.Last;
+ Target.Last := Source.Last;
 
- elsif Node_Access (Before) = Container.First then
+ elsif Node_Access (Before) = Target.First then
 
- pragma Assert (Container.First.Prev = null);
+ pragma Assert (Target.First.Prev = null);
 
- Source.Last.Next := Container.First;
- Container.First.Prev := Source.Last;
+ Source.Last.Next := Target.First;
+ Target.First.Prev := Source.Last;
 
- Container.First := Source.First;
+ Target.First := Source.First;
 
       else
 
@@ -685,14 +711,14 @@
       Source.First := null;
       Source.Last := null;
 
- Container.Length := Container.Length + Source.Length;
+ Target.Length := Target.Length + Source.Length;
       Source.Length := 0;
 
    end Splice;
 
 
    procedure Splice
- (Container : in out List;
+ (Target : in out List;
       Before : in Cursor;
       Position : in Cursor) is
 
@@ -707,61 +733,61 @@
          return;
       end if;
 
- pragma Assert (Container.Length > 0);
+ pragma Assert (Target.Length > 0);
 
- if Before = Null_Cursor then
+ if Before = No_Element then
 
- pragma Assert (X /= Container.Last);
+ pragma Assert (X /= Target.Last);
 
- if X = Container.First then
- Container.First := X.Next;
- Container.First.Prev := null;
+ if X = Target.First then
+ Target.First := X.Next;
+ Target.First.Prev := null;
          else
             X.Prev.Next := X.Next;
             X.Next.Prev := X.Prev;
          end if;
 
- Container.Last.Next := X;
- X.Prev := Container.Last;
+ Target.Last.Next := X;
+ X.Prev := Target.Last;
 
- Container.Last := X;
- Container.Last.Next := null;
+ Target.Last := X;
+ Target.Last.Next := null;
 
          return;
 
       end if;
 
- if Node_Access (Before) = Container.First then
+ if Node_Access (Before) = Target.First then
 
- pragma Assert (X /= Container.First);
+ pragma Assert (X /= Target.First);
 
- if X = Container.Last then
- Container.Last := X.Prev;
- Container.Last.Next := null;
+ if X = Target.Last then
+ Target.Last := X.Prev;
+ Target.Last.Next := null;
          else
             X.Prev.Next := X.Next;
             X.Next.Prev := X.Prev;
          end if;
 
- Container.First.Prev := X;
- X.Next := Container.First;
+ Target.First.Prev := X;
+ X.Next := Target.First;
 
- Container.First := X;
- Container.First.Prev := null;
+ Target.First := X;
+ Target.First.Prev := null;
 
          return;
 
       end if;
 
- if X = Container.First then
+ if X = Target.First then
 
- Container.First := X.Next;
- Container.First.Prev := null;
+ Target.First := X.Next;
+ Target.First.Prev := null;
 
- elsif X = Container.Last then
+ elsif X = Target.Last then
 
- Container.Last := X.Prev;
- Container.Last.Next := null;
+ Target.Last := X.Prev;
+ Target.Last.Next := null;
 
       else
 
@@ -780,7 +806,7 @@
 
 
    procedure Splice
- (Container : in out List;
+ (Target : in out List;
       Before : in Cursor;
       Source : in out List;
       Position : in Cursor) is
@@ -789,8 +815,8 @@
 
    begin
 
- if Container'Address = Source'Address then
- Splice (Container, Before, Position);
+ if Target'Address = Source'Address then
+ Splice (Target, Before, Position);
          return;
       end if;
 
@@ -825,30 +851,30 @@
 
       end if;
 
- if Container.Length = 0 then
+ if Target.Length = 0 then
 
- pragma Assert (Before = Null_Cursor);
- pragma Assert (Container.First = null);
- pragma Assert (Container.Last = null);
+ pragma Assert (Before = No_Element);
+ pragma Assert (Target.First = null);
+ pragma Assert (Target.Last = null);
 
- Container.First := X;
- Container.Last := X;
+ Target.First := X;
+ Target.Last := X;
 
- elsif Before = Null_Cursor then
+ elsif Before = No_Element then
 
- Container.Last.Next := X;
- X.Next := Container.Last;
+ Target.Last.Next := X;
+ X.Next := Target.Last;
 
- Container.Last := X;
- Container.Last.Next := null;
+ Target.Last := X;
+ Target.Last.Next := null;
 
- elsif Node_Access (Before) = Container.First then
+ elsif Node_Access (Before) = Target.First then
 
- Container.First.Prev := X;
- X.Next := Container.First;
+ Target.First.Prev := X;
+ X.Next := Target.First;
 
- Container.First := X;
- Container.First.Prev := null;
+ Target.First := X;
+ Target.First.Prev := null;
 
       else
 
@@ -860,7 +886,7 @@
 
       end if;
 
- Container.Length := Container.Length + 1;
+ Target.Length := Target.Length + 1;
       Source.Length := Source.Length - 1;
 
    end Splice;
@@ -890,60 +916,23 @@
    end;
 
 
- procedure Generic_Delete_Duplicates
- (Container : in out List) is
-
- I : Cursor := First (Container);
- J : Cursor;
-
- begin
-
- if I = Null_Cursor then
- return;
- end if;
-
- J := Next (I);
-
- while J /= Null_Cursor loop
-
- if Predicate (I.Element, J.Element) then
- Delete (Container, Position => J);
- else
- I := J;
- J := Next (I);
- end if;
-
- end loop;
-
- end Generic_Delete_Duplicates;
-
-
- procedure Delete_Duplicates (Container : in out List) is
-
- procedure Delete_Equal is
- new Generic_Delete_Duplicates (Predicate => "=");
- begin
- Delete_Equal (Container);
- end;
-
-
    procedure Generic_Merge
- (Container : in out List;
+ (Target : in out List;
       Source : in out List) is
 
- LI : Cursor := First (Container);
+ LI : Cursor := First (Target);
       RI : Cursor := First (Source);
 
    begin
 
- if Container'Address = Source'Address then
+ if Target'Address = Source'Address then
          return;
       end if;
 
- while RI /= Null_Cursor loop
+ while RI /= No_Element loop
 
- if LI = Null_Cursor then
- Splice (Container, Null_Cursor, Source);
+ if LI = No_Element then
+ Splice (Target, No_Element, Source);
             return;
          end if;
 
@@ -953,7 +942,7 @@
                RJ : constant Cursor := RI;
             begin
                RI := Next (RI);
- Splice (Container, LI, Source, RJ);
+ Splice (Target, LI, Source, RJ);
             end;
 
          else
@@ -1124,6 +1113,86 @@
       end loop;
 
    end Write;
+
+
+ procedure Move (Target : in out List;
+ Source : in out List) is
+ begin
+
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ if Target.Length > 0 then
+ raise Constraint_Error;
+ end if;
+
+ Target.First := Source.First;
+ Source.First := null;
+
+ Target.Last := Source.Last;
+ Source.Last := null;
+
+ Target.Length := Source.Length;
+ Source.Length := 0;
+
+ end Move;
+
+
+ procedure Swap (Container : in out List;
+ I, J : in Cursor) is
+ begin
+
+ if I = null then
+ if J = null then
+ return; --NOTE: these semantics are allowed?
+ end if;
+
+ raise Constraint_Error;
+ end if;
+
+ if J = null then
+ raise Constraint_Error;
+ end if;
+
+ pragma Assert (Container.Length >= 1);
+
+ if I = J then
+ return;
+ end if;
+
+ pragma Assert (Container.Length >= 2);
+
+ declare
+ I_Next : constant Cursor := Next (I);
+ begin
+
+ if I_Next = J then
+
+ Splice (Container, Before => I, Position => J);
+
+ declare
+ J_Next : constant Cursor := Next (J);
+ begin
+
+ if J_Next = I then
+
+ Splice (Container, Before => J, Position => I);
+
+ else
+
+ Splice (Container, Before => I_Next, Position => J);
+ Splice (Container, Before => J_Next, Position => I);
+
+ end if;
+
+ end;
+
+ end if;
+
+ end;
+
+ end Swap;
 
 
 end AI302.Containers.Dou​bly_Linked_Lists;




--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: cvs-unsubscribe@char​les.tigris.org
For additional commands, e-mail: cvs-help at charles dot tigris dot org

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /charles/src/ai302/ matthewjheaney Matthew Heaney 2004-05-16 10:37:57 PDT
Messages per page: