-- The Ada Structured Library - A set of container classes and general
-- tools for use with Ada95.
-- Copyright (C) 1998 Corey Minyard (minyard@acm.org)
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Library General Public
-- License as published by the Free Software Foundation; either
-- version 2 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Library General Public License for more details.
--
-- You should have received a copy of the GNU Library General Public
-- License along with this library; if not, write to the Free
-- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-- MA 02111-1307, USA
--
generic
package Asgc.Tree.Dynamic is
subtype Parent_Object is Asgc.Tree.Object;
type Object (Balanced : Boolean) is new Parent_Object with private;
type Object_Class is access all Object'Class;
type Object_Ptr is access all Object;
procedure Add (O : in out Object;
Val : in Contained_Type);
procedure Delete (O : in out Object;
Val : in Contained_Type);
function Value_Exists (O : in Object;
Val : in Contained_Type)
return Boolean;
function Member_Count (O : in Object)
return Natural;
function "=" (O1, O2 : in Object) return Boolean;
procedure Verify_Integrity (O : in Object);
function Copy (O : in Object) return Asgc.Object_Class;
procedure Initialize (O : in out Object);
procedure Adjust (O : in out Object);
procedure Finalize (O : in out Object);
------------------------------------------------------------------------
subtype Parent_Iterator is Asgc.Tree.Iterator;
type Iterator is new Parent_Iterator with private;
type Iterator_Class is access all Iterator'Class;
type Iterator_Ptr is access all Iterator;
procedure Add (Iter : in out Iterator;
Val : in Contained_Type);
procedure Search (Iter : in out Iterator;
Val : in Contained_Type;
Found : out Boolean);
procedure Root (Iter : in out Iterator;
Is_End : out End_Marker);
procedure Left (Iter : in out Iterator;
Is_End : out End_Marker);
procedure Right (Iter : in out Iterator;
Is_End : out End_Marker);
procedure Up (Iter : in out Iterator;
Is_End : out End_Marker);
procedure Last (Iter : in out Iterator; Is_End : out End_Marker);
procedure Prev (Iter : in out Iterator; Is_End : out End_Marker);
procedure Get_Decr (Iter : in out Iterator;
Val : out Contained_Type;
Is_End : out End_Marker);
procedure Finalize (Iter : in out Iterator);
function ">" (Iter1, Iter2 : in Iterator) return Boolean;
function ">" (Iter : in Iterator; Val : in Contained_Type) return Boolean;
function ">" (Val : in Contained_Type; Iter : in Iterator) return Boolean;
function "<" (Iter1, Iter2 : in Iterator) return Boolean;
function "<" (Iter : in Iterator; Val : in Contained_Type) return Boolean;
function "<" (Val : in Contained_Type; Iter : in Iterator) return Boolean;
function ">=" (Iter1, Iter2 : in Iterator) return Boolean;
function ">=" (Iter : in Iterator; Val : in Contained_Type) return Boolean;
function ">=" (Val : in Contained_Type; Iter : in Iterator) return Boolean;
function "<=" (Iter1, Iter2 : in Iterator) return Boolean;
function "<=" (Iter : in Iterator; Val : in Contained_Type) return Boolean;
function "<=" (Val : in Contained_Type; Iter : in Iterator) return Boolean;
-- Abstract functions this must implement
function New_Iterator (O : access Object) return Asgc.Iterator_Class;
function New_Iterator (O : in Object_Class) return Iterator;
procedure Free (Iter : access Iterator);
procedure Set_Container (Iter : in out Iterator;
O : in Asgc.Object_Class);
procedure First (Iter : in out Iterator; Is_End : out End_Marker);
procedure Next (Iter : in out Iterator; Is_End : out End_Marker);
procedure Delete (Iter : in out Iterator; Is_End : out End_Marker);
function Is_Same (Iter1, Iter2 : in Iterator) return Boolean;
function Get (Iter : in Iterator) return Contained_Type;
procedure Get_Incr (Iter : in out Iterator;
Val : out Contained_Type;
Is_End : out End_Marker);
function "=" (Iter1, Iter2 : in Iterator) return Boolean;
function "=" (Iter : in Iterator; Val : in Contained_Type) return Boolean;
function "=" (Val : in Contained_Type; Iter : in Iterator) return Boolean;
private
-- A tree data structure is pretty straighforward, each node has a left,
-- right, and up reference, an AVL balance value, and the contained
-- value.
-- The balance types of an AVL tree node.
type Node_Balance is ('+', '=', '-');
-- The position of a node with respect to the node above it. If the
-- current node comes from the left branch above, it is Left. If the
-- right branch then Right. If the current node is the root, then None.
type Last_Direction is (Left, Right, None);
type Node;
type Node_Ptr is access all Node;
type Node is record
Left, Right, Up : Node_Ptr := null;
Balance : Node_Balance := '=';
Val : Contained_Type;
end record;
type Object (Balanced : Boolean) is new Parent_Object with record
Root : Node_Ptr := null;
Count : Natural := 0;
end record;
type Iterator is new Parent_Iterator with record
Robj : Object_Class := null;
Pos : Node_Ptr := null;
end record;
end Asgc.Tree.Dynamic;