Salome HOME
DGTUMesh with no cells can be now converted into umesh
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingMemArray.cxx
index a53430517ce3dcda26b4b9a1ac3a7050e1de6f98..28806d19d08a755c9ca918e3c3d427940c22decf 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -3061,6 +3061,15 @@ void DataArrayDouble::useExternalArrayWithRWAccess(const double *array, int nbOf
   declareAsNew();
 }
 
+void DataArrayDouble::aggregate(const DataArrayDouble *other)
+{
+  if(!other)
+    throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : null pointer !");
+  if(getNumberOfComponents()!=other->getNumberOfComponents())
+    throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : mismatch number of components !");
+  _mem.insertAtTheEnd(other->begin(),other->end());
+}
+
 /*!
  * Checks if 0.0 value is present in \a this array. If it is the case, an exception
  * is thrown.
@@ -6907,6 +6916,8 @@ bool DataArrayInt::isFittingWith(const std::vector<bool>& v) const
  * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple equal to \a val
  * put True to the corresponding entry in \a vec.
  * \a vec is expected to be with the same size than the number of tuples of \a this.
+ *
+ *  \sa DataArrayInt::switchOnTupleNotEqualTo.
  */
 void DataArrayInt::switchOnTupleEqualTo(int val, std::vector<bool>& vec) const
 {
@@ -6922,6 +6933,27 @@ void DataArrayInt::switchOnTupleEqualTo(int val, std::vector<bool>& vec) const
       vec[i]=true;
 }
 
+/*!
+ * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple different from \a val
+ * put True to the corresponding entry in \a vec.
+ * \a vec is expected to be with the same size than the number of tuples of \a this.
+ * 
+ *  \sa DataArrayInt::switchOnTupleEqualTo.
+ */
+void DataArrayInt::switchOnTupleNotEqualTo(int val, std::vector<bool>& vec) const
+{
+  checkAllocated();
+  if(getNumberOfComponents()!=1)
+    throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of components of this should be equal to one !");
+  int nbOfTuples(getNumberOfTuples());
+  if(nbOfTuples!=(int)vec.size())
+    throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of tuples of this should be equal to size of input vector of bool !");
+  const int *pt(begin());
+  for(int i=0;i<nbOfTuples;i++)
+    if(pt[i]!=val)
+      vec[i]=true;
+}
+
 /*!
  * Sorts values of the array.
  *  \param [in] asc - \a true means ascending order, \a false, descending.
@@ -7159,6 +7191,15 @@ void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple,
   declareAsNew();
 }
 
+void DataArrayInt::aggregate(const DataArrayInt *other)
+{
+  if(!other)
+    throw INTERP_KERNEL::Exception("DataArrayInt::aggregate : null pointer !");
+  if(getNumberOfComponents()!=other->getNumberOfComponents())
+    throw INTERP_KERNEL::Exception("DataArrayInt::aggregate : mismatch number of components !");
+  _mem.insertAtTheEnd(other->begin(),other->end());
+}
+
 /*!
  * Returns a new DataArrayInt holding the same values as \a this array but differently
  * arranged in memory. If \a this array holds 2 components of 3 values:
@@ -7820,6 +7861,24 @@ bool DataArrayInt::isUniform(int val) const
   return true;
 }
 
+/*!
+ * Checks if all values in \a this array are unique.
+ *  \return bool - \a true if condition above is true
+ *  \throw If \a this is not allocated.
+ *  \throw If \a this->getNumberOfComponents() != 1
+ */
+bool DataArrayInt::hasUniqueValues() const
+{
+  checkAllocated();
+  if(getNumberOfComponents()!=1)
+    throw INTERP_KERNEL::Exception("DataArrayInt::hasOnlyUniqueValues: must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
+  int nbOfTuples(getNumberOfTuples());
+  std::set<int> s(begin(),end());  // in C++11, should use unordered_set (O(1) complexity)
+  if (s.size() != nbOfTuples)
+    return false;
+  return true;
+}
+
 /*!
  * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this
  * array to the new one.
@@ -10737,6 +10796,11 @@ void DataArrayInt::sortEachPairToMakeALinkedList()
                 { tmp[3]=conn[2];}
               std::copy(tmp,tmp+4,conn);
             }
+          else
+            {//here we are sure to have (std::count(conn,conn+4,conn[1])==2)
+              if(conn[1]==conn[3])
+                std::swap(conn[2],conn[3]);
+            }
         }
     }
 }