# HG changeset patch # User Jaroslav Hajek # Date 1233759901 -3600 # Node ID e2b4c19c455cda890e00299829c524e11d9e15e2 # Parent 095ae5e0a8313340f5ecb4de80e70d39abe91566 redo changeset 4238f2600a17 with fixes to sorting diff -r 095ae5e0a831 -r e2b4c19c455c liboctave/Array-str.cc --- a/liboctave/Array-str.cc Thu Feb 05 02:42:58 2009 -0500 +++ b/liboctave/Array-str.cc Wed Feb 04 16:05:01 2009 +0100 @@ -24,14 +24,14 @@ #include #endif +#include + // Instantiate Arrays of strings. #include "Array.h" #include "Array.cc" #include "oct-sort.cc" -#include - INSTANTIATE_ARRAY_SORT (std::string); INSTANTIATE_ARRAY (std::string, OCTAVE_API); diff -r 095ae5e0a831 -r e2b4c19c455c liboctave/ChangeLog --- a/liboctave/ChangeLog Thu Feb 05 02:42:58 2009 -0500 +++ b/liboctave/ChangeLog Wed Feb 04 16:05:01 2009 +0100 @@ -1,3 +1,11 @@ +2009-02-05 Jaroslav Hajek + + * str-vec.h (string_vector::sort): Remove implementation. + * str-vec.cc (string_vector::sort): Move here. Use in-place sorting. + * Array-str.cc: Fix order of header files. + * oct-sort.cc (octave_sort::merge_hi): std::copy -> + std::copy_backward where appropriate. + 2009-02-05 John W. Eaton * Array-util.cc (zero_dims_inquire): Eliminate unused variable MATCH. diff -r 095ae5e0a831 -r e2b4c19c455c liboctave/oct-sort.cc --- a/liboctave/oct-sort.cc Thu Feb 05 02:42:58 2009 -0500 +++ b/liboctave/oct-sort.cc Wed Feb 04 16:05:01 2009 +0100 @@ -29,8 +29,9 @@ replacing PyObject* with the type of the class T. * replaced usages of malloc, free, memcpy and memmove by standard C++ - new [], delete [] and std::copy. Note that replacing memmove by std::copy - is possible if the destination starts before the source. + new [], delete [] and std::copy and std::copy_backward. Note that replacing + memmove by std::copy is possible if the destination starts before the source. + If not, std::copy_backward needs to be used. The Python license is @@ -733,7 +734,7 @@ { dest -= k; pa -= k; - std::copy (pa+1, pa+1 + k, dest+1); + std::copy_backward (pa+1, pa+1 + k, dest+1 + k); na -= k; if (na == 0) goto Succeed; @@ -784,7 +785,7 @@ /* The first element of pb belongs at the front of the merge. */ dest -= na; pa -= na; - std::copy (pa+1, pa+1 + na, dest+1); + std::copy_backward (pa+1, pa+1 + na, dest+1 + na); *dest = *pb; return 0; diff -r 095ae5e0a831 -r e2b4c19c455c liboctave/str-vec.cc --- a/liboctave/str-vec.cc Thu Feb 05 02:42:58 2009 -0500 +++ b/liboctave/str-vec.cc Wed Feb 04 16:05:01 2009 +0100 @@ -84,6 +84,18 @@ } string_vector& +string_vector::sort (bool make_uniq) +{ + // Don't use Array::sort () to allow sorting in place. + octave_sort lsort; + lsort.sort (Array::fortran_vec (), length ()); + + if (make_uniq) + uniq (); + + return *this; +} +string_vector& string_vector::uniq (void) { octave_idx_type len = length (); diff -r 095ae5e0a831 -r e2b4c19c455c liboctave/str-vec.h --- a/liboctave/str-vec.h Thu Feb 05 02:42:58 2009 -0500 +++ b/liboctave/str-vec.h Wed Feb 04 16:05:01 2009 +0100 @@ -84,15 +84,7 @@ std::string operator[] (octave_idx_type i) const { return Array::elem (i); } - string_vector& sort (bool make_uniq = false) - { - Array::sort (); - - if (make_uniq) - uniq (); - - return *this; - } + string_vector& sort (bool make_uniq = false); string_vector& uniq (void);