1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- A D A . C O N T A I N E R S . --
6 -- G E N E R I C _ A N O N Y M O U S _ A R R A Y _ S O R T --
10 -- Copyright (C) 2004-2006, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- This unit was originally developed by Matthew J Heaney. --
31 ------------------------------------------------------------------------------
33 -- This algorithm was adapted from GNAT.Heap_Sort (see g-heasor.ad[sb])
37 procedure Ada
.Containers
.Generic_Anonymous_Array_Sort
38 (First
, Last
: Index_Type
'Base)
40 type T
is range System
.Min_Int
.. System
.Max_Int
;
42 function To_Index
(J
: T
) return Index_Type
;
43 pragma Inline
(To_Index
);
45 function Lt
(J
, K
: T
) return Boolean;
48 procedure Xchg
(J
, K
: T
);
51 procedure Sift
(S
: T
);
57 function To_Index
(J
: T
) return Index_Type
is
58 K
: constant T
'Base := Index_Type
'Pos (First
) + J
- T
'(1);
60 return Index_Type'Val (K);
67 function Lt (J, K : T) return Boolean is
69 return Less (To_Index (J), To_Index (K));
76 procedure Xchg (J, K : T) is
78 Swap (To_Index (J), To_Index (K));
81 Max : T := Index_Type'Pos (Last) - Index_Type'Pos (First) + T'(1);
87 procedure Sift
(S
: T
) is
97 if Lt
(Son
, Son
+ 1) then
111 if Lt
(Father
, C
) then
120 -- Start of processing for Generic_Anonymous_Array_Sort
123 for J
in reverse 1 .. Max
/ 2 loop
132 end Ada
.Containers
.Generic_Anonymous_Array_Sort
;