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