comparison liboctave/Array.cc @ 9310:256c0db275b6

fix behavior of find
author Jaroslav Hajek <highegg@gmail.com>
date Sun, 07 Jun 2009 08:15:31 +0200
parents 3c1762c7e787
children 9fd5c56ce57a
comparison
equal deleted inserted replaced
9309:fb8b8589dd46 9310:256c0db275b6
2474 { 2474 {
2475 Array<octave_idx_type> retval; 2475 Array<octave_idx_type> retval;
2476 const T *src = data (); 2476 const T *src = data ();
2477 octave_idx_type nel = nelem (); 2477 octave_idx_type nel = nelem ();
2478 const T zero = T (); 2478 const T zero = T ();
2479 if (n < 0) 2479 if (n < 0 || n >= nel)
2480 { 2480 {
2481 // We want all elements, which means we'll almost surely need 2481 // We want all elements, which means we'll almost surely need
2482 // to resize. So count first, then allocate array of exact size. 2482 // to resize. So count first, then allocate array of exact size.
2483 octave_idx_type cnt = 0; 2483 octave_idx_type cnt = 0;
2484 for (octave_idx_type i = 0; i < nel; i++) 2484 for (octave_idx_type i = 0; i < nel; i++)
2507 else 2507 else
2508 break; 2508 break;
2509 } 2509 }
2510 if (k < n) 2510 if (k < n)
2511 retval.resize (k); 2511 retval.resize (k);
2512 octave_idx_type *rdata = retval.fortran_vec ();
2513 std::reverse (rdata, rdata + k);
2512 } 2514 }
2513 else 2515 else
2514 { 2516 {
2515 // Do the search as a series of successive single-element searches. 2517 // Do the search as a series of successive single-element searches.
2516 octave_idx_type k = 0, l = 0; 2518 octave_idx_type k = 0, l = 0;