-- -------------------------------------------------------------------- -- sci-occurrences-finites -- helper to identify occurrences of a given item -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- SPDX-License-Identifier: Apache-2.0 ----------------------------------------------------------------------- with Ada.Containers.Ordered_Sets; with Ada.Containers.Vectors; generic type Element_Type is private; type Occurrence_Type is private; with function "<" (Left, Right : Element_Type) return Boolean is <>; package SCI.Occurrences.Finites is type Occurrence is record Element : Element_Type; Occurrence : Occurrence_Type; end record; -- Compare the two occurrence only on their name. function "<" (Left, Right : Occurrence) return Boolean is (Left.Element < Right.Element); function Same (Left, Right : Occurrence) return Boolean is (Left.Element = Right.Element); package Vectors is new Ada.Containers.Vectors (Positive, Occurrence); subtype Vector is Vectors.Vector; package Sets is new Ada.Containers.Ordered_Sets (Occurrence, "<", Same); subtype Set is Sets.Set; -- Add the item in the set. If the item already exists, add the value -- to the current count. generic with function "+" (Left, Right : Occurrence_Type) return Occurrence_Type is <>; procedure Add (Set : in out Sets.Set; Item : in Element_Type; Value : in Occurrence_Type); -- Get the list of occurrence items sorted on the occurence value. generic with function "<" (Left, Right : Occurrence_Type) return Boolean is <>; procedure List (Set : in Sets.Set; Into : in out Vectors.Vector); -- Return the longest item in the list. generic with function Length (Item : Element_Type) return Natural is <>; function Longest (From : in Vectors.Vector) return Natural; -- Compute the sum of every element count. generic with function "+" (Left, Right : Occurrence_Type) return Occurrence_Type is <>; function Sum (From : in Vectors.Vector; Initial : in Occurrence_Type) return Occurrence_Type; end SCI.Occurrences.Finites;