1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.BOUNDED_PRIORITY_QUEUES --
9 -- Copyright (C) 2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- This unit was originally developed by Matthew J Heaney. --
28 ------------------------------------------------------------------------------
30 package body Ada.Containers.Bounded_Priority_Queues is
32 package body Implementation is
39 (List : in out List_Type;
40 Element : out Queue_Interfaces.Element_Type)
43 Element := List.Container.First_Element;
44 List.Container.Delete_First;
48 (List : in out List_Type;
49 At_Least : Queue_Priority;
50 Element : in out Queue_Interfaces.Element_Type;
51 Success : out Boolean)
55 or else not Before (At_Least, Get_Priority (List.First_Element))
61 List.Dequeue (Element);
70 (List : in out List_Type;
71 New_Item : Queue_Interfaces.Element_Type)
73 P : constant Queue_Priority := Get_Priority (New_Item);
75 C : List_Types.Cursor;
81 C := List.Container.First;
82 while Has_Element (C) loop
84 -- if Before (P, Get_Priority (List.Constant_Reference (C))) then
85 if Before (P, Get_Priority (Element (C))) then
86 List.Container.Insert (C, New_Item);
93 if not Has_Element (C) then
94 List.Container.Append (New_Item);
97 Count := List.Container.Length;
99 if Count > List.Max_Length then
100 List.Max_Length := Count;
108 function First_Element
109 (List : List_Type) return Queue_Interfaces.Element_Type
112 -- Use Constant_Reference for this. ???
113 return List.Container.First_Element;
120 function Length (List : List_Type) return Count_Type is
122 return List.Container.Length;
129 function Max_Length (List : List_Type) return Count_Type is
131 return List.Max_Length;
136 protected body Queue is
142 function Current_Use return Count_Type is
151 entry Dequeue (Element : out Queue_Interfaces.Element_Type)
155 List.Dequeue (Element);
158 --------------------------------
159 -- Dequeue_Only_High_Priority --
160 --------------------------------
162 procedure Dequeue_Only_High_Priority
163 (At_Least : Queue_Priority;
164 Element : in out Queue_Interfaces.Element_Type;
165 Success : out Boolean)
168 List.Dequeue (At_Least, Element, Success);
169 end Dequeue_Only_High_Priority;
175 entry Enqueue (New_Item : Queue_Interfaces.Element_Type)
176 when List.Length < Capacity
179 List.Enqueue (New_Item);
186 function Peak_Use return Count_Type is
188 return List.Max_Length;
193 end Ada.Containers.Bounded_Priority_Queues;