summaryrefslogtreecommitdiff
path: root/gcc/ada/a-ciorse.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2006-10-31 18:13:22 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2006-10-31 18:13:22 +0000
commitd9e74e050bd1ae08f4be72f63784a42c0973a94a (patch)
tree1a5cb845f084a8360d6f2bc2dd674427a1a51b02 /gcc/ada/a-ciorse.adb
parentad67c992e9102a7a00351747f46956e56b6f0c3f (diff)
downloadgcc-d9e74e050bd1ae08f4be72f63784a42c0973a94a.tar.gz
2006-10-31 Matt Heaney <heaney@adacore.com>
* a-crbtgo.ads: Commented each subprogram * a-crbtgo.adb: Added reference to book from which algorithms were adapted. * a-crbtgk.ads, a-crbtgk.adb (Generic_Insert_Post): pass flag to indicate which child. (Generic_Conditional_Insert): changed parameter name from "Success" to "Inserted". (Generic_Unconditional_Insert_With_Hint): improved algorithm * a-coorse.adb (Replace_Element): changed parameter name in call to conditional insert operation. * a-convec.adb, a-coinve.adb (Insert): removed obsolete comment * a-cohama.adb (Iterate): manipulate busy-bit here, instead of in Generic_Iteration * a-ciorse.adb (Replace_Element): changed parameter name in call to conditional insert operation. * a-cihama.adb (Iterate): manipulate busy-bit here, instead of in Generic_Iteration. * a-cidlli.ads, a-cidlli.adb (Splice): Position param is now mode in instead of mode inout. * a-chtgop.adb (Adjust): modified comments to reflect current AI-302 draft (Generic_Read): preserve existing buckets array if possible (Generic_Write): don't send buckets array length anymore * a-cdlili.ads, a-cdlili.adb (Splice): Position param is now mode in instead of mode inout. * a-cihase.adb (Difference): iterate over smaller of Tgt and Src sets (Iterate): manipulate busy-bit here, instead of in Generic_Iteration * a-cohase.adb (Difference): iterate over smaller of Tgt and Src sets (Iterate): manipulate busy-bit here, instead of in Generic_Iteration (Replace_Element): local operation is now an instantiation * a-chtgke.ads, a-chtgke.adb (Generic_Conditional_Insert): manually check current length. (Generic_Replace_Element): new operation git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@118324 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-ciorse.adb')
-rw-r--r--gcc/ada/a-ciorse.adb163
1 files changed, 69 insertions, 94 deletions
diff --git a/gcc/ada/a-ciorse.adb b/gcc/ada/a-ciorse.adb
index 0e11e6506ed..adc34abf950 100644
--- a/gcc/ada/a-ciorse.adb
+++ b/gcc/ada/a-ciorse.adb
@@ -7,11 +7,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 2004-2005, Free Software Foundation, Inc. --
--- --
--- This specification is derived from the Ada Reference Manual for use with --
--- GNAT. The copyright notice above, and the license provisions that follow --
--- apply solely to the contents of the part following the private keyword. --
+-- Copyright (C) 2004-2006, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -1463,121 +1459,100 @@ package body Ada.Containers.Indefinite_Ordered_Sets is
Node : Node_Access;
Item : Element_Type)
is
+ pragma Assert (Node /= null);
+ pragma Assert (Node.Element /= null);
+
+ function New_Node return Node_Access;
+ pragma Inline (New_Node);
+
+ procedure Local_Insert_Post is
+ new Element_Keys.Generic_Insert_Post (New_Node);
+
+ procedure Local_Insert_Sans_Hint is
+ new Element_Keys.Generic_Conditional_Insert (Local_Insert_Post);
+
+ procedure Local_Insert_With_Hint is
+ new Element_Keys.Generic_Conditional_Insert_With_Hint
+ (Local_Insert_Post,
+ Local_Insert_Sans_Hint);
+
+ --------------
+ -- New_Node --
+ --------------
+
+ function New_Node return Node_Access is
+ begin
+ Node.Element := new Element_Type'(Item); -- OK if fails
+ Node.Color := Red;
+ Node.Parent := null;
+ Node.Right := null;
+ Node.Left := null;
+
+ return Node;
+ end New_Node;
+
+ Hint : Node_Access;
+ Result : Node_Access;
+ Inserted : Boolean;
+
+ X : Element_Access := Node.Element;
+
+ -- Start of processing for Insert
+
begin
if Item < Node.Element.all
or else Node.Element.all < Item
then
null;
+
else
if Tree.Lock > 0 then
raise Program_Error with
"attempt to tamper with cursors (set is locked)";
end if;
- declare
- X : Element_Access := Node.Element;
- begin
- Node.Element := new Element_Type'(Item);
- Free_Element (X);
- end;
+ Node.Element := new Element_Type'(Item);
+ Free_Element (X);
return;
end if;
- Tree_Operations.Delete_Node_Sans_Free (Tree, Node); -- Checks busy-bit
-
- Insert_New_Item : declare
- function New_Node return Node_Access;
- pragma Inline (New_Node);
-
- procedure Insert_Post is
- new Element_Keys.Generic_Insert_Post (New_Node);
-
- procedure Insert is
- new Element_Keys.Generic_Conditional_Insert (Insert_Post);
-
- --------------
- -- New_Node --
- --------------
-
- function New_Node return Node_Access is
- begin
- Node.Element := new Element_Type'(Item); -- OK if fails
- Node.Color := Red;
- Node.Parent := null;
- Node.Right := null;
- Node.Left := null;
-
- return Node;
- end New_Node;
+ Hint := Element_Keys.Ceiling (Tree, Item);
- Result : Node_Access;
- Inserted : Boolean;
-
- X : Element_Access := Node.Element;
+ if Hint = null then
+ null;
- -- Start of processing for Insert_New_Item
+ elsif Item < Hint.Element.all then
+ if Hint = Node then
+ if Tree.Lock > 0 then
+ raise Program_Error with
+ "attempt to tamper with cursors (set is locked)";
+ end if;
- begin
- Attempt_Insert : begin
- Insert
- (Tree => Tree,
- Key => Item,
- Node => Result,
- Success => Inserted); -- TODO: change name of formal param
- exception
- when others =>
- Inserted := False;
- end Attempt_Insert;
+ Node.Element := new Element_Type'(Item);
+ Free_Element (X);
- if Inserted then
- pragma Assert (Result = Node);
- Free_Element (X); -- OK if fails
return;
end if;
- end Insert_New_Item;
-
- Reinsert_Old_Element : declare
- function New_Node return Node_Access;
- pragma Inline (New_Node);
-
- procedure Insert_Post is
- new Element_Keys.Generic_Insert_Post (New_Node);
-
- procedure Insert is
- new Element_Keys.Generic_Conditional_Insert (Insert_Post);
-
- --------------
- -- New_Node --
- --------------
-
- function New_Node return Node_Access is
- begin
- Node.Color := Red;
- Node.Parent := null;
- Node.Right := null;
- Node.Left := null;
- return Node;
- end New_Node;
+ else
+ pragma Assert (not (Hint.Element.all < Item));
+ raise Program_Error with "attempt to replace existing element";
+ end if;
- Result : Node_Access;
- Inserted : Boolean;
+ Tree_Operations.Delete_Node_Sans_Free (Tree, Node); -- Checks busy-bit
- -- Start of processing for Reinsert_Old_Element
+ Local_Insert_With_Hint
+ (Tree => Tree,
+ Position => Hint,
+ Key => Item,
+ Node => Result,
+ Inserted => Inserted);
- begin
- Insert
- (Tree => Tree,
- Key => Node.Element.all,
- Node => Result,
- Success => Inserted); -- TODO: change name of formal param
- exception
- when others =>
- null;
- end Reinsert_Old_Element;
+ pragma Assert (Inserted);
+ pragma Assert (Result = Node);
- raise Program_Error with "attempt to replace existing element";
+ Free_Element (X);
end Replace_Element;
procedure Replace_Element