lace: Add a simple stack generic.

This commit is contained in:
Rod Kay
2023-05-01 21:18:04 +10:00
parent 2a3231830e
commit eb17c310f1
2 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
package body lace.Stack
is
use ada.Containers;
function to_Stack return Item
is
Self : Item;
begin
Self.reserve_Capacity (Count_type (initial_Capacity));
return Self;
end to_Stack;
procedure push (Self : in out Item; E : in Element_T)
is
pragma assert (Check => Self.Capacity >= Count_type (initial_Capacity),
Message => "Stack has not been initialised.");
begin
Self.append (E);
end push;
function pop (Self : in out Item) return Element_T
is
Top : constant Element_t := Self.last_Element;
begin
Self.delete_Last;
return Top;
end pop;
function getCount (Self : in Item) return Natural
is
begin
return Natural (Self.Length);
end getCount;
end lace.Stack;

View File

@@ -0,0 +1,29 @@
private
with
ada.Containers.Vectors;
generic
type Element_t is private;
initial_Capacity : Positive;
package lace.Stack
is
type Item is private;
function to_Stack return Item;
procedure push (Self : in out Item; E : in Element_T);
function pop (Self : in out Item) return Element_T;
function getCount (Self : in Item) return Natural;
private
package Vectors is new ada.Containers.Vectors (Positive, Element_t);
type Item is new Vectors.Vector with null record;
end lace.Stack;