--  Graphs that ownership alone cannot express, over arenas (ledger D78): a company shared by
--  its employees, a doubly linked list, and a tree whose nodes know their parents.
with Verada.Containers.Arenas;

package Graphs is
   --  a company that several people refer to: renaming it is one change, seen by all
   type Company is record
      Code : Natural := 0;
      Staff : Natural := 0;
   end record;

   package Companies is new Verada.Containers.Arenas (Company, 8);

   type Person is record
      Age : Natural := 0;
      Employer : Companies.Handle := Companies.No_Handle;
   end record;

   --  a doubly linked list: each node links to the ones before and after it
   type Link is record
      Value : Integer := 0;
      Previous : Long_Long_Integer := 0;
      Next : Long_Long_Integer := 0;
   end record;

   package Links is new Verada.Containers.Arenas (Link, 16);

   type List is record
      First : Links.Handle := Links.No_Handle;
      Last : Links.Handle := Links.No_Handle;
   end record;

   procedure Append (Nodes : in out Links.Arena; L : in out List; Value : Integer)
     with Pre => Links.Has_Room (Nodes);

   --  the values from the first to the last, and back
   function Sum_Forward (Nodes : Links.Arena; L : List) return Long_Long_Long_Integer;
   function Count_Backward (Nodes : Links.Arena; L : List) return Natural;

   --  a tree: each node knows its parent
   type Tree_Node is record
      Label : Natural := 0;
      Parent : Long_Long_Integer := 0;
   end record;

   package Trees is new Verada.Containers.Arenas (Tree_Node, 16);

   --  how many steps from H up to the root (at most 16)
   function Depth (Nodes : Trees.Arena; H : Trees.Handle) return Natural;
end Graphs;
