changeset 8678:e2b4c19c455c

redo changeset 4238f2600a17 with fixes to sorting
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 04 Feb 2009 16:05:01 +0100
parents 095ae5e0a831
children 280fae940bb0
files liboctave/Array-str.cc liboctave/ChangeLog liboctave/oct-sort.cc liboctave/str-vec.cc liboctave/str-vec.h
diffstat 5 files changed, 28 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- 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 <config.h>
 #endif
 
+#include <string>
+
 // Instantiate Arrays of strings.
 
 #include "Array.h"
 #include "Array.cc"
 #include "oct-sort.cc"
 
-#include <string>
-
 INSTANTIATE_ARRAY_SORT (std::string);
 
 INSTANTIATE_ARRAY (std::string, OCTAVE_API);
--- 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  <highegg@gmail.com>
+
+	* 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<T>::merge_hi): std::copy ->
+	std::copy_backward where appropriate.
+
 2009-02-05  John W. Eaton  <jwe@octave.org>
 
 	* Array-util.cc (zero_dims_inquire): Eliminate unused variable MATCH.
--- 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;
--- 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<std::string>::sort () to allow sorting in place.
+  octave_sort<std::string> lsort;
+  lsort.sort (Array<std::string>::fortran_vec (), length ());
+
+  if (make_uniq)
+    uniq ();
+
+  return *this;
+}
+string_vector&
 string_vector::uniq (void)
 {
   octave_idx_type len = length ();
--- 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<std::string>::elem (i); }
 
-  string_vector& sort (bool make_uniq = false)
-  {
-    Array<std::string>::sort ();
-
-    if (make_uniq)
-      uniq ();
-
-    return *this;
-  }
+  string_vector& sort (bool make_uniq = false);
 
   string_vector& uniq (void);