1--  Copyright 1994 Grady Booch
2--  Copyright 1998-2014 Simon Wright <simon@pushface.org>
3
4--  This package is free software; you can redistribute it and/or
5--  modify it under terms of the GNU General Public License as
6--  published by the Free Software Foundation; either version 2, or
7--  (at your option) any later version. This package is distributed in
8--  the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9--  even the implied warranty of MERCHANTABILITY or FITNESS FOR A
10--  PARTICULAR PURPOSE. See the GNU General Public License for more
11--  details. You should have received a copy of the GNU General Public
12--  License distributed with this package; see file COPYING.  If not,
13--  write to the Free Software Foundation, 59 Temple Place - Suite
14--  330, Boston, MA 02111-1307, USA.
15
16--  As a special exception, if other files instantiate generics from
17--  this unit, or you link this unit with other files to produce an
18--  executable, this unit does not by itself cause the resulting
19--  executable to be covered by the GNU General Public License.  This
20--  exception does not however invalidate any other reasons why the
21--  executable file might be covered by the GNU Public License.
22
23with BC.Support.Dynamic;
24with System.Storage_Pools;
25
26generic
27   Storage : in out System.Storage_Pools.Root_Storage_Pool'Class;
28   Initial_Size : Positive := 10;
29package BC.Containers.Queues.Ordered.Dynamic is
30
31   pragma Preelaborate;
32
33   type Queue is new Abstract_Ordered_Queue with private;
34   --  A dynamic Queue exhibits similar performance to a
35   --  Bounded_Queue, except its size is limited only to available
36   --  memory.  It dynamically grows in a linear fashion (based on
37   --  Chunk_Size).
38
39   function Null_Container return Queue;
40
41   procedure Clear (Q : in out Queue);
42   --  Empty the queue of all items.
43
44   procedure Append (Q : in out Queue; Elem : Item);
45   --  Add the item to the queue; the item itself is copied.
46
47   procedure Pop (Q : in out Queue);
48   --  Remove the item from the front of the queue.
49
50   procedure Remove (Q : in out Queue; From : Positive);
51   --  Remove the item at the given index.
52
53   function Length (Q : in Queue) return Natural;
54   --  Return the number of items in the queue.
55
56   function Is_Empty (Q : in Queue) return Boolean;
57   --  Return True if and only if there are no items in the queue.
58
59   function Front (Q : in Queue) return Item;
60   --  Return a copy of the item at the front of the queue.
61
62   function Location (Q : in Queue; Elem : Item) return Natural;
63   --  Return the first index at which the item is found; return 0 if
64   --  the item does not exist in the queue.
65
66   function "=" (Left, Right : in Queue) return Boolean;
67   --  Return True if and only if both queues have the same length and
68   --  the same items; return False otherwise.
69
70   procedure Preallocate (Q : in out Queue; Size : Natural);
71   --  Allocates 'Size' additional storage elements for the Queue
72
73   procedure Set_Chunk_Size (Q : in out Queue; Size : Natural);
74   --  Establishes the Size the Queue will grow if the Queue exhausts
75   --  its current size.
76
77   function Chunk_Size (Q : Queue) return Natural;
78   --  Returns the Chunk_Size
79
80   function New_Iterator (For_The_Queue : Queue) return Iterator'Class;
81   --  Return a reset Iterator bound to the specific Queue.
82
83private
84
85   package Queue_Nodes
86   is new BC.Support.Dynamic (Item => Item,
87                              Item_Ptr => Item_Ptr,
88                              Storage => Storage,
89                              Initial_Size => Initial_Size);
90
91   type Queue is new Abstract_Ordered_Queue with record
92      Rep : Queue_Nodes.Dyn_Node;
93   end record;
94
95   function Item_At (Q : Queue; Index : Positive) return Item_Ptr;
96
97end BC.Containers.Queues.Ordered.Dynamic;
98