Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?

85 views
Skip to first unread message

reinert

unread,
Feb 14, 2023, 3:49:55 AM2/14/23
to
Hello,

Sometimes, I have to sort records. One possibility is to use Generig_Sorting under Ada.Containers.Vectors and eksplicitly use Sort. An alternative is to use Ada.Containders.Ordered_Sets and somehow get sorting "for free".

I would like to get arguments for and against these two alternatives.

reinert

Jeffrey R.Carter

unread,
Feb 14, 2023, 4:35:26 AM2/14/23
to
On 2023-02-14 09:49, reinert wrote:
>
> Sometimes, I have to sort records. One possibility is to use Generig_Sorting under Ada.Containers.Vectors and eksplicitly use Sort. An alternative is to use Ada.Containders.Ordered_Sets and somehow get sorting "for free".
>
> I would like to get arguments for and against these two alternatives.

Both should be O(NlogN), so the distinction is which works better for what you
do with them after they are sorted.

--
Jeff Carter
"[B]ecause of our experience in security, we are convinced
that C is too error-prone. Its loose typing, its unsafe
bitfields management, too many compiler dependent behaviors,
etc. easily lead to vulnerabilities."
EwoK developers
163

reinert

unread,
Feb 14, 2023, 5:46:31 AM2/14/23
to
My main argument for using Ordered_Sets is that it seems to be less verbose and somehow garanteres sorting. Myset.Last/First always provides the "largest"/"smallest" element.

reinert



G.B.

unread,
Feb 14, 2023, 1:48:16 PM2/14/23
to
On 14.02.23 11:46, reinert wrote:
> My main argument for using Ordered_Sets is that it seems to be less verbose and somehow garanteres sorting. Myset.Last/First always provides the "largest"/"smallest" element.

You could measure performance of operations
that you find critical, given a typical number
of elements in the set. If there isn't any operation
that is particularly critical, some weighted
average of all set operations might be of interest.

Two similar data structures might both use a common
algorithm, such as sorting. If a program uses both
data structures, then having just one algorithm
might be advantageous, if only for the size of
the executable.

Marius Amado-Alves

unread,
Mar 15, 2023, 6:05:37 AM3/15/23
to
> Sometimes, I have to sort records. One possibility is to use Generig_Sorting under Ada.Containers.Vectors and eksplicitly use Sort. An alternative is to use Ada.Containders.Ordered_Sets and somehow get sorting "for free".
>
> I would like to get arguments for and against these two alternatives.
>
> reinert

Sets have slightly stricter semantics, namely no duplicates. Normally, if the real data has this semantics, you should use sets (and populate with Include or else catch the exception raised upon trying to Insert a duplicate).

Brad Moore

unread,
Mar 15, 2023, 10:24:04 AM3/15/23
to
On Tuesday, February 14, 2023 at 1:49:55 AM UTC-7, reinert wrote:
> Hello,
I might use the generic sorting for example, for the case where the data is more static and needs to be sorted once, whereas I'd use an ordered set if the data is continuously being updated and manipulated, or if I needed set semantics.

Brad
0 new messages