Generated on Sat Jun 2 2018 07:17:44 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  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #include <cstdarg>
41 #include <iostream>
42 #include <iterator>
43 #include <vector>
44 #include <sstream>
45 
46 namespace Gecode {
47 
48  template<class Var> class VarArray;
49  template<class Var> class VarArgArray;
50 
63  template<class A>
64  class ArrayTraits {};
65 
81  template<class Var>
82  class VarArray {
83  protected:
85  int n;
87  Var* x;
88  public:
90 
91  typedef Var value_type;
94  typedef Var& reference;
96  typedef const Var& const_reference;
98  typedef Var* pointer;
100  typedef const Var* const_pointer;
102  typedef Var* iterator;
104  typedef const Var* const_iterator;
106  typedef std::reverse_iterator<Var*> reverse_iterator;
108  typedef std::reverse_iterator<const Var*> const_reverse_iterator;
110 
112 
114  VarArray(void);
117  VarArray(Space& home, int m);
119  VarArray(Space& home, const VarArgArray<Var>&);
121  VarArray(const VarArray<Var>& a);
123  const VarArray<Var>& operator =(const VarArray<Var>& a);
125 
127 
128  int size(void) const;
131 
133 
134  Var& operator [](int i);
137  const Var& operator [](int i) const;
143  typename ArrayTraits<VarArgArray<Var> >::ArgsType
144  slice(int start, int inc=1, int n=-1);
146 
148 
149  iterator begin(void);
152  const_iterator begin(void) const;
154  iterator end(void);
156  const_iterator end(void) const;
158  reverse_iterator rbegin(void);
160  const_reverse_iterator rbegin(void) const;
162  reverse_iterator rend(void);
164  const_reverse_iterator rend(void) const;
166 
168  bool assigned(void) const;
169 
171 
172  void update(Space& home, VarArray<Var>& a);
175  private:
176  static void* operator new(size_t) throw();
177  static void operator delete(void*,size_t);
178  };
179 
183  template<class T>
184  typename ArrayTraits<VarArray<T> >::ArgsType
185  operator +(const VarArray<T>& x, const VarArgArray<T>& y);
186 
190  template<class T>
191  typename ArrayTraits<VarArray<T> >::ArgsType
192  operator +(const VarArray<T>& x, const VarArray<T>& y);
193 
197  template<class T>
198  typename ArrayTraits<VarArray<T> >::ArgsType
199  operator +(const VarArgArray<T>& x, const VarArray<T>& y);
200 
204  template<class T>
205  typename ArrayTraits<VarArray<T> >::ArgsType
206  operator +(const VarArray<T>& x, const T& y);
207 
211  template<class T>
212  typename ArrayTraits<VarArray<T> >::ArgsType
213  operator +(const T& x, const VarArray<T>& y);
214 
223  template<class View>
224  class ViewArray {
225  private:
227  int n;
229  View* x;
231  template<class X>
232  class ViewLess {
233  public:
234  bool operator ()(const X&, const X&);
235  };
237  static void sort(View* x, int n);
238  public:
240 
241  typedef View value_type;
244  typedef View& reference;
246  typedef const View& const_reference;
248  typedef View* pointer;
250  typedef const View* const_pointer;
252  typedef View* iterator;
254  typedef const View* const_iterator;
256  typedef std::reverse_iterator<View*> reverse_iterator;
258  typedef std::reverse_iterator<const View*> const_reverse_iterator;
260 
262 
263  ViewArray(void);
266  ViewArray(Space& home, int m);
268  ViewArray(Region& r, int m);
270  ViewArray(const ViewArray<View>& a);
272  ViewArray(Space& home, const ViewArray<View>& a);
274  ViewArray(Region& r, const ViewArray<View>& a);
276  const ViewArray<View>& operator =(const ViewArray<View>& a);
283  template<class Var>
285  : n(a.size()) {
286  // This may not be in the hpp file (to satisfy the MS compiler)
287  if (n>0) {
288  x = home.alloc<View>(n);
289  for (int i=n; i--; )
290  x[i]=a[i];
291  } else {
292  x = NULL;
293  }
294  }
301  template<class Var>
303  : n(a.size()) {
304  // This may not be in the hpp file (to satisfy the MS compiler)
305  if (n>0) {
306  x = r.alloc<View>(n);
307  for (int i=n; i--; )
308  x[i]=a[i];
309  } else {
310  x = NULL;
311  }
312  }
314 
316 
317  int size(void) const;
320  void size(int n);
322 
324 
325  View& operator [](int i);
328  const View& operator [](int i) const;
330 
332 
333  iterator begin(void);
336  const_iterator begin(void) const;
338  iterator end(void);
340  const_iterator end(void) const;
342  reverse_iterator rbegin(void);
344  const_reverse_iterator rbegin(void) const;
346  reverse_iterator rend(void);
348  const_reverse_iterator rend(void) const;
350 
352 
353 
360  void subscribe(Space& home, Propagator& p, PropCond pc,
361  bool schedule=true);
363  void cancel(Space& home, Propagator& p, PropCond pc);
365  void subscribe(Space& home, Advisor& a);
367  void cancel(Space& home, Advisor& a);
369  void reschedule(Space& home, Propagator& p, PropCond pc);
371 
373 
374  void update(Space& home, ViewArray<View>& a);
377 
378 
380 
381  void move_fst(int i);
384  void move_lst(int i);
390  void move_fst(int i, Space& home, Propagator& p, PropCond pc);
396  void move_lst(int i, Space& home, Propagator& p, PropCond pc);
402  void move_fst(int i, Space& home, Advisor& a);
408  void move_lst(int i, Space& home, Advisor& a);
410 
412 
413  void drop_fst(int i);
416  void drop_lst(int i);
422  void drop_fst(int i, Space& home, Propagator& p, PropCond pc);
429  void drop_lst(int i, Space& home, Propagator& p, PropCond pc);
435  void drop_fst(int i, Space& home, Advisor& a);
441  void drop_lst(int i, Space& home, Advisor& a);
443 
445  bool assigned(void) const;
446 
448 
449 
454  bool same(void) const;
460  bool same(const View& y) const;
462  void unique(void);
464 
466 
467 
472  bool shared(void) const;
478  template<class ViewY>
479  bool shared(const ViewY& y) const;
485  template<class ViewY>
486  bool shared(const ViewArray<ViewY>& y) const;
488 
489  private:
490  static void* operator new(size_t) throw();
491  static void operator delete(void*,size_t);
492  };
493 
507  template<class T>
508  class ArgArrayBase {
509  protected:
511  int n;
513  int capacity;
515  T* a;
517  static const int onstack_size = 16;
519  T onstack[onstack_size];
521  T* allocate(int n);
523  void resize(int i);
525  template<class A>
526  A concat(const ArgArrayBase<T>& x) const;
528  template<class A>
529  A concat(const T& x) const;
531  template<class A>
532  A& append(const T& x);
534  template<class A>
535  A& append(const ArgArrayBase<T>& x);
541  template<class A>
542  A slice(int start, int inc=1, int n=-1);
543  public:
545 
546  typedef T value_type;
549  typedef T& reference;
551  typedef const T& const_reference;
553  typedef T* pointer;
555  typedef const T* const_pointer;
557  typedef T* iterator;
559  typedef const T* const_iterator;
561  typedef std::reverse_iterator<T*> reverse_iterator;
563  typedef std::reverse_iterator<const T*> const_reverse_iterator;
565 
567 
568  ArgArrayBase(void);
571  explicit ArgArrayBase(int n);
573  ArgArrayBase(const ArgArrayBase<T>& a);
575  const ArgArrayBase<T>& operator =(const ArgArrayBase<T>& a);
577  ArgArrayBase(const std::vector<T>& a);
579  template<class InputIterator>
580  ArgArrayBase(InputIterator first, InputIterator last);
582 
584 
585  int size(void) const;
588 
590 
591  T& operator [](int i);
594  const T& operator [](int i) const;
596 
598 
599  iterator begin(void);
602  const_iterator begin(void) const;
604  iterator end(void);
606  const_iterator end(void) const;
608  reverse_iterator rbegin(void);
610  const_reverse_iterator rbegin(void) const;
612  reverse_iterator rend(void);
614  const_reverse_iterator rend(void) const;
616 
618 
619  ~ArgArrayBase(void);
622  };
623 
624  template<class> class PrimArgArray;
625 
629  template<class T>
630  typename ArrayTraits<PrimArgArray<T> >::ArgsType
631  operator +(const PrimArgArray<T>& x, const PrimArgArray<T>& y);
632 
636  template<class T>
637  typename ArrayTraits<PrimArgArray<T> >::ArgsType
638  operator +(const PrimArgArray<T>& x, const T& y);
639 
643  template<class T>
644  typename ArrayTraits<PrimArgArray<T> >::ArgsType
645  operator +(const T& x, const PrimArgArray<T>& y);
646 
658  template<class T>
659  class PrimArgArray : public ArgArrayBase<T> {
660  protected:
661  using ArgArrayBase<T>::a;
662  public:
663  using ArgArrayBase<T>::size;
665 
666  PrimArgArray(void);
669  explicit PrimArgArray(int n);
671  PrimArgArray(int n, T e0, ...);
673  PrimArgArray(int n, const T* e);
677  PrimArgArray(const std::vector<T>& a);
679  template<class InputIterator>
680  PrimArgArray(InputIterator first, InputIterator last);
682 
684 
689  typename ArrayTraits<PrimArgArray<T> >::ArgsType
690  slice(int start, int inc=1, int n=-1);
692 
694  typename ArrayTraits<PrimArgArray<T> >::ArgsType&
696  operator <<(const T& x);
698  typename ArrayTraits<PrimArgArray<T> >::ArgsType&
699  operator <<(const PrimArgArray<T>& x);
701 
702  friend typename ArrayTraits<PrimArgArray<T> >::ArgsType
703  operator + <>(const PrimArgArray<T>& x, const PrimArgArray<T>& y);
704  friend typename ArrayTraits<PrimArgArray<T> >::ArgsType
705  operator + <>(const PrimArgArray<T>& x, const T& y);
706  friend
707  typename ArrayTraits<PrimArgArray<T> >::ArgsType
708  operator + <>(const T& x, const PrimArgArray<T>& y);
709  };
710 
711  template<class> class ArgArray;
712 
716  template<class T>
717  typename ArrayTraits<ArgArray<T> >::ArgsType
718  operator +(const ArgArray<T>& x, const ArgArray<T>& y);
719 
723  template<class T>
724  typename ArrayTraits<ArgArray<T> >::ArgsType
725  operator +(const ArgArray<T>& x, const T& y);
726 
730  template<class T>
731  typename ArrayTraits<ArgArray<T> >::ArgsType
732  operator +(const T& x, const ArgArray<T>& y);
733 
745  template<class T>
746  class ArgArray : public ArgArrayBase<T> {
747  protected:
748  using ArgArrayBase<T>::a;
749  public:
750  using ArgArrayBase<T>::size;
752 
753  ArgArray(void);
756  explicit ArgArray(int n);
758  ArgArray(int n, const T* e);
760  ArgArray(const ArgArray<T>& a);
762  ArgArray(const std::vector<T>& a);
764  template<class InputIterator>
765  ArgArray(InputIterator first, InputIterator last);
767 
769  typename ArrayTraits<ArgArray<T> >::ArgsType
771  slice(int start, int inc=1, int n=-1);
773 
775  typename ArrayTraits<ArgArray<T> >::ArgsType&
777  operator <<(const T& x);
779  typename ArrayTraits<ArgArray<T> >::ArgsType&
780  operator <<(const ArgArray<T>& x);
782 
783  friend typename ArrayTraits<ArgArray<T> >::ArgsType
784  operator + <>(const ArgArray<T>& x, const ArgArray<T>& y);
785  friend typename ArrayTraits<ArgArray<T> >::ArgsType
786  operator + <>(const ArgArray<T>& x, const T& y);
787  friend
788  typename ArrayTraits<ArgArray<T> >::ArgsType
789  operator + <>(const T& x, const ArgArray<T>& y);
790  };
791 
792  template<class> class VarArgArray;
793 
797  template<class Var>
798  typename ArrayTraits<VarArgArray<Var> >::ArgsType
800 
804  template<class Var>
805  typename ArrayTraits<VarArgArray<Var> >::ArgsType
806  operator +(const VarArgArray<Var>& x, const Var& y);
807 
811  template<class Var>
812  typename ArrayTraits<VarArgArray<Var> >::ArgsType
813  operator +(const Var& x, const VarArgArray<Var>& y);
814 
826  template<class Var>
827  class VarArgArray : public ArgArrayBase<Var> {
828  protected:
829  using ArgArrayBase<Var>::a;
830  using ArgArrayBase<Var>::n;
832  class VarLess {
833  public:
834  bool operator ()(const Var&, const Var&);
835  };
836  public:
839 
840  VarArgArray(void);
843  explicit VarArgArray(int n);
847  VarArgArray(const VarArray<Var>& a);
849  VarArgArray(const std::vector<Var>& a);
851  template<class InputIterator>
852  VarArgArray(InputIterator first, InputIterator last);
854 
856  typename ArrayTraits<VarArgArray<Var> >::ArgsType
858  slice(int start, int inc=1, int n=-1);
860 
862  typename ArrayTraits<VarArgArray<Var> >::ArgsType&
864  operator <<(const Var& x);
866  typename ArrayTraits<VarArgArray<Var> >::ArgsType&
867  operator <<(const VarArgArray<Var>& x);
869 
871  bool assigned(void) const;
872 
873  friend typename ArrayTraits<VarArgArray<Var> >::ArgsType
874  operator + <>(const VarArgArray<Var>& x, const VarArgArray<Var>& y);
875  friend typename ArrayTraits<VarArgArray<Var> >::ArgsType
876  operator + <>(const VarArgArray<Var>& x, const Var& y);
877  friend
878  typename ArrayTraits<VarArgArray<Var> >::ArgsType
879  operator + <>(const Var& x, const VarArgArray<Var>& y);
880 
882 
883 
888  bool same(void) const;
894  bool same(const Var& y) const;
900  bool same(const VarArgArray<Var>& y) const;
902  };
903 
908  template<class Char, class Traits, class Var>
909  std::basic_ostream<Char,Traits>&
910  operator <<(std::basic_ostream<Char,Traits>& os,
911  const VarArray<Var>& x);
912 
917  template<class Char, class Traits, class View>
918  std::basic_ostream<Char,Traits>&
919  operator <<(std::basic_ostream<Char,Traits>& os, const ViewArray<View>& x);
920 
925  template<class Char, class Traits, class T>
926  std::basic_ostream<Char,Traits>&
927  operator <<(std::basic_ostream<Char,Traits>& os, const ArgArrayBase<T>& x);
928 
929 
930  /*
931  * Implementation
932  *
933  */
934 
935  /*
936  * Variable arrays
937  *
938  * These arrays are allocated in the space.
939  *
940  */
941 
942  template<class Var>
944  VarArray<Var>::VarArray(void) : n(0), x(NULL) {}
945 
946  template<class Var>
949  : n(n0) {
950  // Allocate from space
951  x = (n>0) ? home.alloc<Var>(n) : NULL;
952  }
953 
954  template<class Var>
957  n = a.n; x = a.x;
958  }
959 
960  template<class Var>
961  inline const VarArray<Var>&
963  n = a.n; x = a.x;
964  return *this;
965  }
966 
967  template<class Var>
968  forceinline int
969  VarArray<Var>::size(void) const {
970  return n;
971  }
972 
973  template<class Var>
976  assert((i >= 0) && (i < size()));
977  return x[i];
978  }
979 
980  template<class Var>
981  forceinline const Var&
983  assert((i >= 0) && (i < size()));
984  return x[i];
985  }
986 
987  template<class Var>
988  typename ArrayTraits<VarArgArray<Var> >::ArgsType
989  VarArray<Var>::slice(int start, int inc, int maxN) {
990  assert(n==0 || start < n);
991  if (n==0 || maxN<0)
992  maxN = n;
993  int s;
994  if (inc == 0)
995  s = n-start;
996  else if (inc > 0)
997  s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
998  else
999  s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
1000  typename ArrayTraits<VarArgArray<Var> >::ArgsType r(std::min(maxN,s));
1001  for (int i=0; i<r.size(); i++, start+=inc)
1002  r[i] = x[start];
1003  return r;
1004  }
1005 
1006  template<class Var>
1009  return x;
1010  }
1011 
1012  template<class Var>
1014  VarArray<Var>::begin(void) const {
1015  return x;
1016  }
1017 
1018  template<class Var>
1021  return x+n;
1022  }
1023 
1024  template<class Var>
1026  VarArray<Var>::end(void) const {
1027  return x+n;
1028  }
1029 
1030  template<class Var>
1033  return reverse_iterator(x+n);
1034  }
1035 
1036  template<class Var>
1039  return const_reverse_iterator(x+n);
1040  }
1041 
1042  template<class Var>
1045  return reverse_iterator(x);
1046  }
1047 
1048  template<class Var>
1050  VarArray<Var>::rend(void) const {
1051  return const_reverse_iterator(x);
1052  }
1053 
1054  template<class Var>
1055  forceinline void
1057  n = a.n;
1058  if (n > 0) {
1059  x = home.alloc<Var>(n);
1060  for (int i = n; i--;)
1061  x[i].update(home, a.x[i]);
1062  } else {
1063  x = NULL;
1064  }
1065  }
1066 
1067  template<class Var>
1068  forceinline bool
1070  for (int i = n; i--;)
1071  if (!x[i].assigned())
1072  return false;
1073  return true;
1074  }
1075 
1076  template<class Var>
1077  forceinline void*
1078  VarArray<Var>::operator new(size_t) throw() {
1079  return NULL;
1080  }
1081 
1082  template<class Var>
1083  forceinline void
1084  VarArray<Var>::operator delete(void*,size_t) {
1085  }
1086 
1087  template<class Var>
1088  typename ArrayTraits<VarArray<Var> >::ArgsType
1090  typename ArrayTraits<VarArray<Var> >::ArgsType r(x.size()+y.size());
1091  for (int i=x.size(); i--;)
1092  r[i] = x[i];
1093  for (int i=y.size(); i--;)
1094  r[x.size()+i] = y[i];
1095  return r;
1096  }
1097 
1098  template<class Var>
1099  typename ArrayTraits<VarArray<Var> >::ArgsType
1101  typename ArrayTraits<VarArray<Var> >::ArgsType r(x.size()+y.size());
1102  for (int i=x.size(); i--;)
1103  r[i] = x[i];
1104  for (int i=y.size(); i--;)
1105  r[x.size()+i] = y[i];
1106  return r;
1107  }
1108 
1109  template<class Var>
1110  typename ArrayTraits<VarArray<Var> >::ArgsType
1112  typename ArrayTraits<VarArray<Var> >::ArgsType r(x.size()+y.size());
1113  for (int i=x.size(); i--;)
1114  r[i] = x[i];
1115  for (int i=y.size(); i--;)
1116  r[x.size()+i] = y[i];
1117  return r;
1118  }
1119 
1120  template<class Var>
1121  typename ArrayTraits<VarArray<Var> >::ArgsType
1122  operator +(const VarArray<Var>& x, const Var& y) {
1123  typename ArrayTraits<VarArray<Var> >::ArgsType r(x.size()+1);
1124  for (int i=x.size(); i--;)
1125  r[i] = x[i];
1126  r[x.size()] = y;
1127  return r;
1128  }
1129 
1130  template<class Var>
1131  typename ArrayTraits<VarArray<Var> >::ArgsType
1132  operator +(const Var& x, const VarArray<Var>& y) {
1133  typename ArrayTraits<VarArray<Var> >::ArgsType r(y.size()+1);
1134  r[0] = x;
1135  for (int i=y.size(); i--;)
1136  r[1+i] = y[i];
1137  return r;
1138  }
1139 
1140  /*
1141  * View arrays
1142  *
1143  */
1144 
1145  template<class View>
1146  forceinline
1147  ViewArray<View>::ViewArray(void) : n(0), x(NULL) {}
1148 
1149  template<class View>
1150  forceinline
1152  : n(n0) {
1153  x = (n>0) ? home.alloc<View>(n) : NULL;
1154  }
1155  template<class View>
1156  forceinline
1158  : n(n0) {
1159  x = (n>0) ? r.alloc<View>(n) : NULL;
1160  }
1161 
1162  template<class View>
1164  : n(a.size()) {
1165  if (n>0) {
1166  x = home.alloc<View>(n);
1167  for (int i = n; i--; )
1168  x[i] = a[i];
1169  } else {
1170  x = NULL;
1171  }
1172  }
1173  template<class View>
1175  : n(a.size()) {
1176  if (n>0) {
1177  x = r.alloc<View>(n);
1178  for (int i = n; i--; )
1179  x[i] = a[i];
1180  } else {
1181  x = NULL;
1182  }
1183  }
1184 
1185  template<class View>
1186  forceinline
1188  : n(a.n), x(a.x) {}
1189 
1190  template<class View>
1193  n = a.n; x = a.x;
1194  return *this;
1195  }
1196 
1197  template<class View>
1198  forceinline int
1200  return n;
1201  }
1202 
1203  template<class View>
1204  forceinline void
1206  n = n0;
1207  }
1208 
1209  template<class View>
1210  forceinline View&
1212  assert((i >= 0) && (i < size()));
1213  return x[i];
1214  }
1215 
1216  template<class View>
1217  forceinline const View&
1219  assert((i >= 0) && (i < size()));
1220  return x[i];
1221  }
1222 
1223  template<class View>
1226  return x;
1227  }
1228 
1229  template<class View>
1232  return x;
1233  }
1234 
1235  template<class View>
1238  return x+n;
1239  }
1240 
1241  template<class View>
1243  ViewArray<View>::end(void) const {
1244  return x+n;
1245  }
1246 
1247  template<class View>
1250  return reverse_iterator(x+n);
1251  }
1252 
1253  template<class View>
1256  return const_reverse_iterator(x+n);
1257  }
1258 
1259  template<class View>
1262  return reverse_iterator(x);
1263  }
1264 
1265  template<class View>
1268  return const_reverse_iterator(x);
1269  }
1270 
1271  template<class View>
1272  forceinline void
1274  x[i]=x[0]; x++; n--;
1275  }
1276 
1277  template<class View>
1278  forceinline void
1280  n--; x[i]=x[n];
1281  }
1282 
1283  template<class View>
1284  forceinline void
1286  assert(i>=0);
1287  x += i; n -= i;
1288  }
1289 
1290  template<class View>
1291  forceinline void
1293  assert(i<n);
1294  n = i+1;
1295  }
1296 
1297  template<class View>
1298  forceinline void
1300  // Move x[0] to x[i]
1301  x[i].cancel(home,p,pc);
1302  x[i]=x[0]; x++; n--;
1303  }
1304 
1305  template<class View>
1306  forceinline void
1308  // Move x[n-1] to x[i]
1309  x[i].cancel(home,p,pc);
1310  n--; x[i]=x[n];
1311  }
1312 
1313  template<class View>
1314  void
1316  // Drop elements from 0..i-1
1317  assert(i>=0);
1318  for (int j=i; j--; )
1319  x[j].cancel(home,p,pc);
1320  x += i; n -= i;
1321  }
1322 
1323  template<class View>
1324  void
1326  // Drop elements from i+1..n-1
1327  assert(i<n);
1328  for (int j=i+1; j<n; j++)
1329  x[j].cancel(home,p,pc);
1330  n = i+1;
1331  }
1332 
1333  template<class View>
1334  forceinline void
1336  // Move x[0] to x[i]
1337  x[i].cancel(home,a);
1338  x[i]=x[0]; x++; n--;
1339  }
1340 
1341  template<class View>
1342  forceinline void
1344  // Move x[n-1] to x[i]
1345  x[i].cancel(home,a);
1346  n--; x[i]=x[n];
1347  }
1348 
1349  template<class View>
1350  void
1352  // Drop elements from 0..i-1
1353  assert(i>=0);
1354  for (int j=i; j--; )
1355  x[j].cancel(home,a);
1356  x += i; n -= i;
1357  }
1358 
1359  template<class View>
1360  void
1362  // Drop elements from i+1..n-1
1363  assert(i<n);
1364  for (int j=i+1; j<n; j++)
1365  x[j].cancel(home,a);
1366  n = i+1;
1367  }
1368 
1369  template<class View>
1370  void
1372  n = y.n;
1373  if (n > 0) {
1374  x = home.alloc<View>(n);
1375  for (int i = n; i--; )
1376  x[i].update(home, y.x[i]);
1377  } else {
1378  x = NULL;
1379  }
1380  }
1381 
1382  template<class View>
1383  void
1385  bool schedule) {
1386  for (int i = n; i--; )
1387  x[i].subscribe(home,p,pc,schedule);
1388  }
1389 
1390  template<class View>
1391  void
1393  for (int i = n; i--; )
1394  x[i].cancel(home,p,pc);
1395  }
1396 
1397  template<class View>
1398  void
1400  for (int i = n; i--; )
1401  x[i].subscribe(home,a);
1402  }
1403 
1404  template<class View>
1405  void
1407  for (int i = n; i--; )
1408  x[i].cancel(home,a);
1409  }
1410 
1411  template<class View>
1412  void
1414  for (int i = n; i--; )
1415  x[i].reschedule(home,p,pc);
1416  }
1417 
1418  template<class View>
1419  forceinline bool
1421  for (int i = n; i--;)
1422  if (!x[i].assigned())
1423  return false;
1424  return true;
1425  }
1426 
1427  template<class View>
1428  forceinline bool
1429  __before(const View& x, const View& y) {
1430  return before(x,y);
1431  }
1432 
1433  template<class View> template<class X>
1434  forceinline bool
1435  ViewArray<View>::ViewLess<X>::operator ()(const X& a, const X& b) {
1436  return __before(a,b);
1437  }
1438 
1439  template<class View>
1440  void
1441  ViewArray<View>::sort(View* y, int m) {
1442  ViewLess<View> vl;
1443  Support::quicksort<View,ViewLess<View> >(y,m,vl);
1444  }
1445 
1446  template<class X, class Y>
1447  forceinline bool
1448  __same(const X& x, const Y& y) {
1449  return same(x,y);
1450  }
1451  template<class X, class Y>
1452  forceinline bool
1453  __shared(const X& x, const Y& y) {
1454  return shared(x,y);
1455  }
1456 
1457  template<class View>
1458  bool
1460  if (n < 2)
1461  return false;
1462  Region r;
1463  View* y = r.alloc<View>(n);
1464  for (int i = n; i--; )
1465  y[i] = x[i];
1466  sort(y,n);
1467  for (int i = n-1; i--; )
1468  if (!y[i].assigned() && __same(y[i+1],y[i])) {
1469  r.free<View>(y,n);
1470  return true;
1471  }
1472  r.free<View>(y,n);
1473  return false;
1474  }
1475 
1476  template<class View>
1477  bool
1478  ViewArray<View>::same(const View& y) const {
1479  if (y.assigned())
1480  return false;
1481  for (int i = n; i--; )
1482  if (__same(x[i],y))
1483  return true;
1484  return false;
1485  }
1486 
1487  template<class View>
1488  void
1490  if (n < 2)
1491  return;
1492  sort(x,n);
1493  int j = 0;
1494  for (int i = 1; i<n; i++)
1495  if (!__same(x[j],x[i]))
1496  x[++j] = x[i];
1497  n = j+1;
1498  }
1499 
1500  template<class View>
1501  bool
1503  if (n < 2)
1504  return false;
1505  Region r;
1506  View* y = r.alloc<View>(n);
1507  for (int i = n; i--; )
1508  y[i] = x[i];
1509  sort(y,n);
1510  for (int i = n-1; i--; )
1511  if (!y[i].assigned() && __shared(y[i+1],y[i])) {
1512  r.free<View>(y,n);
1513  return true;
1514  }
1515  r.free<View>(y,n);
1516  return false;
1517  }
1518 
1519  template<class View> template<class ViewY>
1520  bool
1521  ViewArray<View>::shared(const ViewY& y) const {
1522  if (y.assigned())
1523  return false;
1524  for (int i = n; i--; )
1525  if (!x[i].assigned() && __shared(x[i],y))
1526  return true;
1527  return false;
1528  }
1529 
1530  template<class View> template<class ViewY>
1531  bool
1533  if ((size() < 1) || (y.size() < 1))
1534  return false;
1535  Region r;
1536  View* xs = r.alloc<View>(size());
1537  for (int i=size(); i--; )
1538  xs[i] = x[i];
1539  ViewLess<View> xvl;
1540  Support::quicksort<View,ViewLess<View> >(xs,size(),xvl);
1541  ViewY* ys = r.alloc<ViewY>(y.size());
1542  for (int j=y.size(); j--; )
1543  ys[j] = y[j];
1544  ViewLess<ViewY> yvl;
1545  Support::quicksort<ViewY,ViewLess<ViewY> >(ys,y.size(),yvl);
1546  {
1547  int i=0, j=0;
1548  while ((i < size()) && (j < y.size()))
1549  if (!x[i].assigned() && __shared(x[i],y[j])) {
1550  r.free<View>(xs,size());
1551  r.free<ViewY>(ys,y.size());
1552  return true;
1553  } else if (before(x[i],y[j])) {
1554  i++;
1555  } else {
1556  j++;
1557  }
1558  }
1559  r.free<View>(xs,size());
1560  r.free<ViewY>(ys,y.size());
1561  return false;
1562  }
1563 
1564  template<class View>
1565  forceinline void*
1566  ViewArray<View>::operator new(size_t) throw() {
1567  return NULL;
1568  }
1569 
1570  template<class View>
1571  forceinline void
1572  ViewArray<View>::operator delete(void*,size_t) {
1573  }
1574 
1575 
1576  /*
1577  * Argument arrays: base class
1578  *
1579  */
1580 
1581  template<class T>
1582  forceinline T*
1584  return (n > onstack_size) ?
1585  heap.alloc<T>(static_cast<unsigned int>(n)) : &onstack[0];
1586  }
1587 
1588  template<class T>
1589  forceinline void
1591  if (n+i >= capacity) {
1592  assert(n+i >= onstack_size);
1593  int newCapacity = (3*capacity)/2;
1594  if (newCapacity <= n+i)
1595  newCapacity = n+i;
1596  T* newA = allocate(newCapacity);
1597  heap.copy<T>(newA,a,n);
1598  if (capacity > onstack_size)
1599  heap.free(a,capacity);
1600  capacity = newCapacity;
1601  a = newA;
1602  }
1603  }
1604 
1605  template<class T>
1606  forceinline
1608  : n(0), capacity(onstack_size), a(allocate(0)) {}
1609 
1610  template<class T>
1611  forceinline
1613  : n(n0), capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {}
1614 
1615  template<class T>
1616  inline
1618  : n(aa.n), capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
1619  heap.copy<T>(a,aa.a,n);
1620  }
1621 
1622  template<class T>
1623  inline
1624  ArgArrayBase<T>::ArgArrayBase(const std::vector<T>& aa)
1625  : n(static_cast<int>(aa.size())),
1626  capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
1627  heap.copy<T>(a,&aa[0],n);
1628  }
1629 
1630  template<class T>
1631  forceinline
1633  if (capacity > onstack_size)
1634  heap.free(a,capacity);
1635  }
1636 
1637  template<class T>
1640  if (&aa != this) {
1641  if (capacity > onstack_size)
1642  heap.free(a,capacity);
1643  n = aa.n;
1644  capacity = (n < onstack_size ? onstack_size : n);
1645  a = allocate(aa.n);
1646  heap.copy<T>(a,aa.a,n);
1647  }
1648  return *this;
1649  }
1650 
1651  template<class T>
1652  forceinline int
1654  return n;
1655  }
1656 
1657  template<class T>
1658  forceinline T&
1660  assert((i>=0) && (i < n));
1661  return a[i];
1662  }
1663 
1664  template<class T>
1665  forceinline const T&
1667  assert((i>=0) && (i < n));
1668  return a[i];
1669  }
1670 
1671  template<class T>
1674  return a;
1675  }
1676 
1677  template<class T>
1680  return a;
1681  }
1682 
1683  template<class T>
1686  return a+n;
1687  }
1688 
1689  template<class T>
1691  ArgArrayBase<T>::end(void) const {
1692  return a+n;
1693  }
1694 
1695  template<class T>
1698  return reverse_iterator(a+n);
1699  }
1700 
1701  template<class T>
1704  return const_reverse_iterator(a+n);
1705  }
1706 
1707  template<class T>
1710  return reverse_iterator(a);
1711  }
1712 
1713  template<class T>
1716  return const_reverse_iterator(a);
1717  }
1718 
1719  template<class T> template<class A>
1720  A
1721  ArgArrayBase<T>::slice(int start, int inc, int maxN) {
1722  assert(n==0 || start < n);
1723  if (n==0 || maxN<0)
1724  maxN = n;
1725  int s;
1726  if (inc == 0)
1727  s = n-start;
1728  else if (inc > 0)
1729  s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
1730  else
1731  s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
1732  A r(std::min(maxN,s));
1733  for (int i=0; i<r.size(); i++, start+=inc)
1734  new (&r[i]) T(a[start]);
1735  return r;
1736  }
1737 
1738  template<class T> template<class A>
1739  inline A&
1741  resize(1);
1742  new (&a[n++]) T(x);
1743  return static_cast<A&>(*this);
1744  }
1745 
1746  template<class T>
1747  template<class InputIterator>
1748  inline
1749  ArgArrayBase<T>::ArgArrayBase(InputIterator first, InputIterator last)
1750  : n(0), capacity(onstack_size), a(allocate(0)) {
1751  while (first != last) {
1752  (void) append<ArgArrayBase<T> >(*first);
1753  ++first;
1754  }
1755  }
1756 
1757 
1758  template<class T> template<class A>
1759  inline A&
1761  resize(x.size());
1762  for (int i=0; i<x.size(); i++)
1763  new (&a[n++]) T(x[i]);
1764  return static_cast<A&>(*this);
1765  }
1766 
1767  template<class T> template<class A>
1768  inline A
1770  A r(n+x.n);
1771  for (int i=n; i--;)
1772  new (&r[i]) T(a[i]);
1773  for (int i=x.n; i--;)
1774  new (&r[n+i]) T(x.a[i]);
1775  return r;
1776  }
1777 
1778  template<class T> template<class A>
1779  inline A
1780  ArgArrayBase<T>::concat(const T& x) const {
1781  A r(n+1);
1782  for (int i=n; i--;)
1783  new (&r[i]) T(a[i]);
1784  new (&r[n]) T(x);
1785  return r;
1786  }
1787 
1788  /*
1789  * Argument arrays for primitive types
1790  *
1791  */
1792 
1793  template<class T>
1794  forceinline
1796 
1797  template<class T>
1798  forceinline
1800 
1801  template<class T>
1803  : ArgArrayBase<T>(n) {
1804  va_list args;
1805  va_start(args, a0);
1806  a[0] = a0;
1807  for (int i = 1; i < n; i++)
1808  a[i] = va_arg(args,T);
1809  va_end(args);
1810  }
1811 
1812  template<class T>
1814  : ArgArrayBase<T>(n) {
1815  for (int i=n; i--; )
1816  a[i] = a0[i];
1817  }
1818 
1819  template<class T>
1820  forceinline
1822  : ArgArrayBase<T>(aa) {}
1823 
1824  template<class T>
1825  forceinline
1826  PrimArgArray<T>::PrimArgArray(const std::vector<T>& aa)
1827  : ArgArrayBase<T>(aa) {}
1828 
1829  template<class T>
1830  template<class InputIterator>
1831  forceinline
1832  PrimArgArray<T>::PrimArgArray(InputIterator first, InputIterator last)
1833  : ArgArrayBase<T>(first,last) {}
1834 
1835  template<class T>
1836  forceinline typename ArrayTraits<PrimArgArray<T> >::ArgsType
1837  PrimArgArray<T>::slice(int start, int inc, int maxN) {
1839  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>
1840  (start,inc,maxN);
1841  }
1842 
1843  template<class T>
1844  forceinline typename ArrayTraits<PrimArgArray<T> >::ArgsType&
1846  return
1848  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>(x);
1849  }
1850 
1851  template<class T>
1852  forceinline typename ArrayTraits<PrimArgArray<T> >::ArgsType&
1854  return
1856  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>(x);
1857  }
1858 
1859  template<class T>
1860  typename ArrayTraits<PrimArgArray<T> >::ArgsType
1862  return x.template concat
1863  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>(y);
1864  }
1865 
1866  template<class T>
1867  typename ArrayTraits<PrimArgArray<T> >::ArgsType
1868  operator +(const PrimArgArray<T>& x, const T& y) {
1869  return x.template concat
1870  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>(y);
1871  }
1872 
1873  template<class T>
1874  typename ArrayTraits<PrimArgArray<T> >::ArgsType
1875  operator +(const T& x, const PrimArgArray<T>& y) {
1876  return PrimArgArray<T>(1,x).template concat
1877  <typename ArrayTraits<PrimArgArray<T> >::ArgsType>(y);
1878  }
1879 
1880 
1881  /*
1882  * Argument arrays for non-primitive types
1883  *
1884  */
1885 
1886  template<class T>
1887  forceinline
1889 
1890  template<class T>
1891  forceinline
1893 
1894  template<class T>
1895  ArgArray<T>::ArgArray(int n, const T* a0)
1896  : ArgArrayBase<T>(n) {
1897  for (int i=n; i--; )
1898  a[i] = a0[i];
1899  }
1900 
1901  template<class T>
1902  forceinline
1904  : ArgArrayBase<T>(aa) {}
1905 
1906  template<class T>
1907  forceinline
1908  ArgArray<T>::ArgArray(const std::vector<T>& aa)
1909  : ArgArrayBase<T>(aa) {}
1910 
1911  template<class T>
1912  template<class InputIterator>
1913  forceinline
1914  ArgArray<T>::ArgArray(InputIterator first, InputIterator last)
1915  : ArgArrayBase<T>(first,last) {}
1916 
1917  template<class T>
1918  forceinline typename ArrayTraits<ArgArray<T> >::ArgsType
1919  ArgArray<T>::slice(int start, int inc, int maxN) {
1921  <typename ArrayTraits<ArgArray<T> >::ArgsType>
1922  (start,inc,maxN);
1923  }
1924 
1925  template<class T>
1926  forceinline typename ArrayTraits<ArgArray<T> >::ArgsType&
1928  return
1930  <typename ArrayTraits<ArgArray<T> >::ArgsType>(x);
1931  }
1932 
1933  template<class T>
1934  forceinline typename ArrayTraits<ArgArray<T> >::ArgsType&
1936  return
1938  <typename ArrayTraits<ArgArray<T> >::ArgsType>(x);
1939  }
1940 
1941  template<class T>
1942  typename ArrayTraits<ArgArray<T> >::ArgsType
1943  operator +(const ArgArray<T>& x, const ArgArray<T>& y) {
1944  return x.template concat
1945  <typename ArrayTraits<ArgArray<T> >::ArgsType>(y);
1946  }
1947 
1948  template<class T>
1949  typename ArrayTraits<ArgArray<T> >::ArgsType
1950  operator +(const ArgArray<T>& x, const T& y) {
1951  return x.template concat
1952  <typename ArrayTraits<ArgArray<T> >::ArgsType>(y);
1953  }
1954 
1955  template<class T>
1956  typename ArrayTraits<ArgArray<T> >::ArgsType
1957  operator +(const T& x, const ArgArray<T>& y) {
1958  ArgArray<T> xa(1);
1959  xa[0] = x;
1960  return xa.template concat
1961  <typename ArrayTraits<ArgArray<T> >::ArgsType>(y);
1962  }
1963 
1964  /*
1965  * Argument arrays for variables
1966  *
1967  */
1968 
1969  template<class Var>
1970  forceinline
1972 
1973  template<class Var>
1974  forceinline
1976 
1977  template<class Var>
1978  forceinline
1980  : ArgArrayBase<Var>(aa) {}
1981 
1982  template<class Var>
1983  forceinline
1984  VarArgArray<Var>::VarArgArray(const std::vector<Var>& aa)
1985  : ArgArrayBase<Var>(aa) {}
1986 
1987  template<class Var>
1988  template<class InputIterator>
1989  forceinline
1990  VarArgArray<Var>::VarArgArray(InputIterator first, InputIterator last)
1991  : ArgArrayBase<Var>(first,last) {}
1992 
1993  template<class Var>
1994  inline
1996  : ArgArrayBase<Var>(x.size()) {
1997  for (int i=x.size(); i--; )
1998  a[i]=x[i];
1999  }
2000 
2001  template<class Var>
2002  forceinline typename ArrayTraits<VarArgArray<Var> >::ArgsType
2003  VarArgArray<Var>::slice(int start, int inc, int maxN) {
2005  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>
2006  (start,inc,maxN);
2007  }
2008 
2009  template<class Var>
2010  forceinline typename ArrayTraits<VarArgArray<Var> >::ArgsType&
2012  return
2014  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>(x);
2015  }
2016 
2017  template<class Var>
2018  forceinline typename ArrayTraits<VarArgArray<Var> >::ArgsType&
2020  return
2022  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>(x);
2023  }
2024 
2025  template<class Var>
2026  typename ArrayTraits<VarArgArray<Var> >::ArgsType
2028  return x.template concat
2029  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>(y);
2030  }
2031 
2032  template<class Var>
2033  typename ArrayTraits<VarArgArray<Var> >::ArgsType
2034  operator +(const VarArgArray<Var>& x, const Var& y) {
2035  return x.template concat
2036  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>(y);
2037  }
2038 
2039  template<class Var>
2040  typename ArrayTraits<VarArgArray<Var> >::ArgsType
2041  operator +(const Var& x, const VarArgArray<Var>& y) {
2042  VarArgArray<Var> xa(1);
2043  xa[0] = x;
2044  return xa.template concat
2045  <typename ArrayTraits<VarArgArray<Var> >::ArgsType>(y);
2046  }
2047 
2048  template<class Var>
2049  forceinline bool
2051  return a.varimp() < b.varimp();
2052  }
2053 
2054  template<class Var>
2055  forceinline bool
2057  for (int i = n; i--;)
2058  if (!a[i].assigned())
2059  return false;
2060  return true;
2061  }
2062 
2063  template<class Var>
2064  bool
2066  if (n < 2)
2067  return false;
2068  Region r;
2069  Var* y = r.alloc<Var>(n);
2070  for (int i = n; i--; )
2071  y[i] = a[i];
2072  VarLess vl;
2073  Support::quicksort<Var,VarLess>(y,n,vl);
2074  for (int i = n-1; i--; )
2075  if (!y[i].assigned() && (y[i+1].varimp() == y[i].varimp())) {
2076  r.free<Var>(y,n);
2077  return true;
2078  }
2079  r.free<Var>(y,n);
2080  return false;
2081  }
2082 
2083  template<class Var>
2084  bool
2086  int m = n + y.n;
2087  if (m < 2)
2088  return false;
2089  Region r;
2090  Var* z = r.alloc<Var>(m);
2091  for (int i = n; i--; )
2092  z[i] = a[i];
2093  for (int i = y.n; i--; )
2094  z[i+n] = y.a[i];
2095  VarLess vl;
2096  Support::quicksort<Var,VarLess>(z,m,vl);
2097  for (int i = m-1; i--; )
2098  if (!z[i].assigned() && (z[i+1].varimp() == z[i].varimp())) {
2099  r.free<Var>(z,m);
2100  return true;
2101  }
2102  r.free<Var>(z,m);
2103  return false;
2104  }
2105 
2106  template<class Var>
2107  bool
2108  VarArgArray<Var>::same(const Var& y) const {
2109  if (y.assigned())
2110  return false;
2111  for (int i = n; i--; )
2112  if (a[i].varimp() == y.varimp())
2113  return true;
2114  return false;
2115  }
2116 
2117 
2118 
2119 
2120 
2121 
2122  /*
2123  * Interdependent code
2124  *
2125  */
2126 
2127  template<class Var>
2128  inline
2130  : n(a.size()) {
2131  if (n>0) {
2132  x = home.alloc<Var>(n);
2133  for (int i=n; i--;)
2134  x[i] = a[i];
2135  } else {
2136  x = NULL;
2137  }
2138  }
2139 
2140 
2141  /*
2142  * Printing of arrays
2143  *
2144  */
2145  template<class Char, class Traits, class Var>
2146  std::basic_ostream<Char,Traits>&
2147  operator <<(std::basic_ostream<Char,Traits>& os,
2148  const VarArray<Var>& x) {
2149  std::basic_ostringstream<Char,Traits> s;
2150  s.copyfmt(os); s.width(0);
2151  s << '{';
2152  if (x.size() > 0) {
2153  s << x[0];
2154  for (int i=1; i<x.size(); i++)
2155  s << ", " << x[i];
2156  }
2157  s << '}';
2158  return os << s.str();
2159  }
2160 
2161  template<class Char, class Traits, class View>
2162  std::basic_ostream<Char,Traits>&
2163  operator <<(std::basic_ostream<Char,Traits>& os,
2164  const ViewArray<View>& x) {
2165  std::basic_ostringstream<Char,Traits> s;
2166  s.copyfmt(os); s.width(0);
2167  s << '{';
2168  if (x.size() > 0) {
2169  s << x[0];
2170  for (int i=1; i<x.size(); i++)
2171  s << ", " << x[i];
2172  }
2173  s << '}';
2174  return os << s.str();
2175  }
2176 
2177  template<class Char, class Traits, class T>
2178  std::basic_ostream<Char,Traits>&
2179  operator <<(std::basic_ostream<Char,Traits>& os,
2180  const ArgArrayBase<T>& x) {
2181  std::basic_ostringstream<Char,Traits> s;
2182  s.copyfmt(os); s.width(0);
2183  s << '{';
2184  if (x.size() > 0) {
2185  s << x[0];
2186  for (int i=1; i<x.size(); i++)
2187  s << ", " << x[i];
2188  }
2189  s << '}';
2190  return os << s.str();
2191  }
2192 
2193 }
2194 
2195 // STATISTICS: kernel-other
void free(void)
Free allocate memory.
Definition: region.hpp:350
int capacity
Allocated size of the array.
Definition: array.hpp:513
static T * copy(T *d, const T *s, long unsigned int n)
Copy n objects starting at s to d.
Definition: heap.hpp:583
const T * const_iterator
Type of the iterator used to iterate read-only through this array&#39;s elements.
Definition: array.hpp:559
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1653
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:969
Argument array for primtive types.
Definition: array.hpp:624
bool __shared(const X &x, const Y &y)
Definition: array.hpp:1453
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:81
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition: region.hpp:380
Var * iterator
Type of the iterator used to iterate through this array&#39;s elements.
Definition: array.hpp:102
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:563
Var & reference
Type of a reference to the value type.
Definition: array.hpp:94
Base-class for propagators.
Definition: core.hpp:1023
Var * pointer
Type of a pointer to the value type.
Definition: array.hpp:98
Base-class for advisors.
Definition: core.hpp:1251
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const ArgArrayBase< T > &x)
Definition: array.hpp:2179
Variable arrays
Definition: array.hpp:48
T * iterator
Type of the iterator used to iterate through this array&#39;s elements.
Definition: array.hpp:557
Handle to region.
Definition: region.hpp:53
#define forceinline
Definition: config.hpp:185
const View & const_reference
Type of a constant reference to the value type.
Definition: array.hpp:246
Computation spaces.
Definition: core.hpp:1701
View * iterator
Type of the iterator used to iterate through this array&#39;s elements.
Definition: array.hpp:252
bool shared(const IntSet &, VX)
Definition: view-base.hpp:118
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition: core.hpp:2794
View * pointer
Type of a pointer to the value type.
Definition: array.hpp:248
const Var & const_reference
Type of a constant reference to the value type.
Definition: array.hpp:96
void sort(TaskViewArray< TaskView > &t)
Sort task view array t according to sto and inc (increasing or decreasing)
Definition: sort.hpp:133
bool same(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether two views are the same.
Definition: view.hpp:676
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
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:108
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Definition: heap.hpp:431
const FloatNum min
Smallest allowed float value.
Definition: float.hh:846
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Argument array for non-primitive types.
Definition: array.hpp:711
Var * x
Array of variables.
Definition: array.hpp:87
const View * const_pointer
Type of a read-only pointer to the value type.
Definition: array.hpp:250
FloatVal operator+(const FloatVal &x)
Definition: val.hpp:164
NNF * r
Right subtree.
Definition: bool-expr.cpp:242
int PropCond
Type for propagation conditions.
Definition: core.hpp:72
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:71
ArrayTraits< VarArgArray< Var > >::ArgsType operator+(const Var &x, const VarArgArray< Var > &y)
Definition: array.hpp:2041
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:302
VarArray(void)
Default constructor (array of size 0)
Definition: array.hpp:944
T & reference
Type of a reference to the value type.
Definition: array.hpp:549
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:765
bool __before(const View &x, const View &y)
Definition: array.hpp:1429
View arrays.
Definition: array.hpp:224
int n
Number of variables (size)
Definition: array.hpp:85
bool __same(const X &x, const Y &y)
Definition: array.hpp:1448
Boolean integer variables.
Definition: int.hh:488
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:765
bool before(const Item &i, const Item &j)
Test whether one item is before another.
Definition: propagate.hpp:76
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:553
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:765
View & reference
Type of a reference to the value type.
Definition: array.hpp:244
Base class for variables.
Definition: var.hpp:40
void free(T *b, long unsigned int n)
Delete n objects starting at b.
Definition: heap.hpp:457
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
Base-class for argument arrays.
Definition: array.hpp:508
Heap heap
The single global heap.
Definition: heap.cpp:44
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:43
bool same(const Item &i, const Item &j)
Whether two items are the same.
Definition: propagate.hpp:72
const int vl[6]
Definition: distinct.cpp:261
const Var * const_pointer
Type of a read-only pointer to the value type.
Definition: array.hpp:100
Post propagator for SetVar x
Definition: set.hh:765
Archive & operator<<(Archive &e, FloatNumBranch nl)
Definition: val-sel.hpp:39
int n
Number of elements.
Definition: array.hpp:511
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:735
Sort order for variables.
Definition: array.hpp:832
Traits of arrays in Gecode.
Definition: array.hpp:64
const T & const_reference
Type of a constant reference to the value type.
Definition: array.hpp:551
Gecode toplevel namespace
Argument array for variables.
Definition: array.hpp:49
const int capacity[n_warehouses]
Capacity of a single warehouse.
Definition: warehouses.cpp:49
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:258
ViewArray(Space &home, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements)
Definition: array.hpp:284
std::reverse_iterator< T * > reverse_iterator
Type of the iterator used to iterate backwards through this array&#39;s elements.
Definition: array.hpp:561
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:92
const Var * const_iterator
Type of the iterator used to iterate read-only through this array&#39;s elements.
Definition: array.hpp:104
View value_type
Type of the view stored in this array.
Definition: array.hpp:242
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1199
const View * const_iterator
Type of the iterator used to iterate read-only through this array&#39;s elements.
Definition: array.hpp:254
std::reverse_iterator< View * > reverse_iterator
Type of the iterator used to iterate backwards through this array&#39;s elements.
Definition: array.hpp:256
const T * const_pointer
Type of a read-only pointer to the value type.
Definition: array.hpp:555
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:103
const unsigned int slice
Size of a slice in a portfolio and scale factor for restarts(in number of failures) ...
Definition: search.hh:126
std::reverse_iterator< Var * > reverse_iterator
Type of the iterator used to iterate backwards through this array&#39;s elements.
Definition: array.hpp:106
T * a
Element array.
Definition: array.hpp:515