comp.lang.ada
 help / color / mirror / Atom feed
* Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
@ 2023-02-14  8:49 reinert
  2023-02-14  9:35 ` Jeffrey R.Carter
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: reinert @ 2023-02-14  8:49 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
  2023-02-14  8:49 Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ? reinert
@ 2023-02-14  9:35 ` Jeffrey R.Carter
  2023-02-14 10:46   ` reinert
  2023-03-15 10:05 ` Marius Amado-Alves
  2023-03-15 14:24 ` Brad Moore
  2 siblings, 1 reply; 6+ messages in thread
From: Jeffrey R.Carter @ 2023-02-14  9:35 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
  2023-02-14  9:35 ` Jeffrey R.Carter
@ 2023-02-14 10:46   ` reinert
  2023-02-14 18:48     ` G.B.
  0 siblings, 1 reply; 6+ messages in thread
From: reinert @ 2023-02-14 10:46 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
  2023-02-14 10:46   ` reinert
@ 2023-02-14 18:48     ` G.B.
  0 siblings, 0 replies; 6+ messages in thread
From: G.B. @ 2023-02-14 18:48 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
  2023-02-14  8:49 Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ? reinert
  2023-02-14  9:35 ` Jeffrey R.Carter
@ 2023-03-15 10:05 ` Marius Amado-Alves
  2023-03-15 14:24 ` Brad Moore
  2 siblings, 0 replies; 6+ messages in thread
From: Marius Amado-Alves @ 2023-03-15 10:05 UTC (permalink / raw)


> 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).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
  2023-02-14  8:49 Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ? reinert
  2023-02-14  9:35 ` Jeffrey R.Carter
  2023-03-15 10:05 ` Marius Amado-Alves
@ 2023-03-15 14:24 ` Brad Moore
  2 siblings, 0 replies; 6+ messages in thread
From: Brad Moore @ 2023-03-15 14:24 UTC (permalink / raw)


On Tuesday, February 14, 2023 at 1:49:55 AM UTC-7, reinert wrote:
> 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

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-15 14:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14  8:49 Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ? reinert
2023-02-14  9:35 ` Jeffrey R.Carter
2023-02-14 10:46   ` reinert
2023-02-14 18:48     ` G.B.
2023-03-15 10:05 ` Marius Amado-Alves
2023-03-15 14:24 ` Brad Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox