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 |
1560
|
32 class ColumnVector; |
2828
|
33 class boolMatrix; |
164
|
34 class Matrix; |
|
35 class Range; |
|
36 |
453
|
37 class |
|
38 idx_vector |
1
|
39 { |
1560
|
40 private: |
|
41 |
1879
|
42 class |
1560
|
43 idx_vector_rep |
1879
|
44 { |
|
45 public: |
|
46 |
2802
|
47 idx_vector_rep (void) |
1879
|
48 { |
|
49 colon = 0; |
|
50 len = 0; |
|
51 num_zeros = 0; |
|
52 num_ones = 0; |
|
53 one_zero = 0; |
|
54 orig_nr = 0; |
|
55 orig_nc = 0; |
|
56 initialized = 0; |
|
57 frozen = 0; |
|
58 colon_equiv_checked = 0; |
|
59 colon_equiv = 0; |
|
60 data = 0; |
|
61 } |
1560
|
62 |
1879
|
63 idx_vector_rep (const ColumnVector& v); |
1560
|
64 |
1879
|
65 idx_vector_rep (const Matrix& m); |
|
66 |
|
67 idx_vector_rep (const Range& r); |
1560
|
68 |
2386
|
69 idx_vector_rep (double d); |
|
70 |
3928
|
71 idx_vector_rep (int i); |
|
72 |
1879
|
73 idx_vector_rep (char c); |
1560
|
74 |
2828
|
75 idx_vector_rep (bool b); |
|
76 |
|
77 idx_vector_rep (const boolMatrix& bm); |
|
78 |
1879
|
79 idx_vector_rep (const idx_vector_rep& a); |
1560
|
80 |
2802
|
81 ~idx_vector_rep (void) { delete [] data; } |
1560
|
82 |
1879
|
83 idx_vector_rep& operator = (const idx_vector_rep& a); |
1560
|
84 |
1879
|
85 int ok (void) { return initialized; } |
1560
|
86 |
1879
|
87 int capacity (void) const { return len; } |
|
88 int length (int colon_len) const { return colon ? colon_len : len; } |
1560
|
89 |
1879
|
90 int elem (int n) const { return colon ? n : data[n]; } |
1560
|
91 |
1879
|
92 int checkelem (int n) const; |
|
93 int operator () (int n) const { return checkelem (n); } |
1560
|
94 |
1879
|
95 int max (void) const { return max_val; } |
|
96 int min (void) const { return min_val; } |
|
97 |
|
98 int one_zero_only (void) const { return one_zero; } |
|
99 int zeros_count (void) const { return num_zeros; } |
|
100 int ones_count (void) const { return num_ones; } |
|
101 |
|
102 int is_colon (void) const { return colon; } |
2356
|
103 int is_colon_equiv (int n, int sort_uniq); |
1560
|
104 |
3079
|
105 void sort (bool uniq); |
|
106 |
1879
|
107 int orig_rows (void) const { return orig_nr; } |
|
108 int orig_columns (void) const { return orig_nc; } |
1560
|
109 |
1879
|
110 // other stuff |
1560
|
111 |
1879
|
112 void shorten (int n); // Unsafe. Avoid at all cost. |
1560
|
113 |
4461
|
114 int freeze (int z_len, const char *tag, bool resize_ok, bool warn_resize); |
1560
|
115 |
1879
|
116 // i/o |
1560
|
117 |
3504
|
118 std::ostream& print (std::ostream& os) const; |
1560
|
119 |
1879
|
120 int *data; |
|
121 int len; |
|
122 int num_zeros; |
|
123 int num_ones; |
|
124 int max_val; |
|
125 int min_val; |
|
126 int orig_nr; |
|
127 int orig_nc; |
|
128 int count; |
|
129 int frozen_at_z_len; |
|
130 int frozen_len; |
|
131 unsigned int colon : 1; |
|
132 unsigned int one_zero : 1; |
|
133 unsigned int initialized : 1; |
|
134 unsigned int frozen : 1; |
|
135 unsigned int colon_equiv_checked : 1; |
|
136 unsigned int colon_equiv : 1; |
1560
|
137 |
1879
|
138 void init_state (void); |
1560
|
139 |
2828
|
140 void maybe_convert_one_zero_to_idx (int z_len); |
1879
|
141 }; |
1560
|
142 |
1
|
143 public: |
1551
|
144 |
2802
|
145 idx_vector (void) |
1551
|
146 { |
1560
|
147 rep = new idx_vector_rep (); |
|
148 rep->count = 1; |
|
149 } |
|
150 |
|
151 idx_vector (const ColumnVector& v) |
|
152 { |
|
153 rep = new idx_vector_rep (v); |
|
154 rep->count = 1; |
|
155 } |
|
156 |
|
157 idx_vector (const Matrix& m) |
|
158 { |
|
159 rep = new idx_vector_rep (m); |
|
160 rep->count = 1; |
|
161 } |
|
162 |
|
163 idx_vector (const Range& r) |
|
164 { |
|
165 rep = new idx_vector_rep (r); |
|
166 rep->count = 1; |
|
167 } |
|
168 |
2386
|
169 idx_vector (double d) |
|
170 { |
|
171 rep = new idx_vector_rep (d); |
|
172 rep->count = 1; |
|
173 } |
|
174 |
3928
|
175 idx_vector (int i) |
|
176 { |
|
177 rep = new idx_vector_rep (i); |
|
178 rep->count = 1; |
|
179 } |
|
180 |
1560
|
181 idx_vector (char c) |
|
182 { |
|
183 rep = new idx_vector_rep (c); |
|
184 rep->count = 1; |
|
185 } |
|
186 |
2828
|
187 idx_vector (bool b) |
|
188 { |
|
189 rep = new idx_vector_rep (b); |
|
190 rep->count = 1; |
|
191 } |
|
192 |
|
193 idx_vector (const boolMatrix& bm) |
|
194 { |
|
195 rep = new idx_vector_rep (bm); |
|
196 rep->count = 1; |
|
197 } |
|
198 |
1560
|
199 idx_vector (const idx_vector& a) |
|
200 { |
|
201 rep = a.rep; |
|
202 rep->count++; |
1551
|
203 } |
|
204 |
2802
|
205 ~idx_vector (void) |
1560
|
206 { |
|
207 if (--rep->count <= 0) |
|
208 delete rep; |
|
209 } |
1
|
210 |
1560
|
211 idx_vector& operator = (const idx_vector& a) |
|
212 { |
|
213 if (this != &a) |
|
214 { |
|
215 if (--rep->count <= 0) |
|
216 delete rep; |
1
|
217 |
1560
|
218 rep = a.rep; |
|
219 rep->count++; |
|
220 } |
|
221 return *this; |
1551
|
222 } |
|
223 |
3145
|
224 operator bool () const { return rep->ok (); } |
1560
|
225 |
2802
|
226 int capacity (void) const { return rep->capacity (); } |
|
227 int length (int cl) const { return rep->length (cl); } |
191
|
228 |
2802
|
229 int elem (int n) const { return rep->elem (n); } |
|
230 int checkelem (int n) const { return rep->checkelem (n); } |
|
231 int operator () (int n) const { return rep->operator () (n); } |
1
|
232 |
2802
|
233 int max (void) const { return rep->max (); } |
|
234 int min (void) const { return rep->min (); } |
1551
|
235 |
2802
|
236 int one_zero_only (void) const { return rep->one_zero_only (); } |
|
237 int zeros_count (void) const { return rep->zeros_count (); } |
|
238 int ones_count (void) const { return rep->ones_count (); } |
1
|
239 |
1560
|
240 int is_colon (void) const { return rep->is_colon (); } |
2356
|
241 int is_colon_equiv (int n, int sort_uniq = 0) const |
|
242 { return rep->is_colon_equiv (n, sort_uniq); } |
1
|
243 |
3079
|
244 void sort (bool uniq = false) { rep->sort (uniq); } |
|
245 |
1560
|
246 int orig_rows (void) const { return rep->orig_rows (); } |
|
247 int orig_columns (void) const { return rep->orig_columns (); } |
208
|
248 |
2663
|
249 int orig_empty (void) const |
|
250 { |
|
251 return (! is_colon () |
|
252 && (orig_rows () == 0 || orig_columns () == 0)); |
|
253 } |
|
254 |
1560
|
255 // Unsafe. Avoid at all cost. |
|
256 void shorten (int n) { rep->shorten (n); } |
434
|
257 |
1
|
258 // i/o |
|
259 |
4461
|
260 int freeze (int z_len, const char *tag, bool resize_ok = false, |
|
261 bool warn_resize = false) |
|
262 { return rep->freeze (z_len, tag, resize_ok, warn_resize); } |
1560
|
263 |
3504
|
264 std::ostream& print (std::ostream& os) const { return rep->print (os); } |
1560
|
265 |
3504
|
266 friend std::ostream& operator << (std::ostream& os, const idx_vector& a) |
1560
|
267 { return a.print (os); } |
|
268 |
2828
|
269 void maybe_convert_one_zero_to_idx (int z_len) |
|
270 { rep->maybe_convert_one_zero_to_idx (z_len); } |
1
|
271 |
|
272 private: |
|
273 |
1560
|
274 idx_vector_rep *rep; |
1
|
275 |
1560
|
276 void init_state (void) { rep->init_state (); } |
1
|
277 }; |
|
278 |
|
279 #endif |
|
280 |
|
281 /* |
|
282 ;;; Local Variables: *** |
|
283 ;;; mode: C++ *** |
|
284 ;;; End: *** |
|
285 */ |