changeset 4997:d117a9fb83be

[project @ 2004-09-15 20:49:21 by jwe]
author jwe
date Wed, 15 Sep 2004 20:49:35 +0000
parents fcbdb120450a
children 3f3d6eec0a2c
files src/ChangeLog src/DLD-FUNCTIONS/sort.cc src/ov.cc src/ov.h
diffstat 4 files changed, 70 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Sep 15 20:44:39 2004 +0000
+++ b/src/ChangeLog	Wed Sep 15 20:49:35 2004 +0000
@@ -1,3 +1,33 @@
+2004-09-15  David Bateman  <dbateman@free.fr>
+
+	* ov.cc (octave_value::octave_value (const ArrayN<char>&, bool)):
+	New Constructor .
+	* ov.h: Provide decl.
+
+	* DLD-FUNCTIONS/sort.cc (sortmode): New enum to define sort direction.
+	(template <class T> class vec_index): New class to contain values and
+	index for indexed sorts, replacing all previous struct versions. 
+	Instantiate for double, Complex, char and octave_value.
+	(template <class T> static octave_value_list mx_sort (ArrayN<T> &, int,
+	sortmode)): New templated version of mx_sort replacing all previous
+	versions, but specific to non indexed sorts. Instantiate for char
+	and double if not IEEE754.
+	(template <> static octave_value_list mx_sort (ArrayN<double> &, 
+	int, sortmode)): Specialized function of mx_sort of IEEE754.
+	(template <class T> static octave_value_list mx_sort_indexed 
+	(ArrayN<T> &, int, sortmode)): New templated version of mx_sort 
+	for indexed sorts. Instantiate for double, Complex, char and 
+	octave_value.
+	(ascending_compare, descending_compare): Comparison functions
+	for double, char, vec_index<double> *, vec_index<Complex> *,
+	vec_index<char> *, vec_index<octave_value>. Fix Complex comparison
+	operator to sort by arg of values if absolute values are equal.
+	(Fsort): Update docs for new mode argument and for sorting of 
+	strings and cell arrays of strings. Implement mode argument to
+	define ascending and descending sorts. Include sorting of cell
+	arrays of strings. Adapt for new templated versions of the mx_sort
+	function.
+
 2004-09-15  John W. Eaton  <jwe@octave.org>
 
 	* ov-cell.cc (octave_cell::subsref): Pass nargout to next_subsref.
--- a/src/DLD-FUNCTIONS/sort.cc	Wed Sep 15 20:44:39 2004 +0000
+++ b/src/DLD-FUNCTIONS/sort.cc	Wed Sep 15 20:49:35 2004 +0000
@@ -38,13 +38,13 @@
 #include "ov-cell.h"
 #include "oct-sort.cc"
 
-enum sortmode {UNDEFINED, ASCENDING, DESCENDING};
+enum sortmode { UNDEFINED, ASCENDING, DESCENDING };
 
 template <class T>
 class
 vec_index
 {
- public:
+public:
   T vec;
   int indx;
 };
@@ -74,11 +74,13 @@
     sort.set_compare (descending_compare);
 
   if (stride == 1)
-    for (unsigned int j = 0; j < iter; j++)
-      {
-	sort.sort (v, ns);
-	v += ns;
-      }
+    {
+      for (unsigned int j = 0; j < iter; j++)
+	{
+	  sort.sort (v, ns);
+	  v += ns;
+	}
+    }
   else
     {
       OCTAVE_LOCAL_BUFFER (T, vi, ns);
@@ -103,7 +105,8 @@
 	}
     }
 
-  retval (0) = octave_value (m);
+  retval(0) = octave_value (m);
+
   return retval;
 }
 
@@ -190,8 +193,8 @@
 	}
     }
 
-  retval (1) = idx;
-  retval (0) = octave_value (m);
+  retval(1) = idx;
+  retval(0) = octave_value (m);
   return retval;
 }
 
