annotate gcc/ada/libgnat/g-bubsor.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- G N A T . B U B B L E _ S O R T --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1995-2018, AdaCore --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- Sort Utility (Using Bubblesort Algorithm)
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 -- This package provides a bubblesort routine that works with access to
kono
parents:
diff changeset
35 -- subprogram parameters, so that it can be used with different types with
kono
parents:
diff changeset
36 -- shared sorting code.
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 -- See also GNAT.Bubble_Sort_G and GNAT.Bubble_Sort_A. These are older
kono
parents:
diff changeset
39 -- versions of this routine. In some cases GNAT.Bubble_Sort_G may be a
kono
parents:
diff changeset
40 -- little faster than GNAT.Bubble_Sort, at the expense of generic code
kono
parents:
diff changeset
41 -- duplication and a less convenient interface. The generic version also
kono
parents:
diff changeset
42 -- has the advantage of being Pure, while this unit can only be Preelaborate.
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 package GNAT.Bubble_Sort is
kono
parents:
diff changeset
45 pragma Pure;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 -- The data to be sorted is assumed to be indexed by integer values from
kono
parents:
diff changeset
48 -- 1 to N, where N is the number of items to be sorted.
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 type Xchg_Procedure is access procedure (Op1, Op2 : Natural);
kono
parents:
diff changeset
51 -- A pointer to a procedure that exchanges the two data items whose
kono
parents:
diff changeset
52 -- index values are Op1 and Op2.
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 type Lt_Function is access function (Op1, Op2 : Natural) return Boolean;
kono
parents:
diff changeset
55 -- A pointer to a function that compares two items and returns True if
kono
parents:
diff changeset
56 -- the item with index value Op1 is less than the item with Index value
kono
parents:
diff changeset
57 -- Op2, and False if the Op1 item is greater than or equal to the Op2
kono
parents:
diff changeset
58 -- item.
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 procedure Sort (N : Natural; Xchg : Xchg_Procedure; Lt : Lt_Function);
kono
parents:
diff changeset
61 -- This procedures sorts items in the range from 1 to N into ascending
kono
parents:
diff changeset
62 -- order making calls to Lt to do required comparisons, and calls to
kono
parents:
diff changeset
63 -- Xchg to exchange items. The sort is stable, that is the order of
kono
parents:
diff changeset
64 -- equal items in the input is preserved.
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 end GNAT.Bubble_Sort;