Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
array.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  * Guido Tack <tack@gecode.org>
6  *
7  * Contributing authors:
8  * Gregory Crosswhite <gcross@phys.washington.edu>
9  *
10  * Copyright:
11  * Gregory Crosswhite, 2011
12  * Christian Schulte, 2003
13  * Guido Tack, 2004
14  *
15  * Last modified:
16  * $Date$ by $Author$
17  * $Revision$
18  *
19  * This file is part of Gecode, the generic constraint
20  * development environment:
21  * http://www.gecode.org
22  *
23  * Permission is hereby granted, free of charge, to any person obtaining
24  * a copy of this software and associated documentation files (the
25  * "Software"), to deal in the Software without restriction, including
26  * without limitation the rights to use, copy, modify, merge, publish,
27  * distribute, sublicense, and/or sell copies of the Software, and to
28  * permit persons to whom the Software is furnished to do so, subject to
29  * the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be
32  * included in all copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41  *
42  */
43 
44 #include <cstdarg>
45 #include <iostream>
46 #include <iterator>
47 #include <vector>
48 #include <sstream>
49 
50 namespace Gecode {
51 
52  template<class Var> class VarArray;
53  template<class Var> class VarArgArray;
54 
67  template<class A>
68  class ArrayTraits {};
69 
85  template<class Var>
86  class VarArray {
87  protected:
89  int n;
91  Var* x;
92  public:
94 
95  typedef Var value_type;
98  typedef Var& reference;
100  typedef const Var& const_reference;
102  typedef Var* pointer;
104  typedef const Var* const_pointer;
106  typedef Var* iterator;
108  typedef const Var* const_iterator;
110  typedef std::reverse_iterator<Var*> reverse_iterator;
112  typedef std::reverse_iterator<const Var*> const_reverse_iterator;
114 
116 
118  VarArray(void);
121  VarArray(Space& home, int m);
123  VarArray(Space& home, const VarArgArray<Var>&);
125  VarArray(const VarArray<Var>& a);
127  const VarArray<Var>& operator =(const VarArray<Var>& a);
129 
131 
132  int size(void) const;
135 
137 
138  Var& operator [](int i);
141  const Var& operator [](int i) const;
147  typename ArrayTraits<VarArgArray<Var> >::ArgsType
148  slice(int start, int inc=1, int n=-1);
150 
152 
153  iterator begin(void);
156  const_iterator begin(void) const;
158  iterator end(void);
160  const_iterator end(void) const;
162  reverse_iterator rbegin(void);
164  const_reverse_iterator rbegin(void) const;
166  reverse_iterator rend(void);
168  const_reverse_iterator rend(void) const;
170 
172  bool assigned(void) const;
173 
175 
176  void update(Space& home, VarArray<Var>& a);
179  private:
180  static void* operator new(size_t) throw();
181  static void operator delete(void*,size_t);
182  };
183 
187  template<class T>
188  typename ArrayTraits<VarArray<T> >::ArgsType
189  operator +(const VarArray<T>& x, const VarArgArray<T>& y);
190 
194  template<class T>
195  typename ArrayTraits<VarArray<T> >::ArgsType
196  operator +(const VarArray<T>& x, const VarArray<T>& y);
197 
201  template<class T>
202  typename ArrayTraits<VarArray<T> >::ArgsType
203  operator +(const VarArgArray<T>& x, const VarArray<T>& y);
204 
208  template<class T>
209  typename ArrayTraits<VarArray<T> >::ArgsType
210  operator +(const VarArray<T>& x, const T& y);
211 
215  template<class T>
216  typename ArrayTraits<VarArray<T> >::ArgsType
217  operator +(const T& x, const VarArray<T>& y);
218 
227  template<class View>
228  class ViewArray {
229  private:
231  int n;
233  View* x;
235  template<class X>
236  class ViewLess {
237  public:
238  bool operator ()(const X&, const X&);
239  };
241  static void sort(View* x, int n);
242  public:
244 
245  typedef View value_type;
248  typedef View& reference;
250  typedef const View& const_reference;
252  typedef View* pointer;
254  typedef const View* const_pointer;
256  typedef View* iterator;
258  typedef const View* const_iterator;
260  typedef std::reverse_iterator<View*> reverse_iterator;
262  typedef std::reverse_iterator<const View*> const_reverse_iterator;
264 
266 
267  ViewArray(void);
270  ViewArray(Space& home, int m);
272  ViewArray(Region& r, int m);
274  ViewArray(const ViewArray<View>& a);
276  ViewArray(Space& home, const ViewArray<View>& a);
278  ViewArray(Region& r, const ViewArray<View>& a);
280  const ViewArray<View>& operator =(const ViewArray<View>& a);
287  template<class Var>
289  : n(a.size()) {
290  // This may not be in the hpp file (to satisfy the MS compiler)
291  if (n>0) {
292  x = home.alloc<View>(n);
293  for (int i=n; i--; )
294  x[i]=a[i];
295  } else {
296  x = NULL;
297  }
298  }
305  template<class Var>
307  : n(a.size()) {
308  // This may not be in the hpp file (to satisfy the MS compiler)
309  if (n>0) {
310  x = r.alloc<View>(n);
311  for (int i=n; i--; )
312  x[i]=a[i];
313  } else {
314  x = NULL;
315  }
316  }
318 
320 
321  int size(void) const;
324  void size(int n);
326 
328 
329  View& operator [](int i);
332  const View& operator [](int i) const;
334 
336 
337  iterator begin(void);
340  const_iterator begin(void) const;
342  iterator end(void);
344  const_iterator end(void) const;
346  reverse_iterator rbegin(void);
348  const_reverse_iterator rbegin(void) const;
350  reverse_iterator rend(void);
352  const_reverse_iterator rend(void) const;
354 
356 
357 
364  void subscribe(Space& home, Propagator& p, PropCond pc,
365  bool schedule=true);
367  void cancel(Space& home, Propagator& p, PropCond pc);
369  void subscribe(Space& home, Advisor& a);
371  void cancel(Space& home, Advisor& a);
373  void reschedule(Space& home, Propagator& p, PropCond pc);
375 
377 
378  void update(Space& home, ViewArray<View>& a);
381 
382 
384 
385  void move_fst(int i);
388  void move_lst(int i);
394  void move_fst(int i, Space& home, Propagator& p, PropCond pc);
400  void move_lst(int i, Space& home, Propagator& p, PropCond pc);
406  void move_fst(int i, Space& home, Advisor& a);
412  void move_lst(int i, Space& home, Advisor& a);
414 
416 
417  void drop_fst(int i);
420  void drop_lst(int i);
426  void drop_fst(int i, Space& home, Propagator& p, PropCond pc);
433  void drop_lst(int i, Space& home, Propagator& p, PropCond pc);
439  void drop_fst(int i, Space& home, Advisor& a);
445  void drop_lst(int i, Space& home, Advisor& a);
447 
449  bool assigned(void) const;
450 
452 
453 
458  bool same(void) const;
464  bool same(const View& y) const;
466  void unique(void);
468 
470 
471 
476  bool shared(void) const;
482  template<class ViewY>
483  bool shared(const ViewY& y) const;
489  template<class ViewY>
490  bool shared(const ViewArray<ViewY>& y) const;
492 
493  private:
494  static void* operator new(size_t) throw();
495  static void operator delete(void*,size_t);
496  };
497 
511  template<class T>
512  class ArgArrayBase {
513  protected:
515  int n;
517  int capacity;
519  T* a;
521  static const int onstack_size = 16;
523  T onstack[onstack_size];
525  T* allocate(int n);
527  void resize(int i);
529  template<class A>
530  A concat(const ArgArrayBase<T>& x) const;
532  template<class A>
533  A concat(const T& x) const;
535  template<class A>
536  A& append(const T& x);
538  template<class A>
539  A& append(const ArgArrayBase<T>& x);
545  template<class A>
546  A slice(int start, int inc=1, int n=-1);
547  public:
549 
550  typedef T value_type;
553  typedef T& reference;
555  typedef const T& const_reference;
557  typedef T* pointer;
559  typedef const T* const_pointer;
561  typedef T* iterator;
563  typedef const T* const_iterator;
565  typedef std::reverse_iterator<T*> reverse_iterator;
567  typedef std::reverse_iterator<const T*> const_reverse_iterator;
569 
571 
572  ArgArrayBase(void);
575  explicit ArgArrayBase(int n);
577  ArgArrayBase(const ArgArrayBase<T>& a);
579  const ArgArrayBase<T>& operator =(const ArgArrayBase<T>& a);
581  ArgArrayBase(const std::vector<T>& a);
583  template<class InputIterator>
584  ArgArrayBase(InputIterator first, InputIterator last);
586 
588 
589  int size(void) const;
592 
594 
595  T& operator [](int i);
598  const T& operator [](int i) const;
600 
602 
603  iterator begin(void);
606  const_iterator begin(void) const;
608  iterator end(void);
610  const_iterator end(void) const;
612  reverse_iterator rbegin(void);
614  const_reverse_iterator rbegin(void) const;
616  reverse_iterator rend(void);
618  const_reverse_iterator rend(void) const;
620 
622 
623  ~ArgArrayBase(void);
626  };
627 
628  template<class> class PrimArgArray;
629 
633  template<class T>
634  typename ArrayTraits<PrimArgArray<T> >::ArgsType
635  operator +(const PrimArgArray<T>& x, const PrimArgArray<T>& y);
636 
640  template<class T>
641  typename ArrayTraits<PrimArgArray<T> >::ArgsType
642  operator +(const PrimArgArray<T>& x, const T& y);
643 
647  template<class T>
648  typename ArrayTraits<PrimArgArray<T> >::ArgsType
649  operator +(const T& x, const PrimArgArray<T>& y);
650 
662  template<class T>
663  class PrimArgArray : public ArgArrayBase<T> {
664  protected:
665  using ArgArrayBase<T>::a;
666  public:
667  using ArgArrayBase<T>::size;
669 
670  PrimArgArray(void);
673  explicit PrimArgArray(int n);
675  PrimArgArray(int n, T e0, ...);
677  PrimArgArray(int n, const T* e);
681  PrimArgArray(const std::vector<T>& a);
683  template<class InputIterator>
684  PrimArgArray(InputIterator first, InputIterator last);
686 
688 
693  typename ArrayTraits<PrimArgArray<T> >::ArgsType
694  slice(int start, int inc=1, int n=-1);
696 
698  typename ArrayTraits<PrimArgArray<T> >::ArgsType&
700  operator <<(const T& x);
702  typename ArrayTraits<PrimArgArray<T> >::ArgsType&
703  operator <<(const PrimArgArray<T>& x);
705 
706  friend typename ArrayTraits<PrimArgArray<T> >::ArgsType
707  operator + <>(const PrimArgArray<T>& x, const PrimArgArray<T>& y);
708  friend typename ArrayTraits<PrimArgArray<T> >::ArgsType
709  operator + <>(const PrimArgArray<T>& x, const T& y);
710  friend
711  typename ArrayTraits<PrimArgArray<T> >::ArgsType
712  operator + <>(const T& x, const PrimArgArray<T>& y);
713  };
714 
715  template<class> class ArgArray;
716 
720  template<class T>
721  typename ArrayTraits<ArgArray<T> >::ArgsType
722  operator +(const ArgArray<T>& x, const ArgArray<T>& y);
723 
727  template<class T>
728  typename ArrayTraits<ArgArray<T> >::ArgsType
729  operator +(const ArgArray<T>& x, const T& y);
730 
734  template<class T>
735  typename ArrayTraits<ArgArray<T> >::ArgsType
736  operator +(const T& x, const ArgArray<T>& y);
737 
749  template<class T>
750  class ArgArray : public ArgArrayBase<T> {
751  protected:
752  using ArgArrayBase<T>::a;
753  public:
754  using ArgArrayBase<T>::size;
756 
757  ArgArray(void);
760  explicit ArgArray(int n);
762  ArgArray(int n, const T* e);
764  ArgArray(const ArgArray<T>& a);
766  ArgArray(const std::vector<T>& a);
768  template<class InputIterator>
769  ArgArray(InputIterator first, InputIterator last);
771 
773  typename ArrayTraits<ArgArray<T> >::ArgsType
775  slice(int start, int inc=1, int n=-1);
777 
779  typename ArrayTraits<ArgArray<T> >::ArgsType&
781  operator <<(const T& x);
783  typename ArrayTraits<ArgArray<T> >::ArgsType&
784  operator <<(const ArgArray<T>& x);
786 
787  friend typename ArrayTraits<ArgArray<T> >::ArgsType
788  operator + <>(const ArgArray<T>& x, const ArgArray<T>& y);
789  friend typename ArrayTraits<ArgArray<T> >::ArgsType
790  operator + <>(const ArgArray<T>& x, const T& y);
791  friend
792  typename ArrayTraits<ArgArray<T> >::ArgsType
793  operator + <>(const T& x, const ArgArray<T>& y);
794  };
795 
796  template<class> class VarArgArray;
797 
801  template<class Var>
802  typename ArrayTraits<VarArgArray<Var> >::ArgsType
804 
808  template<class Var>
809  typename ArrayTraits<VarArgArray<Var> >::ArgsType
810  operator +(const VarArgArray<Var>& x, const Var& y);
811 
815  template<class Var>
816  typename ArrayTraits<VarArgArray<Var> >::ArgsType
817  operator +(const Var& x, const VarArgArray<Var>& y);
818 
830  template<class Var>
831  class VarArgArray : public ArgArrayBase<Var> {
832  protected:
833  using ArgArrayBase<Var>::a;
834  using ArgArrayBase<Var>::n;
836  class VarLess {
837  public:
838  bool operator ()(const Var&, const Var&);
839  };
840  public:
843 
844  VarArgArray(void);
847  explicit VarArgArray(int n);
851  VarArgArray(const VarArray<Var>& a);
853  VarArgArray(const std::vector<Var>& a);
855  template<class InputIterator>
856  VarArgArray(InputIterator first, InputIterator last);
858 
860  typename ArrayTraits<VarArgArray<Var> >::ArgsType
862  slice(int start, int inc=1, int n=-1);
864 
866  typename ArrayTraits<VarArgArray<Var> >::ArgsType&
868  operator <<(const Var& x);
870  typename ArrayTraits<VarArgArray<Var> >::ArgsType&
871  operator <<(const VarArgArray<Var>& x);
873 
875  bool assigned(void) const;
876 
877  friend typename ArrayTraits<VarArgArray<Var> >::ArgsType
878  operator + <>(const VarArgArray<Var>& x, const VarArgArray<Var>& y);
879  friend typename ArrayTraits<VarArgArray<Var> >::ArgsType
880  operator + <>(const VarArgArray<Var>& x, const Var& y);
881  friend
882  typename ArrayTraits<VarArgArray<Var> >::ArgsType
883  operator + <>(const Var& x, const VarArgArray<Var>& y);
884 
886 
887 
892  bool same(void) const;
898  bool same(const Var& y) const;
904  bool same(const VarArgArray<Var>& y) const;
906  };
907 
912  template<class Char, class Traits, class Var>
913  std::basic_ostream<Char,Traits>&
914  operator <<(std::basic_ostream<Char,Traits>& os,
915  const VarArray<Var>& x);
916 
921  template<class Char, class Traits, class View>
922  std::basic_ostream<Char,Traits>&
923  operator <<(std::basic_ostream<Char,Traits>& os, const ViewArray<View>& x);
924 
929  template<class Char, class Traits, class T>
930  std::basic_ostream<Char,Traits>&
931  operator <<(std::basic_ostream<Char,Traits>& os, const ArgArrayBase<T>& x);
932 
933 
934  /*
935  * Implementation
936  *
937  */
938 
939  /*
940  * Variable arrays
941  *
942  * These arrays are allocated in the space.
943  *
944  */
945 
946  template<class Var>
948  VarArray<Var>::VarArray(void) : n(0), x(NULL) {}
949 
950  template<class Var>
953  : n(n0) {
954  // Allocate from space
955  x = (n>0) ? home.alloc<Var>(n) : NULL;
956  }
957 
958  template<class Var>
961  n = a.n; x = a.x;
962  }
963 
964  template<class Var>
965  inline const VarArray<Var>&
967  n = a.n; x = a.x;
968  return *this;
969  }
970 
971  template<class Var>
972  forceinline int
973  VarArray<Var>::size(void) const {
974  return n;
975  }
976 
977  template<class Var>
980  assert((i >= 0) && (i < size()));
981  return x[i];
982  }
983 
984  template<class Var>
985  forceinline const Var&
987  assert((i >= 0) && (i < size()));
988  return x[i];
989  }
990 
991  template<class Var>
992  typename ArrayTraits<VarArgArray<Var> >::ArgsType
993  VarArray<Var>::slice(int start, int inc, int maxN) {
994  assert(n==0 || start < n);
995  if (n==0 || maxN<0)
996  maxN = n;
997  int s;
998  if (inc == 0)
999  s = n-start;
1000  else if (inc > 0)
1001  s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
1002  else
1003  s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
1004  typename ArrayTraits<VarArgArray<Var> >::ArgsType r(std::min(maxN,s));
1005  for (int i=0; i<r.size(); i++, start+=inc)
1006  r[i] = x[start];
1007  return r;
1008  }
1009 
1010  template<class Var>
1013  return x;
1014  }
1015 
1016  template<class Var>
1018  VarArray<Var>::begin(void) const {
1019  return x;
1020  }
1021 
1022  template<class Var>
1025  return x+n;
1026  }
1027 
1028  template<class Var>
1030  VarArray<Var>::end(void) const {
1031  return x+n;
1032  }
1033 
1034  template<class Var>
1037  return reverse_iterator(x+n);
1038  }
1039 
1040  template<class Var>
1043  return const_reverse_iterator(x+n);
1044  }
1045 
1046  template<class Var>
1049  return reverse_iterator(x);
1050  }
1051 
1052  template<class Var>
1054  VarArray<Var>::rend(void) const {
1055  return const_reverse_iterator(x);
1056  }
1057 
1058  template<class Var>
1059  forceinline void
1061  n = a.n;
1062  if (n > 0) {
1063  x = home.alloc<Var>(n);
1064  for (int i = n; i--;)
1065  x[i].update(home, a.x[i]);
1066  } else {
1067  x = NULL;
1068  }
1069  }
1070 
1071  template<class Var>
1072  forceinline bool
1074  for (int i = n; i--;)
1075  if (!x[i].assigned())
1076  return false;
1077  return true;
1078  }
1079 
1080  template<class Var>
1081  forceinline void*
1082  VarArray<Var>::operator new(size_t) throw() {
1083  return NULL;
1084  }
1085 
1086  template<class Var>
1087  forceinline void
1088  VarArray<Var>::operator delete(void*,size_t) {
1089  }
1090 
1091  template<class Var>
1092  typename ArrayTraits<VarArray<Var> >::ArgsType
1094  typename ArrayTraits<VarArray<Var> >::ArgsType r(x.size()+y.size());
1095  for (int i=x.size(); i--;)
1096  r[i] = x[i];
1097  for (int i=y.size(); i--;)
1098  r[x.size()+i] = y[i];
1099  return r;
1100  }
1101 
1102  template<class Var>
1103  typename ArrayTraits<VarArray<Var> >::ArgsType
1105  typename ArrayTraits<VarArray<Var> >::ArgsType r(x.size()+y.size());
1106  for (int i=x.size(); i--;)
1107  r[i] = x[i];
1108  for (int i=y.size(); i--;)
1109  r[x.size()+i] = y[i];
1110  return r;
1111  }
1112 
1113  template<class Var>
1114  typename ArrayTraits<VarArray<Var> >::ArgsType
1116  typename ArrayTraits<VarArray<Var> >::ArgsType r(x.size()+y.size());
1117  for (int i=x.size(); i--;)
1118  r[i] = x[i];
1119  for (int i=y.size(); i--;)
1120  r[x.size()+i] = y[i];
1121  return r;
1122  }
1123 
1124  template<class Var>
1125  typename ArrayTraits<VarArray<Var> >::ArgsType
1126  operator +(const VarArray<Var>& x, const Var& y) {
1127  typename ArrayTraits<VarArray<Var> >::ArgsType r(x.size()+1);
1128  for (int i=x.size(); i--;)
1129  r[i] = x[i];
1130  r[x.size()] = y;
1131  return r;
1132  }
1133 
1134  template<class Var>
1135  typename ArrayTraits<VarArray<Var> >::ArgsType
1136  operator +(const Var& x, const VarArray<Var>& y) {
1137  typename ArrayTraits<VarArray<Var> >::ArgsType r(y.size()+1);
1138  r[0] = x;
1139  for (int i=y.size(); i--;)
1140  r[1+i] = y[i];
1141  return r;
1142  }
1143 
1144  /*
1145  * View arrays
1146  *
1147  */
1148 
1149  template<class View>
1150  forceinline
1151  ViewArray<View>::ViewArray(void) : n(0), x(NULL) {}
1152 
1153  template<class View>
1154  forceinline
1156  : n(n0) {
1157  x = (n>0) ? home.alloc<View>(n) : NULL;
1158  }
1159  template<class View>
1160  forceinline
1162  : n(n0) {
1163  x = (n>0) ? r.alloc<View>(n) : NULL;
1164  }
1165 
1166  template<class View>
1168  : n(a.size()) {
1169  if (n>0) {
1170  x = home.alloc<View>(n);
1171  for (int i = n; i--; )
1172  x[i] = a[i];
1173  } else {
1174  x = NULL;
1175  }
1176  }
1177  template<class View>
1179  : n(a.size()) {
1180  if (n>0) {
1181  x = r.alloc<View>(n);
1182  for (int i = n; i--; )
1183  x[i] = a[i];
1184  } else {
1185  x = NULL;
1186  }
1187  }
1188 
1189  template<class View>
1190  forceinline
1192  : n(a.n), x(a.x) {}
1193 
1194  template<class View>
1197  n = a.n; x = a.x;
1198  return *this;
1199  }
1200 
1201  template<class View>
1202  forceinline int
1204  return n;
1205  }
1206 
1207  template<class View>
1208  forceinline void
1210  n = n0;
1211  }
1212 
1213  template<class View>
1214  forceinline View&
1216  assert((i >= 0) && (i < size()));
1217  return x[i];
1218  }
1219 
1220  template<class View>
1221  forceinline const View&
1223  assert((i >= 0) && (i < size()));
1224  return x[i];
1225  }
1226 
1227  template<class View>
1230  return x;
1231  }
1232 
1233  template<class View>
1236  return x;
1237  }
1238 
1239  template<class View>
1242  return x+n;
1243  }
1244 
1245  template<class View>
1247  ViewArray<View>::end(void) const {
1248  return x+n;
1249  }
1250 
1251  template<class View>
1254  return reverse_iterator(x+n);
1255  }
1256 
1257  template<class View>
1260  return const_reverse_iterator(x+n);
1261  }
1262 
1263  template<class View>
1266  return reverse_iterator(x);
1267  }
1268 
1269  template<class View>
1272  return const_reverse_iterator(x);
1273  }
1274 
1275  template<class View>
1276  forceinline void
1278  x[i]=x[0]; x++; n--;
1279  }
1280 
1281  template<class View>
1282  forceinline void
1284  n--; x[i]=x[n];
1285  }
1286 
1287  template<class View>
1288  forceinline void
1290  assert(i>=0);
1291  x += i; n -= i;
1292  }
1293 
1294  template<class View>
1295  forceinline void
1297  assert(i<n);
1298  n = i+1;
1299  }
1300 
1301  template<class View>
1302  forceinline void
1304  // Move x[0] to x[i]
1305  x[i].cancel(home,p,pc);
1306  x[i]=x[0]; x++; n--;
1307  }
1308 
1309  template<class View>
1310  forceinline void
1312  // Move x[n-1] to x[i]
1313  x[i].cancel(home,p,pc);
1314  n--; x[i]=x[n];
1315  }
1316 
1317  template<class View>
1318  void
1320  // Drop elements from 0..i-1
1321  assert(i>=0);
1322  for (int j=i; j--; )
1323  x[j].cancel(home,p,pc);
1324  x += i; n -= i;
1325  }
1326 
1327  template<class View>
1328  void
1330  // Drop elements from i+1..n-1
1331  assert(i<n);
1332  for (int j=i+1; j<n; j++)
1333  x[j].cancel(home,p,pc);
1334  n = i+1;
1335  }
1336 
1337  template<class View>
1338  forceinline void
1340  // Move x[0] to x[i]
1341  x[i].cancel(home,a);
1342  x[i]=x[0]; x++; n--;
1343  }
1344 
1345  template<class View>
1346  forceinline void
1348  // Move x[n-1] to x[i]
1349  x[i].cancel(home,a);
1350  n--; x[i]=x[n];
1351  }
1352 
1353  template<class View>
1354  void
1356  // Drop elements from 0..i-1
1357  assert(i>=0);
1358  for (int j=i; j--; )
1359  x[j].cancel(home,a);
1360  x += i; n -= i;
1361  }
1362 
1363  template<class View>
1364  void
1366  // Drop elements from i+1..n-1
1367  assert(i<n);
1368  for (int j=i+1; j<n; j++)
1369  x[j].cancel(home,a);
1370  n = i+1;
1371  }
1372 
1373  template<class View>
1374  void
1376  n = y.n;
1377  if (n > 0) {
1378  x = home.alloc<View>(n);
1379  for (int i = n; i--; )
1380  x[i].update(home, y.x[i]);
1381  } else {
1382  x = NULL;
1383  }
1384  }
1385 
1386  template<class View>
1387  void
1389  bool schedule) {
1390  for (int i = n; i--; )
1391  x[i].subscribe(home,p,pc,schedule);
1392  }
1393 
1394  template<class View>
1395  void
1397  for (int i = n; i--; )
1398  x[i].cancel(home,p,pc);
1399  }
1400 
1401  template<class View>
1402  void
1404  for (int i = n; i--; )
1405  x[i].subscribe(home,a);
1406  }
1407 
1408  template<class View>
1409  void
1411  for (int i = n; i--; )
1412  x[i].cancel(home,a);
1413  }
1414 
1415  template<class View>
1416  void
1418  for (int i = n; i--; )
1419  x[i].reschedule(home,p,pc);
1420  }
1421 
1422  template<class View>
1423  forceinline bool
1425  for (int i = n; i--;)
1426  if (!x[i].assigned())
1427  return false;
1428  return true;
1429  }
1430 
1431  template<class View>
1432  forceinline bool
1433  __before(const View& x, const View& y) {
1434  return before(x,y);
1435  }
1436 
1437  template<class View> template<class X>
1438  forceinline bool
1439  ViewArray<View>::ViewLess<X>::operator ()(const X& a, const X& b) {
1440  return __before(a,b);
1441  }
1442 
1443  template<class View>
1444  void
1445  ViewArray<View>::sort(View* y, int m) {
1446  ViewLess<View> vl;
1447  Support::quicksort<View,ViewLess<View> >(y,m,vl);
1448  }
1449 
1450  template<class X, class Y>
1451  forceinline bool
1452  __same(const X& x, const Y& y) {
1453  return same(x,y);
1454  }
1455  template<class X, class Y>
1456  forceinline bool
1457  __shared(const X& x, const Y& y) {
1458  return shared(x,y);
1459  }
1460 
1461  template<class View>
1462  bool
1464  if (n < 2)
1465  return false;
1466  Region r;
1467  View* y = r.alloc<View>(n);
1468  for (int i = n; i--; )
1469  y[i] = x[i];
1470  sort(y,n);
1471  for (int i = n-1; i--; )
1472  if (!y[i].assigned() && __same(y[i+1],y[i])) {
1473  r.free<View>(y,n);
1474  return true;
1475  }
1476  r.free<View>(y,n);
1477  return false;
1478  }
1479 
1480  template<class View>
1481  bool
1482  ViewArray<View>::same(const View& y) const {
1483  if (y.assigned())
1484  return false;
1485  for (int i = n; i--; )
1486  if (__same(x[i],y))
1487  return true;
1488  return false;
1489  }
1490 
1491  template<class View>
1492  void
1494  if (n < 2)
1495  return;
1496  sort(x,n);
1497  int j = 0;
1498  for (int i = 1; i<n; i++)
1499  if (!__same(x[j],x[i]))
1500  x[++j] = x[i];
1501  n = j+1;
1502  }
1503 
1504  template<class View>
1505  bool
1507  if (n < 2)
1508  return false;
1509  Region r;
1510  View* y = r.alloc<View>(n);
1511  for (int i = n; i--; )
1512  y[i] = x[i];
1513  sort(y,n);
1514  for (int i = n-1; i--; )
1515  if (!y[i].assigned() && __shared(y[i+1],y[i])) {
1516  r.free<View>(y,n);
1517  return true;
1518  }
1519  r.free<View>(y,n);
1520  return false;
1521  }
1522 
1523  template<class View> template<class ViewY>
1524  bool
1525  ViewArray<View>::shared(const ViewY& y) const {
1526  if (y.assigned())
1527  return false;
1528  for (int i = n; i--; )
1529  if (!x[i].assigned() && __shared(x[i],y))
1530  return true;
1531  return false;
1532  }
1533 
1534  template<class View> template<class ViewY>
1535  bool
1537  if ((size() < 1) || (y.size() < 1))
1538  return false;
1539  Region r;
1540  View* xs = r.alloc<View>(size());
1541  for (int i=size(); i--; )
1542  xs[i] = x[i];
1543  ViewLess<View> xvl;
1544  Support::quicksort<View,ViewLess<View> >(xs,size(),xvl);
1545  ViewY* ys = r.alloc<ViewY>(y.size());
1546  for (int j=y.size(); j--; )
1547  ys[j] = y[j];
1548  ViewLess<ViewY> yvl;
1549  Support::quicksort<ViewY,ViewLess<ViewY> >(ys,y.size(),yvl);
1550  {
1551  int i=0, j=0;
1552  while ((i < size()) && (j < y.size()))
1553  if (!x[i].assigned() && __shared(x[i],y[j])) {
1554  r.free<View>(xs,size());
1555  r.free<ViewY>(ys,y.size());
1556  return true;
1557  } else if (before(x[i],y[j])) {
1558  i++;
1559  } else {
1560  j++;
1561  }
1562  }
1563  r.free<View>(xs,size());
1564  r.free<ViewY>(ys,y.size());
1565  return false;
1566  }
1567 
1568  template<class View>
1569  forceinline void*
1570  ViewArray<View>::operator new(size_t) throw() {
1571  return NULL;
1572  }
1573 
1574  template<class View>
1575  forceinline void
1576  ViewArray<View>::operator delete(void*,size_t) {
1577  }
1578 
1579 
1580  /*
1581  * Argument arrays: base class
1582  *
1583  */
1584 
1585  template<class T>
1586  forceinline T*
1588  return (n > onstack_size) ?
1589  heap.alloc<T>(static_cast<unsigned int>(n)) : &onstack[0];
1590  }
1591 
1592  template<class T>
1593  forceinline void
1595  if (n+i >= capacity) {
1596  assert(n+i >= onstack_size);
1597  int newCapacity = (3*capacity)/2;
1598  if (newCapacity <= n+i)
1599  newCapacity = n+i;
1600  T* newA = allocate(newCapacity);
1601  heap.copy<T>(newA,a,n);
1602  if (capacity > onstack_size)
1603  heap.free(a,capacity);
1604  capacity = newCapacity;
1605  a = newA;
1606  }
1607  }
1608 
1609  template<class T>
1610  forceinline
1612  : n(0), capacity(onstack_size), a(allocate(0)) {}
1613 
1614  template<class T>
1615  forceinline
1617  : n(n0), capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {}
1618 
1619  template<class T>
1620  inline
1622  : n(aa.n), capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
1623  heap.copy<T>(a,aa.a,n);
1624  }
1625 
1626  template<class T>
1627  inline
1628  ArgArrayBase<T>::ArgArrayBase(const std::vector<T>& aa)
1629  : n(static_cast<int>(aa.size())),
1630  capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
1631  heap.copy<T>(a,&aa[0],n);
1632  }
1633 
1634  template<class T>
1635  forceinline
1637  if (capacity > onstack_size)
1638  heap.free(a,capacity);
1639  }
1640 
1641  template<class T>
1644  if (&aa != this) {
1645  if (capacity > onstack_size)
1646  heap.free(a,capacity);
1647  n = aa.n;
1648  capacity = (n < onstack_size ? onstack_size : n);
1649  a = allocate(aa.n);
1650  heap.copy<T>(a,aa.a,n);
1651  }
1652  return *this;
1653  }
1654 
1655  template<class T>
1656  forceinline int
1658  return n;
1659  }
1660 
1661  template<class T>
1662  forceinline T&
1664  assert((i>=0) && (i < n));
1665  return a[i];
1666  }
1667 
1668  template<class T>
1669  forceinline const T&
1671  assert((i>=0) && (i < n));
1672  return a[i];
1673  }
1674 
1675  template<class T>
1678  return a;
1679  }
1680 
1681  template<class T>
1684  return a;
1685  }
1686 
1687  template<class T>
1690  return a+n;
1691  }
1692 
1693  template<class T>
1695  ArgArrayBase<T>::end(void) const {
1696  return a+n;
1697  }
1698 
1699  template<class T>
1702  return reverse_iterator(a+n);
1703  }
1704 
1705  template<class T>
1708  return const_reverse_iterator(a+n);
1709  }
1710 
1711  template<class T>
1714  return reverse_iterator(a);
1715  }
1716 
1717  template<class T>
1720  return const_reverse_iterator(a);
1721  }
1722 
1723  template<class T> template<class A>
1724  A
1725  ArgArrayBase<T>::slice(int start, int inc, int maxN) {
1726  assert(n==0 || start < n);
1727  if (n==0 || maxN<0)
1728  maxN = n;
1729  int s;
1730  if (inc == 0)
1731  s = n-start;
1732  else if (inc > 0)
1733  s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
1734  else
1735  s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
1736  A r(std::min(maxN,s));
1737  for (int i=0; i<r.size(); i++, start+=inc)
1738  new (&r[i]) T(a[start]);
1739  return r;
1740  }
1741 
1742  template<class T> template<class A>
1743  inline A&
1745  resize(1);
1746  new (&a[n++]) T(x);
1747  return static_cast<A&>(*this);
1748  }
1749 
1750  template<class T>
1751  template<class InputIterator>
1752  inline
1753  ArgArrayBase<T>::ArgArrayBase(InputIterator first, InputIterator last)
1754  : n(0), capacity(onstack_size), a(allocate(0)) {
1755  while (first != last) {
1756  (void) append<ArgArrayBase<T> >(*first);
1757  ++first;
1758  }
1759  }
1760 
1761 
1762  template<class T> template<class A>
1763  inline A&
1765  resize(x.size());
1766  for (int i=0; i<x.size(); i++)
1767  new (&a[n++]) T(x[i]);
1768  return static_cast<A&>(*this);
1769  }
1770 
1771  template<class T> template<class A>
1772  inline A
1774  A r(n+x.n);
1775  for (int i=n; i--;)
1776  new (&r[i]) T(a[i]);
1777  for (int i=x.n; i--;)
1778  new (&r[n+i]) T(x.a[i]);
1779  return r;
1780  }
1781 
1782  template<class T> template<class A>
1783  inline A
1784  ArgArrayBase<T>::concat(const T& x) const {
1785  A r(n+1);
1786  for (int i=n; i--;)
1787  new (&r[i]) T(a[i]);
1788  new (&r[n]) T(x);
1789  return r;
1790  }
1791 
1792  /*
1793  * Argument arrays for primitive types
1794  *
1795  */
1796 
1797  template<class T>
1798  forceinline
1800 
1801  template<class T>
1802  forceinline
1804 
1805  template<class T>
1807  : ArgArrayBase<T>(n) {
1808  va_list args;
1809  va_start(args, a0);
1810  a[0] = a0;
1811  for (int i = 1; i < n; i++)
1812  a[i] = va_arg(args,T);
1813  va_end(args);
1814  }
1815 
1816  template<class T>
1818  : ArgArrayBase<T>(n) {
1819  for (int i=n; i--; )
1820  a[i] = a0[i];
1821  }
1822 
1823  template<class T>
1824  forceinline
1826  : ArgArrayBase<T>(aa) {}
1827 
1828  template<class T>
1829  forceinline
1830  PrimArgArray<T>::PrimArgArray(const std::vector<T>& aa)
1831  : ArgArrayBase<T>(aa) {}
1832 
1833  template<class T>
1834  template<class InputIterator>
1835  forceinline
1836  PrimArgArray<T>::PrimArgArray(InputIterator first, InputIterator last)
1837  : ArgArrayBase<T>(first,last) {}
1838 
1839  template<class T>
1840  forceinline typename ArrayTraits<PrimArgArray<T> >::ArgsType
1841  PrimArgArray<T>::slice(int start, int inc, int maxN) {
1843  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>
1844  (start,inc,maxN);
1845  }
1846 
1847  template<class T>
1848  forceinline typename ArrayTraits<PrimArgArray<T> >::ArgsType&
1850  return
1852  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>(x);
1853  }
1854 
1855  template<class T>
1856  forceinline typename ArrayTraits<PrimArgArray<T> >::ArgsType&
1858  return
1860  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>(x);
1861  }
1862 
1863  template<class T>
1864  typename ArrayTraits<PrimArgArray<T> >::ArgsType
1866  return x.template concat
1867  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>(y);
1868  }
1869 
1870  template<class T>
1871  typename ArrayTraits<PrimArgArray<T> >::ArgsType
1872  operator +(const PrimArgArray<T>& x, const T& y) {
1873  return x.template concat
1874  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>(y);
1875  }
1876 
1877  template<class T>
1878  typename ArrayTraits<PrimArgArray<T> >::ArgsType
1879  operator +(const T& x, const PrimArgArray<T>& y) {
1880  return PrimArgArray<T>(1,x).template concat
1881  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>(y);
1882  }
1883 
1884 
1885  /*
1886  * Argument arrays for non-primitive types
1887  *
1888  */
1889 
1890  template<class T>
1891  forceinline
1893 
1894  template<class T>
1895  forceinline
1897 
1898  template<class T>
1899  ArgArray<T>::ArgArray(int n, const T* a0)
1900  : ArgArrayBase<T>(n) {
1901  for (int i=n; i--; )
1902  a[i] = a0[i];
1903  }
1904 
1905  template<class T>
1906  forceinline
1908  : ArgArrayBase<T>(aa) {}
1909 
1910  template<class T>
1911  forceinline
1912  ArgArray<T>::ArgArray(const std::vector<T>& aa)
1913  : ArgArrayBase<T>(aa) {}
1914 
1915  template<class T>
1916  template<class InputIterator>
1917  forceinline
1918  ArgArray<T>::ArgArray(InputIterator first, InputIterator last)
1919  : ArgArrayBase<T>(first,last) {}
1920 
1921  template<class T>
1922  forceinline typename ArrayTraits<ArgArray<T> >::ArgsType
1923  ArgArray<T>::slice(int start, int inc, int maxN) {
1925  <typename ArrayTraits<ArgArray<T> >::ArgsType>
1926  (start,inc,maxN);
1927  }
1928 
1929  template<class T>
1930  forceinline typename ArrayTraits<ArgArray<T> >::ArgsType&
1932  return
1934  <typename ArrayTraits<ArgArray<T> >::ArgsType>(x);
1935  }
1936 
1937  template<class T>
1938  forceinline typename ArrayTraits<ArgArray<T> >::ArgsType&
1940  return
1942  <typename ArrayTraits<ArgArray<T> >::ArgsType>(x);
1943  }
1944 
1945  template<class T>
1946  typename ArrayTraits<ArgArray<T> >::ArgsType
1947  operator +(const ArgArray<T>& x, const ArgArray<T>& y) {
1948  return x.template concat
1949  <typename ArrayTraits<ArgArray<T> >::ArgsType>(y);
1950  }
1951 
1952  template<class T>
1953  typename ArrayTraits<ArgArray<T> >::ArgsType
1954  operator +(const ArgArray<T>& x, const T& y) {
1955  return x.template concat
1956  <typename ArrayTraits<ArgArray<T> >::ArgsType>(y);
1957  }
1958 
1959  template<class T>
1960  typename ArrayTraits<ArgArray<T> >::ArgsType
1961  operator +(const T& x, const ArgArray<T>& y) {
1962  ArgArray<T> xa(1);
1963  xa[0] = x;
1964  return xa.template concat
1965  <typename ArrayTraits<ArgArray<T> >::ArgsType>(y);
1966  }
1967 
1968  /*
1969  * Argument arrays for variables
1970  *
1971  */
1972 
1973  template<class Var>
1974  forceinline
1976 
1977  template<class Var>
1978  forceinline
1980 
1981  template<class Var>
1982  forceinline
1984  : ArgArrayBase<Var>(aa) {}
1985 
1986  template<class Var>
1987  forceinline
1988  VarArgArray<Var>::VarArgArray(const std::vector<Var>& aa)
1989  : ArgArrayBase<Var>(aa) {}
1990 
1991  template<class Var>
1992  template<class InputIterator>
1993  forceinline
1994  VarArgArray<Var>::VarArgArray(InputIterator first, InputIterator last)
1995  : ArgArrayBase<Var>(first,last) {}
1996 
1997  template<class Var>
1998  inline
2000  : ArgArrayBase<Var>(x.size()) {
2001  for (int i=x.size(); i--; )
2002  a[i]=x[i];
2003  }
2004 
2005  template<class Var>
2006  forceinline typename ArrayTraits<VarArgArray<Var> >::ArgsType
2007  VarArgArray<Var>::slice(int start, int inc, int maxN) {
2009  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>
2010  (start,inc,maxN);
2011  }
2012 
2013  template<class Var>
2014  forceinline typename ArrayTraits<VarArgArray<Var> >::ArgsType&
2016  return
2018  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>(x);
2019  }
2020 
2021  template<class Var>
2022  forceinline typename ArrayTraits<VarArgArray<Var> >::ArgsType&
2024  return
2026  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>(x);
2027  }
2028 
2029  template<class Var>
2030  typename ArrayTraits<VarArgArray<Var> >::ArgsType
2032  return x.template concat
2033  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>(y);
2034  }
2035 
2036  template<class Var>
2037  typename ArrayTraits<VarArgArray<Var> >::ArgsType
2038  operator +(const VarArgArray<Var>& x, const Var& y) {
2039  return x.template concat
2040  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>(y);
2041  }
2042 
2043  template<class Var>
2044  typename ArrayTraits<VarArgArray<Var> >::ArgsType
2045  operator +(const Var& x, const VarArgArray<Var>& y) {
2046  VarArgArray<Var> xa(1);
2047  xa[0] = x;
2048  return xa.template concat
2049  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>(y);
2050  }
2051 
2052  template<class Var>
2053  forceinline bool
2055  return a.varimp() < b.varimp();
2056  }
2057 
2058  template<class Var>
2059  forceinline bool
2061  for (int i = n; i--;)
2062  if (!a[i].assigned())
2063  return false;
2064  return true;
2065  }
2066 
2067  template<class Var>
2068  bool
2070  if (n < 2)
2071  return false;
2072  Region r;
2073  Var* y = r.alloc<Var>(n);
2074  for (int i = n; i--; )
2075  y[i] = a[i];
2076  VarLess vl;
2077  Support::quicksort<Var,VarLess>(y,n,vl);
2078  for (int i = n-1; i--; )
2079  if (!y[i].assigned() && (y[i+1].varimp() == y[i].varimp())) {
2080  r.free<Var>(y,n);
2081  return true;
2082  }
2083  r.free<Var>(y,n);
2084  return false;
2085  }
2086 
2087  template<class Var>
2088  bool
2090  int m = n + y.n;
2091  if (m < 2)
2092  return false;
2093  Region r;
2094  Var* z = r.alloc<Var>(m);
2095  for (int i = n; i--; )
2096  z[i] = a[i];
2097  for (int i = y.n; i--; )
2098  z[i+n] = y.a[i];
2099  VarLess vl;
2100  Support::quicksort<Var,VarLess>(z,m,vl);
2101  for (int i = m-1; i--; )
2102  if (!z[i].assigned() && (z[i+1].varimp() == z[i].varimp())) {
2103  r.free<Var>(z,m);
2104  return true;
2105  }
2106  r.free<Var>(z,m);
2107  return false;
2108  }
2109 
2110  template<class Var>
2111  bool
2112  VarArgArray<Var>::same(const Var& y) const {
2113  if (y.assigned())
2114  return false;
2115  for (int i = n; i--; )
2116  if (a[i].varimp() == y.varimp())
2117  return true;
2118  return false;
2119  }
2120 
2121 
2122 
2123 
2124 
2125 
2126  /*
2127  * Interdependent code
2128  *
2129  */
2130 
2131  template<class Var>
2132  inline
2134  : n(a.size()) {
2135  if (n>0) {
2136  x = home.alloc<Var>(n);
2137  for (int i=n; i--;)
2138  x[i] = a[i];
2139  } else {
2140  x = NULL;
2141  }
2142  }
2143 
2144 
2145  /*
2146  * Printing of arrays
2147  *
2148  */
2149  template<class Char, class Traits, class Var>
2150  std::basic_ostream<Char,Traits>&
2151  operator <<(std::basic_ostream<Char,Traits>& os,
2152  const VarArray<Var>& x) {
2153  std::basic_ostringstream<Char,Traits> s;
2154  s.copyfmt(os); s.width(0);
2155  s << '{';
2156  if (x.size() > 0) {
2157  s << x[0];
2158  for (int i=1; i<x.size(); i++)
2159  s << ", " << x[i];
2160  }
2161  s << '}';
2162  return os << s.str();
2163  }
2164 
2165  template<class Char, class Traits, class View>
2166  std::basic_ostream<Char,Traits>&
2167  operator <<(std::basic_ostream<Char,Traits>& os,
2168  const ViewArray<View>& x) {
2169  std::basic_ostringstream<Char,Traits> s;
2170  s.copyfmt(os); s.width(0);
2171  s << '{';
2172  if (x.size() > 0) {
2173  s << x[0];
2174  for (int i=1; i<x.size(); i++)
2175  s << ", " << x[i];
2176  }
2177  s << '}';
2178  return os << s.str();
2179  }
2180 
2181  template<class Char, class Traits, class T>
2182  std::basic_ostream<Char,Traits>&
2183  operator <<(std::basic_ostream<Char,Traits>& os,
2184  const ArgArrayBase<T>& x) {
2185  std::basic_ostringstream<Char,Traits> s;
2186  s.copyfmt(os); s.width(0);
2187  s << '{';
2188  if (x.size() > 0) {
2189  s << x[0];
2190  for (int i=1; i<x.size(); i++)
2191  s << ", " << x[i];
2192  }
2193  s << '}';
2194  return os << s.str();
2195  }
2196 
2197 }
2198 
2199 // STATISTICS: kernel-other
void free(void)
Free allocate memory.
Definition: region.hpp:354
int capacity
Allocated size of the array.
Definition: array.hpp:517
static T * copy(T *d, const T *s, long unsigned int n)
Copy n objects starting at s to d.
Definition: heap.hpp:587
const T * const_iterator
Type of the iterator used to iterate read-only through this array&#39;s elements.
Definition: array.hpp:563
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1657
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:973
Argument array for primtive types.
Definition: array.hpp:628
bool __shared(const X &x, const Y &y)
Definition: array.hpp:1457
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:85
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition: region.hpp:384
Var * iterator
Type of the iterator used to iterate through this array&#39;s elements.
Definition: array.hpp:106
std::reverse_iterator< const T * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array&#39;s elements...
Definition: array.hpp:567
Var & reference
Type of a reference to the value type.
Definition: array.hpp:98
Base-class for propagators.
Definition: core.hpp:1016
Var * pointer
Type of a pointer to the value type.
Definition: array.hpp:102
Base-class for advisors.
Definition: core.hpp:1218
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const ArgArrayBase< T > &x)
Definition: array.hpp:2183
Variable arrays
Definition: array.hpp:52
T * iterator
Type of the iterator used to iterate through this array&#39;s elements.
Definition: array.hpp:561
Handle to region.
Definition: region.hpp:57
#define forceinline
Definition: config.hpp:182
const View & const_reference
Type of a constant reference to the value type.
Definition: array.hpp:250
Computation spaces.
Definition: core.hpp:1668
View * iterator
Type of the iterator used to iterate through this array&#39;s elements.
Definition: array.hpp:256
bool shared(const IntSet &, VX)
Definition: view-base.hpp:122
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition: core.hpp:2757
View * pointer
Type of a pointer to the value type.
Definition: array.hpp:252
const Var & const_reference
Type of a constant reference to the value type.
Definition: array.hpp:100
void sort(TaskViewArray< TaskView > &t)
Sort task view array t according to sto and inc (increasing or decreasing)
Definition: sort.hpp:137
bool same(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether two views are the same.
Definition: view.hpp:643
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
std::reverse_iterator< const Var * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array&#39;s elements...
Definition: array.hpp:112
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Definition: heap.hpp:435
const FloatNum min
Smallest allowed float value.
Definition: float.hh:850
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Argument array for non-primitive types.
Definition: array.hpp:715
Var * x
Array of variables.
Definition: array.hpp:91
const View * const_pointer
Type of a read-only pointer to the value type.
Definition: array.hpp:254
FloatVal operator+(const FloatVal &x)
Definition: val.hpp:168
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
int PropCond
Type for propagation conditions.
Definition: core.hpp:74
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:75
ArrayTraits< VarArgArray< Var > >::ArgsType operator+(const Var &x, const VarArgArray< Var > &y)
Definition: array.hpp:2045
unsigned int size(I &i)
Size of all ranges of range iterator i.
ViewArray(Region &r, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements)
Definition: array.hpp:306
VarArray(void)
Default constructor (array of size 0)
Definition: array.hpp:948
T & reference
Type of a reference to the value type.
Definition: array.hpp:553
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:769
bool __before(const View &x, const View &y)
Definition: array.hpp:1433
View arrays.
Definition: array.hpp:228
int n
Number of variables (size)
Definition: array.hpp:89
bool __same(const X &x, const Y &y)
Definition: array.hpp:1452
Boolean integer variables.
Definition: int.hh:492
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:769
bool before(const Item &i, const Item &j)
Test whether one item is before another.
Definition: propagate.hpp:80
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
T * pointer
Type of a pointer to the value type.
Definition: array.hpp:557
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
View & reference
Type of a reference to the value type.
Definition: array.hpp:248
Base class for variables.
Definition: var.hpp:44
void free(T *b, long unsigned int n)
Delete n objects starting at b.
Definition: heap.hpp:461
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
Base-class for argument arrays.
Definition: array.hpp:512
Heap heap
The single global heap.
Definition: heap.cpp:48
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
bool same(const Item &i, const Item &j)
Whether two items are the same.
Definition: propagate.hpp:76
const int vl[6]
Definition: distinct.cpp:265
const Var * const_pointer
Type of a read-only pointer to the value type.
Definition: array.hpp:104
Post propagator for SetVar x
Definition: set.hh:769
Archive & operator<<(Archive &e, FloatNumBranch nl)
Definition: val-sel.hpp:43
int n
Number of elements.
Definition: array.hpp:515
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:702
Sort order for variables.
Definition: array.hpp:836
Traits of arrays in Gecode.
Definition: array.hpp:68
const T & const_reference
Type of a constant reference to the value type.
Definition: array.hpp:555
Gecode toplevel namespace
Argument array for variables.
Definition: array.hpp:53
const int capacity[n_warehouses]
Capacity of a single warehouse.
Definition: warehouses.cpp:53
std::reverse_iterator< const View * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array&#39;s elements...
Definition: array.hpp:262
ViewArray(Space &home, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements)
Definition: array.hpp:288
std::reverse_iterator< T * > reverse_iterator
Type of the iterator used to iterate backwards through this array&#39;s elements.
Definition: array.hpp:565
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
const Var * const_iterator
Type of the iterator used to iterate read-only through this array&#39;s elements.
Definition: array.hpp:108
View value_type
Type of the view stored in this array.
Definition: array.hpp:246
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1203
const View * const_iterator
Type of the iterator used to iterate read-only through this array&#39;s elements.
Definition: array.hpp:258
std::reverse_iterator< View * > reverse_iterator
Type of the iterator used to iterate backwards through this array&#39;s elements.
Definition: array.hpp:260
const T * const_pointer
Type of a read-only pointer to the value type.
Definition: array.hpp:559
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:107
const unsigned int slice
Size of a slice in a portfolio and scale factor for restarts(in number of failures) ...
Definition: search.hh:130
std::reverse_iterator< Var * > reverse_iterator
Type of the iterator used to iterate backwards through this array&#39;s elements.
Definition: array.hpp:110
T * a
Element array.
Definition: array.hpp:519