Mercurial > hg > octave-lyh
annotate liboctave/Array-b.cc @ 10485:b4e14e628fc9
Truncate argv() for scripts used without command line parameters. Bug #29423
author | Judd Storrs <jstorrs@gmail.com> |
---|---|
date | Fri, 02 Apr 2010 13:28:02 -0400 |
parents | a3635bc1ea19 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
2493 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007, 2008, 2009 |
7017 | 4 John W. Eaton |
2493 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2493 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2493 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 // Instantiate Arrays of bool values. | |
29 | |
30 #include "Array.h" | |
31 #include "Array.cc" | |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
32 #define INLINE_ASCENDING_SORT |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
33 #define INLINE_DESCENDING_SORT |
7433 | 34 #include "oct-sort.cc" |
35 | |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
36 // Specialize bool sorting (aka stable partitioning). |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
37 |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
38 template<bool desc> |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
39 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
|
40 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
41 octave_idx_type k = 0; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
42 for (octave_idx_type i = 0; i < nel; i++) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
43 if (data[i] == desc) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
44 data[k++] = desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
45 for (octave_idx_type i = k; i < nel; i++) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
46 data[i] = ! desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
47 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
48 |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
49 template<bool desc> |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
50 static void do_bool_partition (bool *data, octave_idx_type *idx, |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
51 octave_idx_type nel) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
52 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
53 // FIXME: This is essentially a simple bucket sort. |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
54 // Can it be efficiently done by std::partition? |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
55 OCTAVE_LOCAL_BUFFER (octave_idx_type, jdx, nel); |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
56 octave_idx_type k = 0, l = 0; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
57 for (octave_idx_type i = 0; i < nel; i++) |
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 if (data[i] == desc) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
60 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
61 data[k] = desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
62 idx[k++] = idx[i]; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
63 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
64 else |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
65 jdx[l++] = idx[i]; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
66 } |
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 for (octave_idx_type i = k; i < nel; i++) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
69 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
70 data[i] = ! desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
71 idx[i] = jdx[i-k]; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
72 } |
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 template <> template <> |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
76 void |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
77 octave_sort<bool>::sort (bool *data, octave_idx_type nel, |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
78 std::less<bool>) |
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 do_bool_partition<false> (data, nel); |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
81 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
82 |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
83 template <> template <> |
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::greater<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<true> (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 |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
91 template <> template <> |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
92 void |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
93 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
|
94 std::less<bool>) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
95 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
96 do_bool_partition<false> (data, idx, nel); |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
97 } |
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 template <> template <> |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
100 void |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
101 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
|
102 std::greater<bool>) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
103 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
104 do_bool_partition<true> (data, idx, nel); |
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 |
7433 | 107 INSTANTIATE_ARRAY_SORT (bool); |
2493 | 108 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
109 INSTANTIATE_ARRAY (bool, OCTAVE_API); |
3836 | 110 |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
111 template OCTAVE_API std::ostream& operator << (std::ostream&, const Array<bool>&); |
4513 | 112 |
2826 | 113 #include "DiagArray2.h" |
114 #include "DiagArray2.cc" | |
115 | |
6108 | 116 template class OCTAVE_API DiagArray2<bool>; |