lace: Add a simple stack generic.
This commit is contained in:
45
1-base/lace/source/lace-stack.adb
Normal file
45
1-base/lace/source/lace-stack.adb
Normal 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;
|
||||
29
1-base/lace/source/lace-stack.ads
Normal file
29
1-base/lace/source/lace-stack.ads
Normal 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;
|
||||
Reference in New Issue
Block a user