36 #define VEC_GC_ENABLED 0
38 #define VEC_GC_ENABLED 1
39 #endif // GENERATOR_FILE
55 #endif // VEC_GC_ENABLED
230 template <
typename,
typename,
typename>
friend struct vec;
242 template<
typename,
typename,
typename>
struct vec;
295 if (GATHER_STATISTICS && v)
296 v->vecpfx_.release_overhead ();
299 unsigned nelem = v ? v->length () : 0;
301 v->embedded_init (alloc, nelem);
303 if (GATHER_STATISTICS)
304 v->vecpfx_.register_overhead (size FINAL_PASS_MEM_STAT);
317 if (GATHER_STATISTICS)
318 v->vecpfx_.release_overhead ();
335 template<
typename T,
typename A>
339 template<
typename T,
typename A>
346 template<
typename T,
typename A>
361 template<
typename T,
typename A>
383 size_t elt_size =
sizeof (
T);
384 alloc = (size - vec_offset) / elt_size;
387 size = vec_offset + alloc * elt_size;
389 unsigned nelem = v ? v->
length () : 0;
414 template <
typename T>
418 template <
typename T>
438 v.vec_->embedded_init (nelems, 0);
460 nelems, exact PASS_MEM_STAT);
465 nelems += v->vecpfx_.num_;
469 exact PASS_MEM_STAT);
472 v->vecpfx_.num_ = oldvec->length ();
475 oldvec->length () *
sizeof (
T));
518 typename L =
typename A::default_layout>
529 template <
typename T,
typename A,
typename L>
561 template<
typename T,
typename A>
565 unsigned allocated (
void)
const {
return vecpfx_.alloc_; }
566 unsigned length (
void)
const {
return vecpfx_.num_; }
567 bool is_empty (
void)
const {
return vecpfx_.num_ == 0; }
570 const T &operator[] (
unsigned)
const;
571 T &operator[] (
unsigned);
573 bool space (
unsigned)
const;
574 bool iterate (
unsigned,
T *)
const;
575 bool iterate (
unsigned,
T **)
const;
576 vec *
copy (ALONE_CXX_MEM_STAT_INFO)
const;
578 void splice (
vec *src);
579 T *quick_push (
const T &);
581 void truncate (
unsigned);
582 void quick_insert (
unsigned,
const T &);
583 void ordered_remove (
unsigned);
584 void unordered_remove (
unsigned);
585 void block_remove (
unsigned,
unsigned);
586 void qsort (
int (*) (
const void *,
const void *));
587 unsigned lower_bound (
T,
bool (*)(
const T &,
const T &))
const;
588 static size_t embedded_size (
unsigned);
589 void embedded_init (
unsigned,
unsigned = 0);
590 void quick_grow (
unsigned len);
591 void quick_grow_cleared (
unsigned len);
594 template <
typename,
typename,
typename>
friend struct vec;
624 template<
typename T,
typename A>
628 return v ? v->
space (nelems) : nelems == 0;
633 template<
typename T,
typename A>
637 return v ? v->
length () : 0;
642 template<
typename T,
typename A>
646 return v ? v->
address () : NULL;
651 template<
typename T,
typename A>
661 template<
typename T,
typename A>
672 template<
typename T,
typename A>
684 template<
typename T,
typename A>
695 template<
typename T,
typename A>
704 template<
typename T,
typename A>
709 gcc_checking_assert (
len >= oldlen);
716 template<
typename T,
typename A>
727 template<
typename T,
typename A>
740 template<
typename T,
typename A>
756 template<
typename T,
typename A>
767 template<
typename T,
typename A>
778 template<
typename T,
typename A>
788 template<
typename T,
typename A>
792 return src ? src->
copy () : NULL;
797 template<
typename T,
typename A>
815 template<
typename T,
typename A>
819 gcc_checking_assert (ix < vecpfx_.num_);
823 template<
typename T,
typename A>
827 gcc_checking_assert (ix < vecpfx_.num_);
834 template<
typename T,
typename A>
838 gcc_checking_assert (vecpfx_.num_ > 0);
839 return (*
this)[vecpfx_.num_ - 1];
849 template<
typename T,
typename A>
853 return vecpfx_.alloc_ - vecpfx_.num_ >= nelems;
864 template<
typename T,
typename A>
868 if (ix < vecpfx_.num_)
890 template<
typename T,
typename A>
894 if (ix < vecpfx_.num_)
896 *ptr = CONST_CAST (
T *, &vecdata_[ix]);
909 template<
typename T,
typename A>
914 unsigned len = length ();
928 template<
typename T,
typename A>
935 gcc_checking_assert (space (len));
941 template<
typename T,
typename A>
954 template<
typename T,
typename A>
958 gcc_checking_assert (space (1));
959 T *
slot = &vecdata_[vecpfx_.num_++];
967 template<
typename T,
typename A>
971 gcc_checking_assert (length () > 0);
972 return vecdata_[--vecpfx_.num_];
979 template<
typename T,
typename A>
983 gcc_checking_assert (length () >= size);
991 template<
typename T,
typename A>
995 gcc_checking_assert (length () < allocated ());
996 gcc_checking_assert (ix <= length ());
997 T *
slot = &vecdata_[ix];
998 memmove (slot + 1, slot, (vecpfx_.num_++ - ix) * sizeof (
T));
1007 template<
typename T,
typename A>
1011 gcc_checking_assert (ix < length());
1012 T *
slot = &vecdata_[ix];
1013 memmove (slot, slot + 1, (--vecpfx_.num_ - ix) * sizeof (
T));
1020 template<
typename T,
typename A>
1024 gcc_checking_assert (ix < length());
1025 vecdata_[ix] = vecdata_[--vecpfx_.num_];
1032 template<
typename T,
typename A>
1036 gcc_checking_assert (ix + len <= length());
1037 T *
slot = &vecdata_[ix];
1038 vecpfx_.num_ -=
len;
1039 memmove (slot, slot + len, (vecpfx_.num_ - ix) * sizeof (
T));
1046 template<
typename T,
typename A>
1050 ::qsort (address(), length(),
sizeof (
T), cmp);
1059 template<
typename T,
typename A>
1064 unsigned int len = length ();
1065 unsigned int half, middle;
1066 unsigned int first = 0;
1072 T middle_elem = (*this)[middle];
1073 if (lessthan (middle_elem, obj))
1077 len = len - half - 1;
1098 template<
typename T,
typename A>
1103 return offsetof (vec_embedded, vecdata_) + alloc *
sizeof (
T);
1110 template<
typename T,
typename A>
1114 vecpfx_.alloc_ =
alloc;
1122 template<
typename T,
typename A>
1126 gcc_checking_assert (length () <= len && len <= vecpfx_.alloc_);
1134 template<
typename T,
typename A>
1138 unsigned oldlen = length ();
1140 memset (&(address()[oldlen]), 0,
sizeof (
T) * (len - oldlen));
1146 template<
typename T>
1151 for (
unsigned i = 0; i < v->length (); i++)
1152 gt_ggc_mx ((*v)[i]);
1155 template<
typename T>
1166 template<
typename T,
typename A>
1171 for (
unsigned i = 0; i < v->
length (); i++)
1172 gt_pch_nx ((*v)[i]);
1175 template<
typename T,
typename A>
1179 for (
unsigned i = 0; i < v->length (); i++)
1180 op (&((*v)[i]), cookie);
1183 template<
typename T,
typename A>
1188 for (
unsigned i = 0; i < v->
length (); i++)
1221 template<
typename T,
typename A>
1227 void create (
unsigned nelems CXX_MEM_STAT_INFO);
1228 void release (
void);
1231 bool exists (
void)
const
1232 {
return vec_ != NULL; }
1235 {
return vec_ ? vec_->is_empty() :
true; }
1237 unsigned length (
void)
const
1238 {
return vec_ ? vec_->length() : 0; }
1241 {
return vec_ ? vec_->vecdata_ : NULL; }
1243 const T *address (
void)
const
1244 {
return vec_ ? vec_->vecdata_ : NULL; }
1246 const T &operator[] (
unsigned ix)
const
1247 {
return (*vec_)[ix]; }
1249 bool operator!=(
const vec &other)
const
1250 {
return !(*
this == other); }
1252 bool operator==(
const vec &other)
const
1253 {
return address() == other.address(); }
1255 T &operator[] (
unsigned ix)
1256 {
return (*vec_)[ix]; }
1259 {
return vec_->last(); }
1261 bool space (
int nelems)
const
1262 {
return vec_ ? vec_->space (nelems) : nelems == 0; }
1264 bool iterate (
unsigned ix,
T *p)
const;
1265 bool iterate (
unsigned ix,
T **p)
const;
1266 vec copy (ALONE_CXX_MEM_STAT_INFO)
const;
1267 bool reserve (
unsigned,
bool =
false CXX_MEM_STAT_INFO);
1268 bool reserve_exact (
unsigned CXX_MEM_STAT_INFO);
1269 void splice (
vec &);
1270 void safe_splice (
vec & CXX_MEM_STAT_INFO);
1271 T *quick_push (
const T &);
1272 T *safe_push (
const T &CXX_MEM_STAT_INFO);
1274 void truncate (
unsigned);
1275 void safe_grow (
unsigned CXX_MEM_STAT_INFO);
1276 void safe_grow_cleared (
unsigned CXX_MEM_STAT_INFO);
1277 void quick_grow (
unsigned);
1278 void quick_grow_cleared (
unsigned);
1279 void quick_insert (
unsigned,
const T &);
1280 void safe_insert (
unsigned,
const T & CXX_MEM_STAT_INFO);
1281 void ordered_remove (
unsigned);
1282 void unordered_remove (
unsigned);
1283 void block_remove (
unsigned,
unsigned);
1284 void qsort (
int (*) (
const void *,
const void *));
1285 unsigned lower_bound (
T,
bool (*)(
const T &,
const T &))
const;
1287 template<
typename T1>
1301 template<
typename T>
1311 template<
typename T>
1316 v->create (nelems PASS_MEM_STAT);
1322 template<
typename T>
1333 template<
typename T>
1378 #define vec_stack_alloc(T,V,N) \
1380 typedef vec<T, va_stack, vl_embed> stackv; \
1381 va_stack::alloc (V, N, XALLOCAVAR (stackv, stackv::embedded_size (N)));\
1392 template<
typename T,
typename A>
1397 return vec_->iterate (ix, ptr);
1415 template<
typename T,
typename A>
1420 return vec_->iterate (ix, ptr);
1430 #define FOR_EACH_VEC_ELT(V, I, P) \
1431 for (I = 0; (V).iterate ((I), &(P)); ++(I))
1433 #define FOR_EACH_VEC_SAFE_ELT(V, I, P) \
1434 for (I = 0; vec_safe_iterate ((V), (I), &(P)); ++(I))
1437 #define FOR_EACH_VEC_ELT_FROM(V, I, P, FROM) \
1438 for (I = (FROM); (V).iterate ((I), &(P)); ++(I))
1441 #define FOR_EACH_VEC_ELT_REVERSE(V, I, P) \
1442 for (I = (V).length () - 1; \
1443 (V).iterate ((I), &(P)); \
1446 #define FOR_EACH_VEC_SAFE_ELT_REVERSE(V, I, P) \
1447 for (I = vec_safe_length (V) - 1; \
1448 vec_safe_iterate ((V), (I), &(P)); \
1454 template<
typename T,
typename A>
1474 template<
typename T,
typename A>
1478 bool extend = nelems ? !space (nelems) :
false;
1480 A::reserve (vec_, nelems, exact PASS_MEM_STAT);
1490 template<
typename T,
typename A>
1494 return reserve (nelems,
true PASS_MEM_STAT);
1503 template<
typename T,
typename A>
1509 reserve_exact (nelems PASS_MEM_STAT);
1515 template<
typename T,
typename A>
1529 template<
typename T,
typename A>
1534 vec_->splice (*(src.
vec_));
1543 template<
typename T,
typename A>
1549 reserve_exact (src.
length());
1559 template<
typename T,
typename A>
1563 return vec_->quick_push (obj);
1571 template<
typename T,
typename A>
1575 reserve (1,
false PASS_MEM_STAT);
1576 return quick_push (obj);
1582 template<
typename T,
typename A>
1586 return vec_->pop ();
1593 template<
typename T,
typename A>
1598 vec_->truncate (size);
1600 gcc_checking_assert (size == 0);
1608 template<
typename T,
typename A>
1612 unsigned oldlen = length ();
1613 gcc_checking_assert (oldlen <= len);
1614 reserve_exact (len - oldlen PASS_MEM_STAT);
1615 vec_->quick_grow (len);
1623 template<
typename T,
typename A>
1627 unsigned oldlen = length ();
1628 safe_grow (len PASS_MEM_STAT);
1629 memset (&(address()[oldlen]), 0,
sizeof (
T) * (len - oldlen));
1636 template<
typename T,
typename A>
1640 gcc_checking_assert (vec_);
1641 vec_->quick_grow (len);
1649 template<
typename T,
typename A>
1653 gcc_checking_assert (vec_);
1654 vec_->quick_grow_cleared (len);
1661 template<
typename T,
typename A>
1665 vec_->quick_insert (ix, obj);
1672 template<
typename T,
typename A>
1676 reserve (1,
false PASS_MEM_STAT);
1677 quick_insert (ix, obj);
1685 template<
typename T,
typename A>
1689 vec_->ordered_remove (ix);
1696 template<
typename T,
typename A>
1700 vec_->unordered_remove (ix);
1707 template<
typename T,
typename A>
1711 vec_->block_remove (ix, len);
1718 template<
typename T,
typename A>
1732 template<
typename T,
typename A>
1737 return vec_ ? vec_->lower_bound (obj, lessthan) : 0;
1740 #if (GCC_VERSION >= 3000)
1741 # pragma GCC poison vec_ vecpfx_ vecdata_