Login | Register
My pages Projects Community openCollabNet

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

charles
Discussion topic

Back to topic list

CVS update: /charles/src/

Reply

Author matthewjheaney
Full name Matthew Heaney
Date 2004-07-12 20:02:21 PDT
Message User: matthewjheaney
Date: 04/07/12 20:02:21

Modified:
 /charles/src/
  charles-deques-unbounded.adb

Log:
 implemented prepend

File Changes:

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

File [changed]: charles-deques-unbounded.adb
Url: http://charles.tigri​s.org/source/browse/​charles/src/charles-​deques-unbounded.adb​?r1=1.4&r2=1.5
Delta lines: +203 -48
----------------------
--- charles-deques-unbounded.adb 11 Jul 2004 17:41:06 -0000 1.4
+++ charles-deques-unbounded.adb 13 Jul 2004 03:02:21 -0000 1.5
@@ -127,7 +127,10 @@
       Node_Index : out Positive;
       Element_Index : out Element_Index_Subtype) is
 
- I : constant Integer'Base := Container.Bias + Index;
+ subtype Index_Subtype is
+ Natural range 0 .. Container.Length - 1;
+
+ I : constant Integer'Base := Container.Bias + Index_Subtype'(Index);
 
       NI : constant Integer'Base := Container.First + I / Elements_Per_Node;
 
@@ -422,83 +425,227 @@
 
 
 
+ procedure Prepend
+ (Container : in out Container_Type;
+ Element_Index : out Element_Index_Subtype) is
+
+ begin
+
+ if Container.Last < Container.First then
+
+ pragma Assert (Container.Length = 0);
+
+ if Container.Nodes = null then
+ Container.Nodes := new Node_Access_Array (1 .. 1); --?
+ end if;
+
+ declare
+ I : constant Positive := 1 + Container.Nodes'Length / 2; --?
+ begin
+ Container.Nodes (I) := new Node_Type;
+ Container.First := I;
+ end;
+
+ Container.Last := Container.First;
+ Container.Length := 1;
+
+ --assume this prepend will be followed by more prepends:
+ Container.Bias := Elements_Per_Node - 1;
+ Element_Index := Container.Bias;
+
+ return;
+
+ end if;
+
+ pragma Assert (Container.Length > 0);
+
+ if Container.Bias > 0 then
+
+ Container.Length := Container.Length + 1;
+
+ Container.Bias := Container.Bias - 1;
+ Element_Index := Container.Bias;
+
+ return;
+
+ end if;
+
+ if Container.First > 1 then
+
+ declare
+ Length : constant Positive := Container.Length + 1;
+ I : constant Positive := Container.First - 1;
+ begin
+ Container.Nodes (I) := new Node_Type;
+ Container.First := I;
+ Container.Length := Length;
+ end;
+
+ Container.Bias := Elements_Per_Node - 1;
+ Element_Index := Container.Bias;
+
+ return;
+
+ end if;
+
+ if Container.Last < Container.Nodes'Last then
+
+ declare
+ Length : constant Positive := Container.Length + 1;
+ Node : constant Node_Access := new Node_Type;
+
+ N : constant Positive := Container.Nodes'Last - Container.Last;
+ I : constant Positive := (N + 1) / 2; --?
+ J : constant Positive := I + Container.Last;
+ begin
+ Container.Nodes (I + 1 .. J) :=
+ Container.Nodes (1 .. Container.Last);
+
+ Container.Nodes (I) := Node;
+
+ Container.First := I;
+ Container.Last := J;
+ Container.Length := Length;
+ end;
+
+ Container.Bias := Elements_Per_Node - 1;
+ Element_Index := Container.Bias;
+
+ return;
+
+ end if;
+
+ declare
+ Length : constant Positive := Container.Length + 1;
+
+ Nodes_Last : constant Positive := 2 * Container.Nodes'Length;
+
+ Nodes : constant Node_Access_Array_Access :=
+ new Node_Access_Array (1 .. Nodes_Last);
+
+ N : constant Positive := Container.Nodes'Length;
+ I : constant Positive := (N + 1) / 2; --?
+ J : constant Positive := I + Container.Last;
+ begin
+ Container.First := I + 1;
+
+ Nodes (Container.First .. J) :=
+ Container.Nodes (1 .. Container.Last);
+
+ Container.Last := J;
+
+ Free (Container.Nodes);
+ Container.Nodes := Nodes;
+
+ Container.Nodes (I) := new Node_Type;
+ Container.First := I;
+ Container.Length := Length;
+ end;
+
+ Container.Bias := Elements_Per_Node - 1;
+ Element_Index := Container.Bias;
+
+ end Prepend;
+
+
    procedure Prepend (Container : in out Container_Type) is
