Руководство по Ada (Ada 2022)
A.18.30 Обобщённый пакет Containers.Unbounded_Priority_Queues
Статическая семантика
Определяемый языком обобщённый пакет Containers.Unbounded_Priority_Queues предоставляет тип Queue, реализующий интерфейсный тип Containers.Synchronized_Queue_Interfaces.Queue.
with System;
with Ada.Containers.Synchronized_Queue_Interfaces;
generic
with package Queue_Interfaces is
new Ada.Containers.Synchronized_Queue_Interfaces (<>);
type Queue_Priority is private;
with function Get_Priority
(Element : Queue_Interfaces.Element_Type) return Queue_Priority is <>;
with function Before
(Left, Right : Queue_Priority) return Boolean is <>;
Default_Ceiling : System.Any_Priority := System.Priority'Last;
package Ada.Containers.Unbounded_Priority_Queues
with Preelaborate,
Nonblocking, Global => in out synchronized is
with Ada.Containers.Synchronized_Queue_Interfaces;
generic
with package Queue_Interfaces is
new Ada.Containers.Synchronized_Queue_Interfaces (<>);
type Queue_Priority is private;
with function Get_Priority
(Element : Queue_Interfaces.Element_Type) return Queue_Priority is <>;
with function Before
(Left, Right : Queue_Priority) return Boolean is <>;
Default_Ceiling : System.Any_Priority := System.Priority'Last;
package Ada.Containers.Unbounded_Priority_Queues
with Preelaborate,
Nonblocking, Global => in out synchronized is
package Implementation is
... -- не определено языком
end Implementation;
... -- не определено языком
end Implementation;
protected type Queue
(Ceiling : System.Any_Priority := Default_Ceiling)
with Priority => Ceiling is
new Queue_Interfaces.Queue with
(Ceiling : System.Any_Priority := Default_Ceiling)
with Priority => Ceiling is
new Queue_Interfaces.Queue with
overriding
entry Enqueue (New_Item : in Queue_Interfaces.Element_Type);
overriding
entry Dequeue (Element : out Queue_Interfaces.Element_Type);
entry Enqueue (New_Item : in Queue_Interfaces.Element_Type);
overriding
entry Dequeue (Element : out Queue_Interfaces.Element_Type);
not overriding
procedure Dequeue_Only_High_Priority
(At_Least : in Queue_Priority;
Element : in out Queue_Interfaces.Element_Type;
Success : out Boolean);
procedure Dequeue_Only_High_Priority
(At_Least : in Queue_Priority;
Element : in out Queue_Interfaces.Element_Type;
Success : out Boolean);
overriding
function Current_Use return Count_Type
with Nonblocking, Global => null, Use_Formal => null;
overriding
function Peak_Use return Count_Type
with Nonblocking, Global => null, Use_Formal => null;
function Current_Use return Count_Type
with Nonblocking, Global => null, Use_Formal => null;
overriding
function Peak_Use return Count_Type
with Nonblocking, Global => null, Use_Formal => null;
private
... -- не определено языком
end Queue;
... -- не определено языком
end Queue;
private
... -- не определено языком
end Ada.Containers.Unbounded_Priority_Queues;
Тип Queue используется для представления безопасных для задач приоритетных очередей.
Ёмкость экземпляров типа Queue неограничена.
Два элемента E1 и E2 эквивалентны, если Before(Get_Priority(E1), Get_Priority(E2)) и Before(Get_Priority(E2), Get_Priority(E1)) оба возвращают False.
Ожидается, что фактические функции Get_Priority и Before каждый раз возвращают одинаковое значение при вызове с одинаковыми фактическими аргументами и не должны изменять свои фактические аргументы. Before должен определять отношение строгой слабой упорядоченности (см. A.18). Если фактические функции ведут себя по-другому, поведение Unbounded_Priority_Queues не определено.
Enqueue вставляет элемент в соответствии с порядком, заданным функцией Before по результату Get_Priority для элементов; Before должно возвращать True, если Left должен быть вставлен перед Right. Если очередь уже содержит элементы, эквивалентные New_Item, то он вставляется после существующих эквивалентных элементов.
При вызове Dequeue_Only_High_Priority, если голова непустой очереди — E, и функция Before(At_Least, Get_Priority(E)) возвращает False, то E присваивается Element, а затем удаляется из очереди, и Success устанавливается в True; в противном случае Success устанавливается в False, и Element не изменяется.