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.Deques.Dynamic is
30
31   pragma Preelaborate;
32
33   type Deque is new Abstract_Deque with private;
34   --  A dynamic Deque exhibits similar performance to a
35   --  Bounded_Deque, 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 Deque;
40
41   procedure Clear (D : in out Deque);
42   --  Empty the deque of all items.
43
44   procedure Append (D : in out Deque;
45                     Elem : Item;
46                     Location : Deque_End := Back);
47   --  Add the item to the deque at the given location; the item
48   --  itself is copied.
49
50   procedure Pop (D : in out Deque; Location : Deque_End := Front);
51   --  Remove the item from the deque at the given location.
52
53   procedure Remove (D : in out Deque; From : Positive);
54   --  Remove the item at the given index.
55
56   function Length (D : in Deque) return Natural;
57   --  Return the number of items in the deque.
58
59   function Is_Empty (D : in Deque) return Boolean;
60   --  Return True if and only if there are no items in the deque.
61
62   function Front (D : in Deque) return Item;
63   --  Return a copy of the item at the front of the deque.
64
65   function Back (D : in Deque) return Item;
66   --  Return a copy of the item at the back of the deque.
67
68   function Location (D : in Deque; Elem : Item) return Natural;
69   --  Return the first index at which the item is found; return 0 if
70   --  the item does not exist in the deque.
71
72   function "=" (Left, Right : in Deque) return Boolean;
73   --  Return True if and only if both deques have the same length and
74   --  the same items in the same order; return False otherwise.
75
76   procedure Preallocate (D : in out Deque; Size : Natural);
77   --  Allocates 'Size' additional storage elements for the Deque
78
79   procedure Set_Chunk_Size (D : in out Deque; Size : Natural);
80   --  Establishes the Size the Deque will grow if the Deque exhausts
81   --  its current size.
82
83   function Chunk_Size (D : Deque) return Natural;
84   --  Returns the Chunk_Size
85
86   function New_Iterator (For_The_Deque : Deque) return Iterator'Class;
87   --  Return a reset Iterator bound to the specific Deque.
88
89private
90
91   package Deque_Nodes
92   is new BC.Support.Dynamic (Item => Item,
93                              Item_Ptr => Item_Ptr,
94                              Storage => Storage,
95                              Initial_Size => Initial_Size);
96
97   type Deque is new Abstract_Deque with record
98      Rep : Deque_Nodes.Dyn_Node;
99   end record;
100
101   function Item_At (D : Deque; Index : Positive) return Item_Ptr;
102
103end BC.Containers.Deques.Dynamic;
104