19#define MultiIndexDestr_D 0
20#define MultiArrayConstr_D 0
21#define MultiArrayCommute_D 0
22#define MultiArrayErase_D 0
23#define MultiArrayScanner_D 0
24#define MultiArrayIndex_D 0
25#define MultiArrayIndexShort_D 0
27#define MultiArrayInfo 1
32 template <u
int dim,
typename T>
64 DEBUGL(MultiIndexDestr_D,
"done.");
74 virtual std::ostream&
info(std::ostream&
os)
const;
93 while(i < dim && (*
this)[i] == a[i]) ++i;
105 for (
uint i = 0; i < dim; ++i)
106 os << (*
this)[i] << ((i == dim-1) ?
"" :
", ");
117 template <u
int dim,
typename T>
122 inline uint operator()(
const uint j)
const {
127 inline const T& value()
const {
return ent_.value(); }
129 virtual std::ostream&
info(std::ostream&
os)
const {
131 for(
uint j=0;j < dim-1;++j)
132 os <<
", " << ent_(j);
133 return os <<
", " << ent_.value() <<
")";
142 template <
typename T>
146 inline uint operator()(
const uint j = 0)
const {
150 inline const T& value()
const {
return value_; }
152 virtual std::ostream&
info(std::ostream&
os)
const {
168 template <u
int dim,
typename T>
176 i_(
array.data_.begin()), end_(
array.data_.end()), j_(0) {
177 DEBUGL(MultiArrayScanner_D, i_->first <<
", " << i_->second);
180 j_ = i_->second.scan();
181 DEBUGL(MultiArrayScanner_D, i_->first <<
", " << i_->second);
184 : i_(scan.i_), end_(scan.end_), j_(scan.j_) {}
189 DEBUGL(MultiArrayScanner_D, i_->first <<
", " << i_->second);
193 DEBUGL(MultiArrayScanner_D, i_->first <<
", " << i_->second);
197 DEBUGL(MultiArrayScanner_D, i_->first <<
", " << i_->second);
215 DEBUGL(MultiArrayScanner_D, i_->first <<
", " << i_->second <<
", " << j_ <<
", " << j_->eos());
218 Scanner* clone()
const {
return new Scanner(*
this); }
223 typename std::map<
uint, MultiArray<dim-1, T> >::const_iterator i_;
225 typename std::map<
uint, MultiArray<dim-1, T> >::const_iterator end_;
227 typename MultiArray<dim-1, T>::Scanner* j_;
252 Scanner* scan()
const {
return new Scanner(*
this); }
271 virtual std::ostream&
info(std::ostream&
os)
const;
276 const bool commutable_;
279 template <u
int dim,
typename T>
282 DEBUGL(!MultiArrayIndex_D && MultiArrayIndexShort_D,
289 template <u
int dim,
typename T>
292 DEBUGL(!MultiArrayIndex_D && MultiArrayIndexShort_D,
297 if (j == data_.end()) {
300 <
typename std::map<
uint,
MultiArray<dim-1, T> >::iterator,
bool> k =
305 DEBUGL(MultiArrayIndex_D, *
this);
307 return j->second[i+1];
310 template <u
int dim,
typename T>
313 DEBUGL(!MultiArrayIndex_D && MultiArrayIndexShort_D,
320 template <u
int dim,
typename T>
323 DEBUGL(!MultiArrayIndex_D && MultiArrayIndexShort_D,
326 typename std::map<
uint,
MultiArray<dim-1, T> >::const_iterator j =
328 if (j == data_.end()) {
329 DEBUGL(MultiArrayIndex_D || MultiArrayIndexShort_D,
333 return j->second[i+1];
336 template <u
int dim,
typename T>
343 template <u
int dim,
typename T>
346 typename std::map<
uint,
MultiArray<dim-1, T> >::const_iterator j =
348 if (j == data_.end())
350 else return j->second.
isElm(i+1);
353 template <u
int dim,
typename T>
356 for(
uint j=1; j < dim; ++j) {
357 if (i[j] < i[0]) std::swap(i[0],i[j]);
363 template <u
int dim,
typename T>
370 template <u
int dim,
typename T>
376 if (j == data_.end())
378 DEBUGL(MultiArrayErase_D, j->second);
379 j->second.erase(i+1);
380 DEBUGL(MultiArrayErase_D, j->second);
381 if (j->second.size()==0)
385 template <u
int dim,
typename T>
389 data_.
erase(j->first);
392 template <u
int dim,
typename T>
395 typename std::map<
uint,
MultiArray<dim-1, T> >::const_iterator j =
397 for(;j != data_.end();++j)
398 size += j->second.
size();
402 template <u
int dim,
typename T>
404 typename std::map<
uint,
MultiArray<dim-1, T> >::iterator j = data_.begin();
405 for(;j != data_.end();++j)
410 template <u
int dim,
typename T>
412 uint size = this->size();
414 if (commutable_)
os <<
"yes";
418 typename std::map<
uint,
MultiArray<dim-1, T> >::const_iterator
j0 = data_.begin();
419 for(;
j0 != data_.end();) {
421 DEBUGL(MultiArrayScanner_D,
j0->first <<
", " <<
j0->second);
422 os <<
"(" <<
j0->first <<
", " <<
j0->second <<
")";
425 std::unique_ptr<Scanner>
sc(scan());
428 if (!
sc->eos())
os <<
", ";
431 if (++
j0 != data_.end())
os <<
", ";
444 template <
typename T>
452 end_(
array.data_.end()) {}
453 Scanner(
const Scanner& scan) : i_(scan.i_), end_(scan.end_) {}
454 bool eos()
const {
return i_ == end_; }
463 DEBUGL(MultiArrayScanner_D, i_->first <<
", " << i_->second);
467 Scanner* clone()
const {
return new Scanner(*
this); }
472 typename std::map<uint, T>::const_iterator i_;
473 typename std::map<uint, T>::const_iterator end_;
483 DEBUGL(MultiArrayConstr_D,
"Constructor called");
513 Scanner*
scan()
const {
return new Scanner(*
this); }
522 DEBUGL(MultiArrayErase_D,
"Erase (" << i <<
")");
526 typename std::map<uint, T>::const_reverse_iterator j =
528 data_.erase(j->first);
534 inline void clear() { data_.clear(); }
536 virtual std::ostream&
info(std::ostream&
os)
const;
539 std::map<uint, T> data_;
542 template <
typename T>
544 typename std::map<uint, T>::const_iterator j = data_.find(i);
545 if (j == data_.end())
550 template <
typename T>
552 typename std::map<uint, T>::const_iterator j = data_.find(i);
553 return (j != data_.end());
556 template <
typename T>
558 uint size = this->size();
562 typename std::map<uint, T>::const_iterator i_ = data_.begin();
563 typename std::map<uint, T>::const_iterator end_ = data_.end();
565 os <<
"(" << i_->first <<
"," << i_->second <<
")";
567 if (i_ != end_)
os <<
", ";
#define conceptsException(exc)
virtual ~Scanner()
delete scanner, if there was one
bool eos() const
Returns true if the end of the scanned set is reached.
Scanner * scan() const
Scanner over the entrances.
void erase(const uint i[1])
uint size() const
Number of entrances.
MultiArray(bool commutable=false)
bool isElm(const uint i[1]) const
void clear()
Clears the array.
void erase(const uint i[dim])
MultiArray(bool commutable=false)
bool isElm(const uint i[dim]) const
void clear()
Clears the array.
T & operator[](const uint i[dim])
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
void commute(uint i[dim]) const
if commutable_ then order the smallest index to front
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
MultiIndex(const uint &dft)
bool operator==(const MultiIndex< dim > &a) const
Comparison operator.
MultiIndex(const MultiIndex< dim > &a)
Copy constructor.
bool operator!=(const MultiIndex< dim > &a) const
Comparison operator.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
#define conceptsAssert(cond, exc)
#define DEBUGL(doit, msg)
std::string typeOf(const T &t)
void memorycpy(F *dest, const G *src, size_t n)
Copies n entries from src to dest (faster than std::memcpy)
Set< F > makeSet(uint n, const F &first,...)