annotate liboctave/array/Array-b.cc @ 21574:ae4d7dfea337

maint: merge stable to default.
author John W. Eaton <jwe@octave.org>
date Fri, 01 Apr 2016 12:57:49 -0400
parents 40de9f8f23a6 f3f8e1d3e399
children aba2e6293dd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2493
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
1 /*
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19395
diff changeset
3 Copyright (C) 1996-2015 John W. Eaton
2493
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
4
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
6
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
10 option) any later version.
2493
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
11
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
15 for more details.
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
16
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
19 <http://www.gnu.org/licenses/>.
2493
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
20
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
21 */
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
22
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21213
diff changeset
24 # include "config.h"
2493
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
25 #endif
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
26
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
27 // Instantiate Arrays of bool values.
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
28
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
29 #include "Array.h"
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
30 #include "Array.cc"
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
31
21213
f7d1050b9b53 maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents: 21202
diff changeset
32 #define INLINE_ASCENDING_SORT 1
f7d1050b9b53 maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents: 21202
diff changeset
33 #define INLINE_DESCENDING_SORT 1
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
34 #include "oct-sort.cc"
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
35
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
36 // Prevent implicit instantiations on some systems (Windows, others?)
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
37 // that can lead to duplicate definitions of static data members.
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
38
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
39 extern template class OCTAVE_API Array<idx_vector>;
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
40 extern template class OCTAVE_API Array<octave_idx_type>;
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
41
10114
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
42 // Specialize bool sorting (aka stable partitioning).
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
43
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
44 template <bool desc>
10114
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
45 static void do_bool_partition (bool *data, octave_idx_type nel)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
46 {
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
47 octave_idx_type k = 0;
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
48 for (octave_idx_type i = 0; i < nel; i++)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
49 if (data[i] == desc)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
50 data[k++] = desc;
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
51 for (octave_idx_type i = k; i < nel; i++)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
52 data[i] = ! desc;
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
53 }
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
54
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
55 template <bool desc>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
56 static void do_bool_partition (bool *data, octave_idx_type *idx,
10114
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
57 octave_idx_type nel)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
58 {
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
59 // FIXME: This is essentially a simple bucket sort.
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
60 // Can it be efficiently done by std::partition?
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
61 OCTAVE_LOCAL_BUFFER (octave_idx_type, jdx, nel);
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
62 octave_idx_type k = 0;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
63 octave_idx_type l = 0;
10114
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
64 for (octave_idx_type i = 0; i < nel; i++)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
65 {
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
66 if (data[i] == desc)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
67 {
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
68 data[k] = desc;
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
69 idx[k++] = idx[i];
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
70 }
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
71 else
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
72 jdx[l++] = idx[i];
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
73 }
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
74
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
75 for (octave_idx_type i = k; i < nel; i++)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
76 {
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
77 data[i] = ! desc;
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
78 idx[i] = jdx[i-k];
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
79 }
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
80 }
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
81
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
82 template <>
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
83 template <>
10114
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
84 void
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
85 octave_sort<bool>::sort (bool *data, octave_idx_type nel,
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
86 std::less<bool>)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
87 {
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
88 do_bool_partition<false> (data, nel);
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
89 }
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
90
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
91 template <>
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
92 template <>
10114
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
93 void
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
94 octave_sort<bool>::sort (bool *data, octave_idx_type nel,
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
95 std::greater<bool>)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
96 {
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
97 do_bool_partition<true> (data, nel);
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
98 }
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
99
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
100 template <>
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
101 template <>
10114
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
102 void
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
103 octave_sort<bool>::sort (bool *data, octave_idx_type *idx, octave_idx_type nel,
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
104 std::less<bool>)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
105 {
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
106 do_bool_partition<false> (data, idx, nel);
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
107 }
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
108
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
109 template <>
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
110 template <>
10114
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
111 void
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
112 octave_sort<bool>::sort (bool *data, octave_idx_type *idx, octave_idx_type nel,
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
113 std::greater<bool>)
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
114 {
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
115 do_bool_partition<true> (data, idx, nel);
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
116 }
e4936c129cbd optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
117
19395
fb09907f4e49 Remove single line makro INSTANTIATE_ARRAY_SORT.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18084
diff changeset
118 template class OCTAVE_API octave_sort<bool>;
2493
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents:
diff changeset
119
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 7433
diff changeset
120 INSTANTIATE_ARRAY (bool, OCTAVE_API);
3836
b8c1cb5b9fd9 [project @ 2001-05-31 19:30:49 by jwe]
jwe
parents: 3176
diff changeset
121
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
122 template OCTAVE_API std::ostream& operator << (std::ostream&,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
123 const Array<bool>&);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 3836
diff changeset
124
2826
d6867cd782c7 [project @ 1997-03-25 23:36:39 by jwe]
jwe
parents: 2493
diff changeset
125 #include "DiagArray2.h"
d6867cd782c7 [project @ 1997-03-25 23:36:39 by jwe]
jwe
parents: 2493
diff changeset
126 #include "DiagArray2.cc"
d6867cd782c7 [project @ 1997-03-25 23:36:39 by jwe]
jwe
parents: 2493
diff changeset
127
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5307
diff changeset
128 template class OCTAVE_API DiagArray2<bool>;