@@ -301,7 +304,7 @@
 	    {
 	      unsigned int i = 0;
 	      double *vtmp = (double *)p;
-	      while (xisnan(vtmp[i++]) && i < ns);
+	      while (xisnan (vtmp[i++]) && i < ns);
 	      for (unsigned int l = 0; l < ns - i + 1; l++)
 		vtmp[l] = vtmp[l+i-1];
 	      for (unsigned int l = ns - i + 1; l < ns; l++)
@@ -350,7 +353,7 @@
 	      (! lo_ieee_signbit (octave_NaN) && (mode == DESCENDING)))
 	    {
 	      unsigned int i = 0;
-	      while (xisnan(v[i++*stride + offset]) && i < ns);
+	      while (xisnan (v[i++*stride + offset]) && i < ns);
 	      for (unsigned int l = 0; l < ns - i + 1; l++)
 		v[l*stride + offset] = v[(l+i-1)*stride + offset];
 	      for (unsigned int l = ns - i + 1; l < ns; l++)
@@ -437,7 +440,7 @@
 	  (! lo_ieee_signbit (octave_NaN) && (mode == DESCENDING)))
 	{
 	  unsigned int i = 0;
-	  while (xisnan(v[i++*stride+offset]) && i < ns);
+	  while (xisnan (v[i++*stride+offset]) && i < ns);
 	  OCTAVE_LOCAL_BUFFER (double, itmp, i - 1);
 	  for (unsigned int l = 0; l < i -1; l++)
 	    itmp[l] = idx(l*stride + offset);
@@ -454,8 +457,8 @@
 	}
     }
 
-  retval (1) = idx;
-  retval (0) = m;
+  retval(1) = idx;
+  retval(0) = m;
   return retval;
 }
 
@@ -464,25 +467,25 @@
 bool
 ascending_compare (double a, double b)
 {
-  return (xisnan(b) || (a < b));
+  return (xisnan (b) || (a < b));
 }
 
 bool
 ascending_compare (vec_index<double> *a, vec_index<double> *b)
 {
-  return (xisnan(b->vec) || (a->vec < b->vec));
+  return (xisnan (b->vec) || (a->vec < b->vec));
 }
 
 bool
 descending_compare (double a, double b)
 {
-  return (xisnan(a) || (a > b));
+  return (xisnan (a) || (a > b));
 }
 
 bool
 descending_compare (vec_index<double> *a, vec_index<double> *b)
 {
-  return (xisnan(a->vec) || (a->vec > b->vec));
+  return (xisnan (a->vec) || (a->vec > b->vec));
 }
 
 template class octave_sort<double>;
@@ -508,15 +511,19 @@
 bool
 ascending_compare (vec_index<Complex> *a, vec_index<Complex> *b)
 {
-  return (xisnan(b->vec) || (xabs(a->vec) < xabs(b->vec)) ||
-	  ((xabs(a->vec) == xabs(b->vec)) && (arg(a->vec) < arg(b->vec))));
+  return (xisnan (b->vec)
+	  || (xabs (a->vec) < xabs (b->vec))
+	  || ((xabs (a->vec) == xabs (b->vec))
+	      && (arg (a->vec) < arg (b->vec))));
 }
 
 bool
 descending_compare (vec_index<Complex> *a, vec_index<Complex> *b)
 {
-  return (xisnan(a->vec) || (xabs(a->vec) > xabs(b->vec)) ||
-	  ((xabs(a->vec) == xabs(b->vec)) && (arg(a->vec) > arg(b->vec))));
+  return (xisnan (a->vec)
+	  || (xabs (a->vec) > xabs (b->vec))
+	  || ((xabs (a->vec) == xabs (b->vec))
+	      && (arg (a->vec) > arg (b->vec))));
 }
 
 template class vec_index<Complex>;
--- a/src/ov.cc	Wed Sep 15 20:44:39 2004 +0000
+++ b/src/ov.cc	Wed Sep 15 20:49:35 2004 +0000
@@ -597,6 +597,15 @@
   maybe_mutate ();
 }
 
+octave_value::octave_value (const ArrayN<char>& chm, bool is_str)
+  : rep (is_str
+	 ? new octave_char_matrix_str (chm)
+	 : new octave_char_matrix (chm))
+{
+  rep->count = 1;
+  maybe_mutate ();
+}
+
 octave_value::octave_value (const octave_int8& i)
   : rep (new octave_int8_scalar (i))
 {
--- a/src/ov.h	Wed Sep 15 20:44:39 2004 +0000
+++ b/src/ov.h	Wed Sep 15 20:49:35 2004 +0000
@@ -217,6 +217,7 @@
   octave_value (const string_vector& s);
   octave_value (const charMatrix& chm, bool is_string = false);
   octave_value (const charNDArray& chnda, bool is_string = false);
+  octave_value (const ArrayN<char>& chnda, bool is_string = false);
   octave_value (const octave_int8& i);
   octave_value (const octave_int16& i);
   octave_value (const octave_int32& i);