diff options
author | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-12-21 13:51:03 +0000 |
---|---|---|
committer | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-12-21 13:51:03 +0000 |
commit | 192b8dab8a1e8131634b977cce11e6eca8447540 (patch) | |
tree | 3954a53c4489b3a57bd7059ad7f7285d618d3db4 /gcc/ada/a-rbtgbk.adb | |
parent | d8ba53a8b11f4d7bcc5c54d6e2ad76cbebffb09d (diff) | |
download | gcc-192b8dab8a1e8131634b977cce11e6eca8447540.tar.gz |
2011-12-21 Vincent Celier <celier@adacore.com>
* prj-nmsc.adb (Report_No_Sources): Remove argument Lang. Report
no sources even for languages that are not allowed.
(Add_Source): Get the source even when the language is not allowed.
2011-12-21 Robert Dewar <dewar@adacore.com>
* sem_ch6.adb (Process_Formals): Add defensive code.
2011-12-21 Ed Schonberg <schonberg@adacore.com>
* sem_ch7.adb, sem_ch13.adb (Analyze_Package_Specification): Build the
invariant procedure of a type declaration that is a completion and has
aspect specifications.
(Build_Invariant_Procedure): If the procedure is built for a
type declaration that is a completion, analyze body expliitly
because all private declarations have been already analyzed.
2011-12-21 Claire Dross <dross@adacore.com>
* a-cfdlli.adb, a-cfhase.adb, a-cforma.adb, a-cforse.adb,
a-cofove.adb: Minor reformating on formal containers
2011-12-21 Vincent Celier <celier@adacore.com>
* makeutl.adb (Mains.Complete_Mains.Do_Complete): Remove
any main that is not in the list of restricted languages.
(Insert_Project_Sources.Do_Insert): Only add sources of languages
in the list of restricted languages.
2011-12-21 Ed Schonberg <schonberg@adacore.com>
* sem_res.adb (Valid_Conversion): A type conversion is valid when
the target type is an anonymous access type and the operand is a
rewriting of an allocator. The conversion is typically inserted
when the designated type is an interface.
2011-12-21 Ed Schonberg <schonberg@adacore.com>
* exp_ch9.adb (Establish_Task_Master): If the enclosing block
has no declarations, create new declarative list for it.
2011-12-21 Matthew Heaney <heaney@adacore.com>
* a-rbtgbk.adb (Generic_Conditional_Insert): Fixed incorrect comment.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182586 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-rbtgbk.adb')
-rw-r--r-- | gcc/ada/a-rbtgbk.adb | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/gcc/ada/a-rbtgbk.adb b/gcc/ada/a-rbtgbk.adb index b12ae841076..e270abf1402 100644 --- a/gcc/ada/a-rbtgbk.adb +++ b/gcc/ada/a-rbtgbk.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2004-2010, Free Software Foundation, Inc. -- +-- Copyright (C) 2004-2011, 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- -- @@ -140,8 +140,22 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Keys is N : Nodes_Type renames Tree.Nodes; begin - Y := 0; + -- This is a "conditional" insertion, meaning that the insertion request + -- can "fail" in the sense that no new node is created. If the Key is + -- equivalent to an existing node, then we return the existing node and + -- Inserted is set to False. Otherwise, we allocate a new node (via + -- Insert_Post) and Inserted is set to True. + + -- Note that we are testing for equivalence here, not equality. Key must + -- be strictly less than its next neighbor, and strictly greater than + -- its previous neighbor, in order for the conditional insertion to + -- succeed. + + -- We search the tree to find the nearest neighbor of Key, which is + -- either the smallest node greater than Key (Inserted is True), or the + -- largest node less or equivalent to Key (Inserted is False). + Y := 0; X := Tree.Root; Inserted := True; while X /= 0 loop @@ -150,33 +164,50 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Keys is X := (if Inserted then Ops.Left (N (X)) else Ops.Right (N (X))); end loop; - -- If Inserted is True, then this means either that Tree is - -- empty, or there was a least one node (strictly) greater than - -- Key. Otherwise, it means that Key is equal to or greater than - -- every node. - if Inserted then + + -- Either Tree is empty, or Key is less than Y. If Y is the first + -- node in the tree, then there are no other nodes that we need to + -- search for, and we insert a new node into the tree. + if Y = Tree.First then Insert_Post (Tree, Y, True, Node); return; end if; + -- Y is the next nearest-neighbor of Key. We know that Key is not + -- equivalent to Y (because Key is strictly less than Y), so we move + -- to the previous node, the nearest-neighbor just smaller or + -- equivalent to Key. + Node := Ops.Previous (Tree, Y); else + -- Y is the previous nearest-neighbor of Key. We know that Key is not + -- less than Y, which means either that Key is equivalent to Y, or + -- greater than Y. + Node := Y; end if; - -- Here Node has a value that is less than or equal to Key. We - -- now have to resolve whether Key is equal to or greater than - -- Node, which determines whether the insertion succeeds. + -- Key is equivalent to or greater than Node. We must resolve which is + -- the case, to determine whether the conditional insertion succeeds. if Is_Greater_Key_Node (Key, N (Node)) then + + -- Key is strictly greater than Node, which means that Key is not + -- equivalent to Node. In this case, the insertion succeeds, and we + -- insert a new node into the tree. + Insert_Post (Tree, Y, Inserted, Node); Inserted := True; return; end if; + -- Key is equivalent to Node. This is a conditional insertion, so we do + -- not insert a new node in this case. We return the existing node and + -- report that no insertion has occurred. + Inserted := False; end Generic_Conditional_Insert; |