* - \a this : [0, 1, 1, 2, 2, 3, 4, 4, 5, 5, 5, 11]
* - \a return is : [0, 1, 3, 5, 6, 8, 11, 12]
*
- * \return a newly allocated array containing the indexed array of
+ * \return a newly allocated array containing the indexed array format of groups by same consecutive value.
* \throw if \a this is not allocated or if \a this has not exactly one component or if number of tuples is equal to 0.
* \sa DataArrayInt::buildUnique, MEDCouplingSkyLineArray::groupPacks
*/
MCAuto<MEDCouplingSkyLineArray> ret(MEDCouplingSkyLineArray::New(retIndex,retValues));
return ret.retn();
}
+/*!
+ * Take as input skylinearrays containing the same number of packs ( \a this->getNumberOf ).
+ * For each packs, this method aggregates corresponding pack in \a sks.
+ *
+ * \throw if either a lenght of not nullptr instances in \a sks is zero or if number of packs of not nullptr instances in \a sks is not the same.
+ * \return a newly allocated skyline array that is the aggregated packs of inputs
+ */
+MEDCouplingSkyLineArray *MEDCouplingSkyLineArray::AggregatePacks(const std::vector<const MEDCouplingSkyLineArray *>& sks)
+{
+ std::vector<const MEDCouplingSkyLineArray *>sksEff;
+ mcIdType nbOfPacks(std::numeric_limits<mcIdType>::max());
+ constexpr char MSG[]="MEDCouplingSkyLineArray::AggregatePacks : ";
+ for(auto sk : sks)
+ {
+ if(!sk)
+ {
+ mcIdType curNbPacks(sk->getNumberOf());
+ if(sksEff.empty())
+ nbOfPacks = curNbPacks;
+ if(nbOfPacks != curNbPacks)
+ {
+ std::ostringstream oss; oss << MSG << "first not null input ska has " << nbOfPacks << " whereas there is presence of ska with " << curNbPacks << " !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ sksEff.push_back(sk);
+ }
+ }
+ if(sksEff.empty())
+ {
+ std::ostringstream oss; oss << MSG << "input vector contains no not nullptr elements !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ //
+ MCAuto<DataArrayIdType> index(DataArrayIdType::New()); index->alloc(nbOfPacks+1,1);
+ mcIdType *indexPtr(index->getPointer()); *indexPtr=0;
+ std::vector<const mcIdType *> indicesIn(SkyLineArrayIndexIterator(0,&sksEff),SkyLineArrayIndexIterator(sksEff.size(),&sksEff));
+ for( mcIdType packId = 0 ; packId < nbOfPacks ; ++packId, ++indexPtr )
+ {
+ mcIdType nbOfAggPacks(0);
+ std::for_each(indicesIn.begin(),indicesIn.end(),[packId,&nbOfPacks](const mcIdType *elt) { nbOfPacks+=elt[packId]; });
+ indexPtr[1] = indexPtr[0] + nbOfAggPacks;
+ }
+ mcIdType nbOfTuplesOut(index->back());
+ MCAuto<DataArrayIdType> values(DataArrayIdType::New()); values->alloc(nbOfTuplesOut,1);
+ mcIdType *valuesPtr(values->getPointer());
+ std::vector<const mcIdType *> valuesIn(SkyLineArrayValuesIterator(0,&sksEff),SkyLineArrayValuesIterator(sksEff.size(),&sksEff));
+ //
+ MCAuto<MEDCouplingSkyLineArray> ret;
+ return ret.retn();
+}
/**
* For a 2- or 3-level SkyLine array, return a copy of the absolute pack with given identifier.
MEDCouplingSkyLineArray *groupPacks(const DataArrayIdType *indexedPacks) const;
MEDCouplingSkyLineArray *uniqueNotSortedByPack() const;
+ static MEDCouplingSkyLineArray *AggregatePacks(const std::vector<const MEDCouplingSkyLineArray *>& sks);
void getSimplePackSafe(const mcIdType absolutePackId, std::vector<mcIdType> & pack) const;
const mcIdType * getSimplePackSafePtr(const mcIdType absolutePackId, mcIdType & packSize) const;
MCAuto<DataArrayIdType> _values;
};
+ template<typename T>
+ class SkyLineArrayGenIterator : public std::iterator< std::input_iterator_tag, const mcIdType *, mcIdType, const mcIdType **, const mcIdType *>
+ {
+ std::size_t _num = 0;
+ std::vector<const MEDCouplingSkyLineArray *> *_data = nullptr;
+ public:
+ explicit SkyLineArrayGenIterator(std::size_t num , std::vector<const MEDCouplingSkyLineArray *> *data) : _num(num),_data(data) {}
+ SkyLineArrayGenIterator<T>& operator++() { ++_num; return *this; }
+ bool operator==(const SkyLineArrayGenIterator& other) const { return _num == other._num; }
+ bool operator!=(const SkyLineArrayGenIterator& other) const { return !(*this == other); }
+ reference operator*() const { T tt; return tt((*_data)[_num]); }
+ };
+
+ struct SkyLineArrayIndexPtrFunctor { const mcIdType *operator()(const MEDCouplingSkyLineArray *ska) { return ska->getIndex(); } };
+
+ using SkyLineArrayIndexIterator = SkyLineArrayGenIterator<SkyLineArrayIndexPtrFunctor>;
+
+ struct SkyLineArrayValuesPtrFunctor { const mcIdType *operator()(const MEDCouplingSkyLineArray *ska) { return ska->getValues(); } };
+
+ using SkyLineArrayValuesIterator = SkyLineArrayGenIterator<SkyLineArrayValuesPtrFunctor>;
}
# endif