From 4e0ab443ac628a90f160f95f517324011e8c11a2 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 7 Jun 2012 13:38:28 +0000 Subject: [PATCH] Sort ascending and descending. --- src/MEDCoupling/MEDCouplingMemArray.cxx | 8 ++++---- src/MEDCoupling/MEDCouplingMemArray.hxx | 6 +++--- src/MEDCoupling/MEDCouplingMemArray.txx | 11 +++++++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 4ae256deb..ad9573207 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -495,12 +495,12 @@ bool DataArrayDouble::isUniform(double val, double eps) const throw(INTERP_KERNE return true; } -void DataArrayDouble::sort() throw(INTERP_KERNEL::Exception) +void DataArrayDouble::sort(bool asc) throw(INTERP_KERNEL::Exception) { checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayDouble::sort : only supported with 'this' array with ONE component !"); - _mem.sort(); + _mem.sort(asc); } void DataArrayDouble::reverse() throw(INTERP_KERNEL::Exception) @@ -3289,12 +3289,12 @@ bool DataArrayInt::isEqualWithoutConsideringStrAndOrder(const DataArrayInt& othe return a->isEqualWithoutConsideringStr(*b); } -void DataArrayInt::sort() throw(INTERP_KERNEL::Exception) +void DataArrayInt::sort(bool asc) throw(INTERP_KERNEL::Exception) { checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::sort : only supported with 'this' array with ONE component !"); - _mem.sort(); + _mem.sort(asc); } void DataArrayInt::reverse() throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 141058249..4ce36c639 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -68,7 +68,7 @@ namespace ParaMEDMEM void fillWithValue(const T& val); T *fromNoInterlace(int nbOfComp) const; T *toNoInterlace(int nbOfComp) const; - void sort(); + void sort(bool asc); void reverse(); void alloc(int nbOfElements) throw(INTERP_KERNEL::Exception); void reAlloc(int newNbOfElements) throw(INTERP_KERNEL::Exception); @@ -150,7 +150,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void fillWithValue(double val) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void iota(double init=0.) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isUniform(double val, double eps) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void sort() throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void sort(bool asc=true) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reverse() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception); @@ -333,7 +333,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayInt& other) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *buildPermutationArr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void sort() throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void sort(bool asc=true) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reverse() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void fillWithZero() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void fillWithValue(int val) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 90438b3f7..efca549b5 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -210,10 +210,17 @@ namespace ParaMEDMEM } template - void MemArray::sort() + void MemArray::sort(bool asc) { T *pt=_pointer.getPointer(); - std::sort(pt,pt+_nb_of_elem); + if(asc) + std::sort(pt,pt+_nb_of_elem); + else + { + typename std::reverse_iterator it1(pt+_nb_of_elem); + typename std::reverse_iterator it2(pt); + std::sort(it1,it2); + } } template -- 2.39.2