Defining a bag Multiset with elements and multiplicity pairs In Ada

150 Views Asked by At

I have to meet a specification which says that I have to write a bag type which is a record with discriminant , which is the maximum capacity of the bag in the record I have to put an array that contains element and multiplicity pairs , I have written some code and updated it as well

type TArray is array (Integer range <>) of Elem,Multi;
type Bag (Max : Positive) is record
                                Data    : TArray (1 .. Max);
                                Pointer : Natural := 0;
                             end record;

The code has been updated please check and suggest

1

There are 1 best solutions below

2
On

The answer is quite simple : if you don't have any error messages at compilation phase, it's ok.

Well according to what you described, your code looks good. I have a question about it.

Do you plan to have negative indexes on your type TArray ? If not, why don't you use the same type as your discriminant ?

The only thing is that you'll have only half the values using Positive instead of Integer but in your record, you anyway already start at 1 and thus have the same range as Positive.