1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
383
|
23 #if !defined (octave_idx_vector_h) |
|
24 #define octave_idx_vector_h 1 |
1
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1297
|
27 #pragma interface |
|
28 #endif |
|
29 |
3503
|
30 #include <iostream> |
|
31 |
4653
|
32 #include "dim-vector.h" |
4504
|
33 |
1560
|
34 class ColumnVector; |
4650
|
35 class boolNDArray; |
|
36 class NDArray; |
164
|
37 class Range; |
|
38 |
453
|
39 class |
|
40 idx_vector |
1
|
41 { |
1560
|
42 private: |
|
43 |
1879
|
44 class |
1560
|
45 idx_vector_rep |
1879
|
46 { |
|
47 public: |
|
48 |
2802
|
49 idx_vector_rep (void) |
4653
|
50 : data (0), len (0), num_zeros (0), num_ones (0), max_val (0), |
|
51 min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), |
|
52 colon (0), one_zero (0), initialized (0), frozen (0), |
|
53 colon_equiv_checked (0), colon_equiv (0), orig_dims () { } |
1560
|
54 |
1879
|
55 idx_vector_rep (const ColumnVector& v); |
1560
|
56 |
4650
|
57 idx_vector_rep (const NDArray& nda); |
1879
|
58 |
|
59 idx_vector_rep (const Range& r); |
1560
|
60 |
2386
|
61 idx_vector_rep (double d); |
|
62 |
3928
|
63 idx_vector_rep (int i); |
|
64 |
1879
|
65 idx_vector_rep (char c); |
1560
|
66 |
2828
|
67 idx_vector_rep (bool b); |
|
68 |
4650
|
69 idx_vector_rep (const boolNDArray& bnda); |
2828
|
70 |
1879
|
71 idx_vector_rep (const idx_vector_rep& a); |
1560
|
72 |
2802
|
73 ~idx_vector_rep (void) { delete [] data; } |
1560
|
74 |
1879
|
75 idx_vector_rep& operator = (const idx_vector_rep& a); |
1560
|
76 |
1879
|
77 int ok (void) { return initialized; } |
1560
|
78 |
1879
|
79 int capacity (void) const { return len; } |
|
80 int length (int colon_len) const { return colon ? colon_len : len; } |
1560
|
81 |
1879
|
82 int elem (int n) const { return colon ? n : data[n]; } |
1560
|
83 |
1879
|
84 int checkelem (int n) const; |
|
85 int operator () (int n) const { return checkelem (n); } |
1560
|
86 |
1879
|
87 int max (void) const { return max_val; } |
|
88 int min (void) const { return min_val; } |
|
89 |
|
90 int one_zero_only (void) const { return one_zero; } |
|
91 int zeros_count (void) const { return num_zeros; } |
|
92 int ones_count (void) const { return num_ones; } |
|
93 |
|
94 int is_colon (void) const { return colon; } |
2356
|
95 int is_colon_equiv (int n, int sort_uniq); |
1560
|
96 |
3079
|
97 void sort (bool uniq); |
|
98 |
4653
|
99 int orig_rows (void) const { return orig_dims(0); } |
|
100 int orig_columns (void) const { return orig_dims(1); } |
1560
|
101 |
4653
|
102 dim_vector orig_dimensions (void) const { return orig_dims; } |
4504
|
103 |
1879
|
104 // other stuff |
1560
|
105 |
1879
|
106 void shorten (int n); // Unsafe. Avoid at all cost. |
1560
|
107 |
4461
|
108 int freeze (int z_len, const char *tag, bool resize_ok, bool warn_resize); |
1560
|
109 |
1879
|
110 // i/o |
1560
|
111 |
3504
|
112 std::ostream& print (std::ostream& os) const; |
1560
|
113 |
1879
|
114 int *data; |
|
115 int len; |
|
116 int num_zeros; |
|
117 int num_ones; |
|
118 int max_val; |
|
119 int min_val; |
4504
|
120 |
1879
|
121 int count; |
|
122 int frozen_at_z_len; |
|
123 int frozen_len; |
4653
|
124 |
1879
|
125 unsigned int colon : 1; |
|
126 unsigned int one_zero : 1; |
|
127 unsigned int initialized : 1; |
|
128 unsigned int frozen : 1; |
|
129 unsigned int colon_equiv_checked : 1; |
|
130 unsigned int colon_equiv : 1; |
1560
|
131 |
4653
|
132 dim_vector orig_dims; |
|
133 |
1879
|
134 void init_state (void); |
1560
|
135 |
2828
|
136 void maybe_convert_one_zero_to_idx (int z_len); |
1879
|
137 }; |
1560
|
138 |
1
|
139 public: |
1551
|
140 |
2802
|
141 idx_vector (void) |
1551
|
142 { |
1560
|
143 rep = new idx_vector_rep (); |
|
144 rep->count = 1; |
|
145 } |
|
146 |
|
147 idx_vector (const ColumnVector& v) |
|
148 { |
|
149 rep = new idx_vector_rep (v); |
|
150 rep->count = 1; |
|
151 } |
|
152 |
4650
|
153 idx_vector (const NDArray& nda) |
1560
|
154 { |
4650
|
155 rep = new idx_vector_rep (nda); |
1560
|
156 rep->count = 1; |
|
157 } |
|
158 |
|
159 idx_vector (const Range& r) |
|
160 { |
|
161 rep = new idx_vector_rep (r); |
|
162 rep->count = 1; |
|
163 } |
|
164 |
2386
|
165 idx_vector (double d) |
|
166 { |
|
167 rep = new idx_vector_rep (d); |
|
168 rep->count = 1; |
|
169 } |
|
170 |
3928
|
171 idx_vector (int i) |
|
172 { |
|
173 rep = new idx_vector_rep (i); |
|
174 rep->count = 1; |
|
175 } |
|
176 |
1560
|
177 idx_vector (char c) |
|
178 { |
|
179 rep = new idx_vector_rep (c); |
|
180 rep->count = 1; |
|
181 } |
|
182 |
2828
|
183 idx_vector (bool b) |
|
184 { |
|
185 rep = new idx_vector_rep (b); |
|
186 rep->count = 1; |
|
187 } |
|
188 |
4650
|
189 idx_vector (const boolNDArray& bnda) |
2828
|
190 { |
4650
|
191 rep = new idx_vector_rep (bnda); |
2828
|
192 rep->count = 1; |
|
193 } |
|
194 |
1560
|
195 idx_vector (const idx_vector& a) |
|
196 { |
|
197 rep = a.rep; |
|
198 rep->count++; |
1551
|
199 } |
|
200 |
2802
|
201 ~idx_vector (void) |
1560
|
202 { |
|
203 if (--rep->count <= 0) |
|
204 delete rep; |
|
205 } |
1
|
206 |
1560
|
207 idx_vector& operator = (const idx_vector& a) |
|
208 { |
|
209 if (this != &a) |
|
210 { |
|
211 if (--rep->count <= 0) |
|
212 delete rep; |
1
|
213 |
1560
|
214 rep = a.rep; |
|
215 rep->count++; |
|
216 } |
|
217 return *this; |
1551
|
218 } |
|
219 |
3145
|
220 operator bool () const { return rep->ok (); } |
1560
|
221 |
2802
|
222 int capacity (void) const { return rep->capacity (); } |
|
223 int length (int cl) const { return rep->length (cl); } |
191
|
224 |
2802
|
225 int elem (int n) const { return rep->elem (n); } |
|
226 int checkelem (int n) const { return rep->checkelem (n); } |
|
227 int operator () (int n) const { return rep->operator () (n); } |
1
|
228 |
2802
|
229 int max (void) const { return rep->max (); } |
|
230 int min (void) const { return rep->min (); } |
1551
|
231 |
2802
|
232 int one_zero_only (void) const { return rep->one_zero_only (); } |
|
233 int zeros_count (void) const { return rep->zeros_count (); } |
|
234 int ones_count (void) const { return rep->ones_count (); } |
1
|
235 |
1560
|
236 int is_colon (void) const { return rep->is_colon (); } |
2356
|
237 int is_colon_equiv (int n, int sort_uniq = 0) const |
|
238 { return rep->is_colon_equiv (n, sort_uniq); } |
1
|
239 |
3079
|
240 void sort (bool uniq = false) { rep->sort (uniq); } |
|
241 |
1560
|
242 int orig_rows (void) const { return rep->orig_rows (); } |
|
243 int orig_columns (void) const { return rep->orig_columns (); } |
208
|
244 |
4653
|
245 dim_vector orig_dimensions (void) const { return rep->orig_dimensions (); } |
4504
|
246 |
2663
|
247 int orig_empty (void) const |
4653
|
248 { return (! is_colon () && orig_dimensions().any_zero ()); } |
2663
|
249 |
4653
|
250 // Unsafe. Avoid at all cost. |
1560
|
251 void shorten (int n) { rep->shorten (n); } |
434
|
252 |
4653
|
253 // i/o |
1
|
254 |
4461
|
255 int freeze (int z_len, const char *tag, bool resize_ok = false, |
|
256 bool warn_resize = false) |
|
257 { return rep->freeze (z_len, tag, resize_ok, warn_resize); } |
1560
|
258 |
3504
|
259 std::ostream& print (std::ostream& os) const { return rep->print (os); } |
1560
|
260 |
3504
|
261 friend std::ostream& operator << (std::ostream& os, const idx_vector& a) |
1560
|
262 { return a.print (os); } |
|
263 |
2828
|
264 void maybe_convert_one_zero_to_idx (int z_len) |
|
265 { rep->maybe_convert_one_zero_to_idx (z_len); } |
1
|
266 |
|
267 private: |
|
268 |
1560
|
269 idx_vector_rep *rep; |
1
|
270 |
1560
|
271 void init_state (void) { rep->init_state (); } |
1
|
272 }; |
|
273 |
|
274 #endif |
|
275 |
|
276 /* |
|
277 ;;; Local Variables: *** |
|
278 ;;; mode: C++ *** |
|
279 ;;; End: *** |
|
280 */ |