+ Index : Element_Index_Subtype;
    begin
- Insert (Container, Before => Index_Type'First);
+ Prepend (Container, Index);
    end;
 
 
    procedure Prepend
      (Container : in out Container_Type;
       New_Item : in Element_Type) is
+
+ Index : Element_Index_Subtype;
    begin
- Insert (Container, Before => Index_Type'First, New_Item => New_Item);
+ Prepend (Container, Index);
+ Container.Nodes (Container.First) (Index) := New_Item;
    end;
 
 
--- procedure Prepend_N
--- (Container : in out Container_Type;
--- Count : in Natural) is
--- begin
--- Insert_N (Container, First (Container), Count);
--- end;
-
-
--- procedure Prepend_N
--- (Container : in out Container_Type;
--- Count : in Natural;
--- New_Item : in Element_Type) is
--- begin
--- Insert_N (Container, First (Container), Count, New_Item);
--- end;
+ procedure Append
+ (Container : in out Container_Type;
+ Index : out Element_Index_Subtype) is
+ begin
+ null;
+ end;
 
 
    procedure Append (Container : in out Container_Type) is
+ Index : Element_Index_Subtype;
    begin
- Insert (Container, Before => Back (Container));
+ Append (Container, Index);
    end;
 
 
    procedure Append
      (Container : in out Container_Type;
       New_Item : in Element_Type) is
+
+ Index : Element_Index_Subtype;
    begin
- Insert (Container, Before => Back (Container), New_Item => New_Item);
+ Append (Container, Index);
+ Container.Nodes (Container.Last) (Index) := New_Item;
    end;
 
 
--- procedure Append_N
--- (Container : in out Container_Type;
--- Count : in Natural) is
--- begin
--- Insert_N (Container, Back (Container), Count);
--- end;
+ procedure Insert
+ (Container : in out Container_Type;
+ Before : in Index_Type'Base) is
 
+ I : constant Integer'Base := Index_Type'Pos (Before);
+ J : constant Integer'Base := Index_Type'Pos (Index_Type'First);
 
--- procedure Append_N
--- (Container : in out Container_Type;
--- Count : in Natural;
--- New_Item : in Element_Type) is
--- begin
--- Insert_N (Container, Back (Container), Count, New_Item);
--- end;
+ subtype Offset_Subtype is Natural range 0 .. Container.Length;
 
+ Offset : constant Offset_Subtype := I - J;
 
- procedure Insert
- (Container : in out Container_Type;
- Before : in Index_Type'Base) is
    begin
- Insert_N (Container, Before, Count => 1);
- end;
+
+ if Offset = 0 then
+ Prepend (Container);
+
+ elsif Offset = Container.Length then
+ Append (Container);
+
+ else
+ null; --TODO
+
+ end if;
+
+ end Insert;
 
 
    procedure Insert
      (Container : in out Container_Type;
       Before : in Index_Type'Base;
       New_Item : in Element_Type) is
+
+ I : constant Integer'Base := Index_Type'Pos (Before);
+ J : constant Integer'Base := Index_Type'Pos (Index_Type'First);
+
+ subtype Offset_Subtype is Natural range 0 .. Container.Length;
+
+ Offset : constant Offset_Subtype := I - J;
+
    begin
- Insert_N (Container, Before, Count => 1, New_Item => New_Item);
- end;
+
+ if Offset = 0 then
+ Prepend (Container, New_Item);
+
+ elsif Offset = Container.Length then
+ Append (Container, New_Item);
+
+ else
+ null; --TODO
+
+ end if;
+
+ end Insert;
+
 
 
    procedure Insert_N
@@ -506,16 +653,24 @@
       Before : in Index_Type'Base;
       Count : in Natural) is
 
--- Before_Index : constant Integer'Base :=
--- Index_Type'Pos (Before) - Index_Type'Pos (Index_Type'First);
    begin
--- Insert_N
--- (Container.Map,
--- Before_Index,
--- Count);
 
+ if Count = 0 then
+ return;
+ end if;
+
+ declare
+ I : constant Integer'Base := Index_Type'Pos (Before);
+ J : constant Integer'Base := Index_Type'Pos (Index_Type'First);
+
+ subtype Offset_Subtype is Natural range 0 .. Container.Length;
+
+ Offset : constant Offset_Subtype := I - J;
+ begin
       null; --TODO
    end;
+
+ end Insert_N;
 
 
    procedure Insert_N




--------------------​--------------------​--------------------​---------
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/ matthewjheaney Matthew Heaney 2004-07-12 20:02:21 PDT
Messages per page: