• Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Se

    From reinert@21:1/5 to All on Tue Feb 14 00:49:53 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeffrey R.Carter@21:1/5 to reinert on Tue Feb 14 10:35:23 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From reinert@21:1/5 to All on Tue Feb 14 02:46:30 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From G.B.@21:1/5 to reinert on Tue Feb 14 19:48:14 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marius Amado-Alves@21:1/5 to All on Wed Mar 15 03:05:34 2023
    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).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Brad Moore@21:1/5 to reinert on Wed Mar 15 07:24:02 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)