Skip to content

Queues

Synchronized Queue Interfaces#

The language-defined generic package Containers.Synchronized_Queue_Interfaces provides interface type Queue, and a set of operations for that type. Interface Queue specifies a first-in, first-out queue.

generic
   type Element_Type is private;
package Ada.Containers.Synchronized_Queue_Interfaces
   with Pure, Nonblocking, Global => null is

   type Queue is synchronized interface;

   procedure Enqueue(Container: in out Queue; New_Item: Element_Type) is abstract
       with Synchronization => By_Entry,
            Nonblocking     => False,
            Global'Class    => in out synchronized;
   procedure Dequeue(Container: in out Queue; Element: out Element_Type) is abstract
       with Synchronization => By_Entry,
            Nonblocking     => False,
            Global'Class    => in out synchronized;
   function Current_Use(Container: Queue) return Count_Type is abstract
       with Nonblocking,
            Global'Class => null,
            Use_Formal   => null;
   function Peak_Use(Container: Queue) return Count_Type is abstract
       with Nonblocking,
            Global'Class => null,
            Use_Formal   => null,
            Post'Class   => Peak_Use'Result >= Current_Use(Container);
end Ada.Containers.Synchronized_Queue_Interfaces;

Unbounded Synchronized Queues#

The language-defined generic package Containers.Unbounded_Synchronized_Queues provides type Queue, which implements the interface type 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(<>);
   Default_Ceiling: System.Any_Priority := System.Priority'Last;
package Ada.Containers.Unbounded_Synchronized_Queues
   with Preelaborate, Nonblocking, Global => in out synchronized is

   package Implementation is
      ... -- not specified by the language
   end Implementation;

   protected type Queue(Ceiling: System.Any_Priority := Default_Ceiling)
      with Priority => Ceiling is

      new Queue_Interfaces.Queue
         with overriding entry Enqueue(New_Item:    Queue_Interfaces.Element_Type);
              overriding entry Dequeue(Element: out Queue_Interfaces.Element_Type);
              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;
      end Queue;
end Ada.Containers.Unbounded_Synchronized_Queues;

Bounded Synchronized Queues#

The language-defined generic package !#Ada Containers.Bounded_Synchronized_Queues provides type Queue, which implements the interface type 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(<>);
   Default_Capacity: Count_Type;
   Default_Ceiling : System.Any_Priority := System.Priority'Last;
package Ada.Containers.Bounded_Synchronized_Queues
   with Preelaborate, Nonblocking, Global => in out synchronized is

   package Implementation is
      ... -- not specified by the language
   end Implementation;

   protected type Queue(Capacity: Count_Type          := Default_Capacity;
                        Ceiling : System.Any_Priority := Default_Ceiling)
      with Priority => Ceiling is new Queue_Interfaces.Queue
         with overriding entry Enqueue(New_Item:    Queue_Interfaces.Element_Type);
              overriding entry Dequeue(Element: out Queue_Interfaces.Element_Type);
              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;
   end Queue;
end Ada.Containers.Bounded_Synchronized_Queues;

Unbounded Priority Queues#

The language-defined generic package Containers.Unbounded_Priority_Queues provides type Queue, which implements the interface type 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

   package Implementation is
      ... -- not specified by the language
   end Implementation;

   protected type Queue(Ceiling: System.Any_Priority := Default_Ceiling)
      with Priority => Ceiling is new Queue_Interfaces.Queue
         with overriding entry Enqueue(New_Item:    Queue_Interfaces.Element_Type);
              overriding entry Dequeue(Element: out Queue_Interfaces.Element_Type);
              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;
              not overriding procedure Dequeue_Only_High_Priority(At_Least: Queue_Priority;
                                                                  Element : in out Queue_Interfaces.Element_Type;
                                                                  Success : out Boolean);
   end Queue;
end Ada.Containers.Unbounded_Priority_Queues;

Bounded Priority Queues#

The language-defined generic package Containers.Bounded_Priority_Queues provides type Queue, which implements the interface type 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_Capacity: Count_Type;
   Default_Ceiling : System.Any_Priority := System.Priority'Last;
package Ada.Containers.Bounded_Priority_Queues
   with Preelaborate, Nonblocking, Global => in out synchronized is

   package Implementation is
      ... -- not specified by the language
   end Implementation;

   protected type Queue(Capacity: Count_Type          := Default_Capacity;
                        Ceiling : System.Any_Priority := Default_Ceiling)
      with Priority => Ceiling is new Queue_Interfaces.Queue
         with overriding entry Enqueue(New_Item:    Queue_Interfaces.Element_Type);
              overriding entry Dequeue(Element: out Queue_Interfaces.Element_Type);
              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;
              not overriding procedure Dequeue_Only_High_Priority(At_Least: Queue_Priority;
                                                                  Element : in out Queue_Interfaces.Element_Type;
                                                                  Success : out Boolean);
   end Queue;
end Ada.Containers.Bounded_Priority_Queues;