Mercurial > hg > octave-lyh
annotate src/oct-map.cc @ 9379:d77fa87c47d8
oct-map.cc: preserve key order
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 23 Jun 2009 09:55:53 -0400 |
parents | 5ec4dc52c131 |
children | 182b7088af1c |
rev | line source |
---|---|
1278 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1995, 1996, 1997, 2002, 2003, 2004, 2005, 2006, 2007, |
4 2008, 2009 John W. Eaton | |
1278 | 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. | |
1278 | 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/>. | |
1278 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
3932 | 28 #include "error.h" |
1755 | 29 #include "str-vec.h" |
30 | |
1278 | 31 #include "oct-map.h" |
32 #include "utils.h" | |
33 | |
6959 | 34 Octave_map::Octave_map (const dim_vector& dv, const Cell& key_vals) |
5880 | 35 : map (), key_list (), dimensions (dv) |
36 { | |
37 Cell c (dv); | |
38 | |
6959 | 39 if (key_vals.is_cellstr ()) |
5880 | 40 { |
6959 | 41 for (octave_idx_type i = 0; i < key_vals.numel (); i++) |
6946 | 42 { |
6959 | 43 std::string k = key_vals(i).string_value (); |
6946 | 44 map[k] = c; |
45 key_list.push_back (k); | |
46 } | |
5880 | 47 } |
6946 | 48 else |
49 error ("Octave_map: expecting keys to be cellstr"); | |
5880 | 50 } |
51 | |
7046 | 52 Octave_map |
53 Octave_map::squeeze (void) const | |
54 { | |
55 Octave_map retval (dims ().squeeze ()); | |
56 | |
57 for (const_iterator pa = begin (); pa != end (); pa++) | |
58 { | |
59 Cell tmp = contents (pa).squeeze (); | |
60 | |
61 if (error_state) | |
62 break; | |
63 | |
64 retval.assign (key (pa), tmp); | |
65 } | |
66 | |
9379
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
67 // Preserve order of keys. |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
68 retval.key_list = key_list; |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
69 |
7046 | 70 return retval; |
71 } | |
72 | |
73 Octave_map | |
74 Octave_map::permute (const Array<int>& vec, bool inv) const | |
75 { | |
76 Octave_map retval (dims ()); | |
77 | |
78 for (const_iterator pa = begin (); pa != end (); pa++) | |
79 { | |
80 Cell tmp = contents (pa).permute (vec, inv); | |
81 | |
82 if (error_state) | |
83 break; | |
84 | |
85 retval.assign (key (pa), tmp); | |
86 } | |
87 | |
9379
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
88 // Preserve order of keys. |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
89 retval.key_list = key_list; |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
90 |
7046 | 91 return retval; |
92 } | |
93 | |
5328 | 94 Cell& |
95 Octave_map::contents (const std::string& k) | |
96 { | |
5880 | 97 maybe_add_to_key_list (k); |
98 | |
5328 | 99 return map[k]; |
100 } | |
101 | |
4513 | 102 Cell |
4675 | 103 Octave_map::contents (const std::string& k) const |
4197 | 104 { |
4587 | 105 const_iterator p = seek (k); |
4197 | 106 |
4513 | 107 return p != end () ? p->second : Cell (); |
4197 | 108 } |
109 | |
5156 | 110 int |
111 Octave_map::intfield (const std::string& k, int def_val) const | |
112 { | |
113 int retval = def_val; | |
114 | |
115 Cell c = contents (k); | |
116 | |
117 if (! c.is_empty ()) | |
118 retval = c(0).int_value (); | |
119 | |
120 return retval; | |
121 } | |
122 | |
123 std::string | |
124 Octave_map::stringfield (const std::string& k, | |
125 const std::string& def_val) const | |
126 { | |
127 std::string retval = def_val; | |
128 | |
129 Cell c = contents (k); | |
130 | |
131 if (! c.is_empty ()) | |
132 retval = c(0).string_value (); | |
133 | |
134 return retval; | |
135 } | |
136 | |
1755 | 137 string_vector |
3933 | 138 Octave_map::keys (void) const |
1278 | 139 { |
6639 | 140 assert (nfields () == key_list.size ()); |
5881 | 141 |
5880 | 142 return string_vector (key_list); |
1278 | 143 } |
144 | |
4567 | 145 Octave_map |
5571 | 146 Octave_map::transpose (void) const |
147 { | |
148 assert (ndims () == 2); | |
5593 | 149 |
5571 | 150 dim_vector dv = dims (); |
151 | |
5593 | 152 octave_idx_type nr = dv(0); |
153 octave_idx_type nc = dv(1); | |
154 | |
155 dim_vector new_dims (nc, nr); | |
156 | |
157 Octave_map retval (new_dims); | |
5571 | 158 |
159 for (const_iterator p = begin (); p != end (); p++) | |
160 retval.assign (key(p), Cell (contents(p).transpose ())); | |
161 | |
9379
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
162 // Preserve order of keys. |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
163 retval.key_list = key_list; |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
164 |
5571 | 165 return retval; |
166 } | |
167 | |
168 Octave_map | |
4567 | 169 Octave_map::reshape (const dim_vector& new_dims) const |
170 { | |
171 Octave_map retval; | |
172 | |
173 if (new_dims != dims ()) | |
174 { | |
175 for (const_iterator p = begin (); p != end (); p++) | |
4675 | 176 retval.assign (key(p), contents(p).reshape (new_dims)); |
4567 | 177 |
4936 | 178 retval.dimensions = new_dims; |
9379
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
179 |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
180 // Preserve order of keys. |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
181 retval.key_list = key_list; |
4567 | 182 } |
4936 | 183 else |
184 retval = *this; | |
4567 | 185 |
186 return retval; | |
187 } | |
188 | |
5781 | 189 void |
190 Octave_map::resize (const dim_vector& dv, bool fill) | |
4936 | 191 { |
192 if (dv != dims ()) | |
193 { | |
6639 | 194 if (nfields () == 0) |
6609 | 195 dimensions = dv; |
196 else | |
4936 | 197 { |
6609 | 198 for (const_iterator p = begin (); p != end (); p++) |
199 { | |
200 Cell tmp = contents(p); | |
5781 | 201 |
6609 | 202 if (fill) |
203 tmp.resize(dv, Cell::resize_fill_value ()); | |
204 else | |
205 tmp.resize(dv); | |
5781 | 206 |
6609 | 207 dimensions = dv; |
5781 | 208 |
6609 | 209 assign (key(p), tmp); |
210 } | |
9379
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
211 |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
212 // Preserve order of keys. |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
213 retval.key_list = key_list; |
4936 | 214 } |
215 } | |
216 } | |
217 | |
4915 | 218 Octave_map |
5275 | 219 Octave_map::concat (const Octave_map& rb, const Array<octave_idx_type>& ra_idx) |
4806 | 220 { |
4937 | 221 Octave_map retval; |
4936 | 222 |
6639 | 223 if (nfields () == rb.nfields ()) |
4936 | 224 { |
5881 | 225 for (const_iterator pa = begin (); pa != end (); pa++) |
4936 | 226 { |
5881 | 227 const_iterator pb = rb.seek (key(pa)); |
4937 | 228 |
5003 | 229 if (pb == rb.end ()) |
4937 | 230 { |
231 error ("field name mismatch in structure concatenation"); | |
232 break; | |
233 } | |
4936 | 234 |
5073 | 235 retval.assign (key(pa), |
236 contents(pa).insert (rb.contents(pb), ra_idx)); | |
4937 | 237 } |
9379
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
238 |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
239 // Preserve order of keys. |
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
240 retval.key_list = key_list; |
4936 | 241 } |
4937 | 242 else |
7959
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
243 { |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
244 dim_vector dv = dims (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
245 |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
246 if (dv.all_zero ()) |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
247 retval = rb; |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
248 else |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
249 { |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
250 dv = rb.dims (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
251 |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
252 if (dv.all_zero ()) |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
253 retval = *this; |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
254 else |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
255 error ("invalid structure concatenation"); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
256 } |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7046
diff
changeset
|
257 } |
4937 | 258 |
4915 | 259 return retval; |
4806 | 260 } |
261 | |
6609 | 262 static bool |
263 keys_ok (const Octave_map& a, const Octave_map& b, string_vector& keys) | |
4197 | 264 { |
6609 | 265 bool retval = false; |
266 | |
267 keys = string_vector (); | |
4197 | 268 |
6639 | 269 if (a.nfields () == 0) |
6609 | 270 { |
271 keys = b.keys (); | |
272 retval = true; | |
273 } | |
274 else | |
275 { | |
8503
8ba2ee57c594
remove qsort in favor of sort
Jaroslav Hajek <highegg@gmail.com>
parents:
8294
diff
changeset
|
276 string_vector a_keys = a.keys().sort (); |
8ba2ee57c594
remove qsort in favor of sort
Jaroslav Hajek <highegg@gmail.com>
parents:
8294
diff
changeset
|
277 string_vector b_keys = b.keys().sort (); |
4197 | 278 |
6609 | 279 octave_idx_type a_len = a_keys.length (); |
280 octave_idx_type b_len = b_keys.length (); | |
281 | |
282 if (a_len == b_len) | |
4197 | 283 { |
6609 | 284 for (octave_idx_type i = 0; i < a_len; i++) |
285 { | |
286 if (a_keys[i] != b_keys[i]) | |
287 goto done; | |
288 } | |
4197 | 289 |
6609 | 290 keys = a_keys; |
291 retval = true; | |
292 } | |
4197 | 293 } |
6609 | 294 |
295 done: | |
4197 | 296 return retval; |
297 } | |
298 | |
299 Octave_map& | |
5592 | 300 Octave_map::maybe_delete_elements (const octave_value_list& idx) |
301 { | |
302 string_vector t_keys = keys(); | |
303 octave_idx_type len = t_keys.length (); | |
304 | |
305 if (len > 0) | |
306 { | |
307 for (octave_idx_type i = 0; i < len; i++) | |
308 { | |
309 std::string k = t_keys[i]; | |
310 | |
8175
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
7959
diff
changeset
|
311 map[k] = contents(k).delete_elements (idx); |
5592 | 312 |
313 if (error_state) | |
314 break; | |
315 } | |
316 | |
317 if (!error_state) | |
318 dimensions = contents(t_keys[0]).dims(); | |
319 } | |
320 | |
321 return *this; | |
322 } | |
323 | |
324 Octave_map& | |
4513 | 325 Octave_map::assign (const octave_value_list& idx, const Octave_map& rhs) |
4197 | 326 { |
6609 | 327 string_vector t_keys; |
4197 | 328 |
6609 | 329 if (keys_ok (*this, rhs, t_keys)) |
4197 | 330 { |
5275 | 331 octave_idx_type len = t_keys.length (); |
4197 | 332 |
6609 | 333 if (len == 0) |
4197 | 334 { |
6609 | 335 Cell tmp_lhs (dims ()); |
336 Cell tmp_rhs (rhs.dims ()); | |
337 | |
338 tmp_lhs.assign (idx, tmp_rhs, Matrix ()); | |
4197 | 339 |
6609 | 340 if (! error_state) |
341 resize (tmp_lhs.dims ()); | |
342 else | |
343 error ("size mismatch in structure assignment"); | |
344 } | |
345 else | |
346 { | |
347 for (octave_idx_type i = 0; i < len; i++) | |
348 { | |
349 std::string k = t_keys[i]; | |
4197 | 350 |
6609 | 351 Cell t_rhs = rhs.contents (k); |
352 | |
353 assign (idx, k, t_rhs); | |
4197 | 354 |
6609 | 355 if (error_state) |
356 break; | |
357 } | |
4197 | 358 } |
359 } | |
360 else | |
361 error ("field name mismatch in structure assignment"); | |
362 | |
363 return *this; | |
364 } | |
365 | |
3932 | 366 Octave_map& |
4587 | 367 Octave_map::assign (const octave_value_list& idx, const std::string& k, |
4513 | 368 const Cell& rhs) |
3932 | 369 { |
5881 | 370 Cell tmp; |
371 | |
372 if (contains (k)) | |
373 tmp = map[k]; | |
9127
5ec4dc52c131
fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
374 else |
5ec4dc52c131
fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
375 tmp = Cell (dimensions); |
3932 | 376 |
9127
5ec4dc52c131
fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
377 tmp.assign (idx, rhs); |
3932 | 378 |
379 if (! error_state) | |
380 { | |
9127
5ec4dc52c131
fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
381 dim_vector tmp_dims = tmp.dims (); |
3932 | 382 |
9127
5ec4dc52c131
fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
383 if (tmp_dims != dimensions) |
3943 | 384 { |
4219 | 385 for (iterator p = begin (); p != end (); p++) |
9127
5ec4dc52c131
fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
386 contents(p).resize (tmp_dims, Cell::resize_fill_value ()); |
5ec4dc52c131
fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
387 |
5ec4dc52c131
fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
388 dimensions = tmp_dims; |
4561 | 389 } |
3932 | 390 |
5880 | 391 maybe_add_to_key_list (k); |
392 | |
4587 | 393 map[k] = tmp; |
3932 | 394 } |
395 | |
396 return *this; | |
397 } | |
398 | |
3933 | 399 Octave_map& |
4675 | 400 Octave_map::assign (const std::string& k, const octave_value& rhs) |
401 { | |
6639 | 402 if (nfields () == 0) |
4675 | 403 { |
5880 | 404 maybe_add_to_key_list (k); |
405 | |
4675 | 406 map[k] = Cell (rhs); |
407 | |
408 dimensions = dim_vector (1, 1); | |
409 } | |
410 else | |
411 { | |
412 dim_vector dv = dims (); | |
413 | |
414 if (dv.all_ones ()) | |
5880 | 415 { |
416 maybe_add_to_key_list (k); | |
417 | |
418 map[k] = Cell (rhs); | |
419 } | |
4675 | 420 else |
421 error ("invalid structure assignment"); | |
422 } | |
423 | |
424 return *this; | |
425 } | |
426 | |
427 Octave_map& | |
4587 | 428 Octave_map::assign (const std::string& k, const Cell& rhs) |
3933 | 429 { |
6639 | 430 if (nfields () == 0) |
4563 | 431 { |
5880 | 432 maybe_add_to_key_list (k); |
433 | |
4587 | 434 map[k] = rhs; |
4563 | 435 |
4730 | 436 dimensions = rhs.dims (); |
4563 | 437 } |
3933 | 438 else |
439 { | |
4562 | 440 if (dims () == rhs.dims ()) |
5880 | 441 { |
442 maybe_add_to_key_list (k); | |
443 | |
444 map[k] = rhs; | |
445 } | |
3933 | 446 else |
447 error ("invalid structure assignment"); | |
448 } | |
449 | |
450 return *this; | |
451 } | |
452 | |
453 Octave_map | |
7046 | 454 Octave_map::index (const octave_value_list& idx, bool resize_ok) const |
3933 | 455 { |
456 Octave_map retval; | |
9379
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
457 |
8682
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
458 octave_idx_type n_idx = idx.length (); |
9379
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
459 |
8682
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
460 if (n_idx > 0) |
3933 | 461 { |
8682
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
462 Array<idx_vector> ra_idx (n_idx); |
9379
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
463 |
8682
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
464 for (octave_idx_type i = 0; i < n_idx; i++) |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
465 { |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
466 ra_idx(i) = idx(i).index_vector (); |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
467 if (error_state) |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
468 break; |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
469 } |
3933 | 470 |
8682
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
471 if (! error_state) |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
472 { |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
473 for (const_iterator p = begin (); p != end (); p++) |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
474 { |
9379
d77fa87c47d8
oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents:
9127
diff
changeset
|
475 Cell tmp = contents (p); |
8682
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
476 |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
477 tmp = tmp.ArrayN<octave_value>::index (ra_idx, resize_ok); |
3933 | 478 |
8682
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
479 if (error_state) |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
480 break; |
8294
b2a6309b2d87
oct-map.cc: copy key_list in indexing functions
John W. Eaton <jwe@octave.org>
parents:
8175
diff
changeset
|
481 |
8682
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
482 retval.assign (key(p), tmp); |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
483 } |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
484 |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
485 // Preserve order of keys. |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
486 retval.key_list = key_list; |
38968f09f7ca
optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
487 } |
3933 | 488 } |
5435 | 489 else |
5539 | 490 retval = *this; |
3933 | 491 |
5539 | 492 return retval; |
3933 | 493 } |
494 | |
1278 | 495 /* |
496 ;;; Local Variables: *** | |
497 ;;; mode: C++ *** | |
498 ;;; End: *** | |
499 */ |