removed object. This is an O(1) operation. */
#define VEC_unordered_remove(TDEF,V,I) (VEC_OP(TDEF,unordered_remove)(V,I))
+/* Get the address of the array of elements
+ T *VEC_T_address (VEC(T) v)
+
+ If you need to directly manipulate the array (for instance, you
+ want to feed it to qsort), use this accessor. */
+#define VEC_address(TDEF,V) (VEC_OP(TDEF,address)(V))
+
#if !IN_GENGTYPE
/* Reallocate an array of elements with prefix. */
extern void *vec_p_reserve (void *, int MEM_STAT_DECL);
static inline void VEC_OP (TDEF,truncate) \
(VEC (TDEF) *vec_, size_t size_) \
{ \
- VEC_ASSERT (vec_->num >= size_, "truncate", TDEF); \
- vec_->num = size_; \
+ VEC_ASSERT (vec_ ? vec_->num >= size_ : !size_, "truncate", TDEF); \
+ if (vec_) \
+ vec_->num = size_; \
} \
\
static inline TDEF VEC_OP (TDEF,replace) \
VEC_ASSERT (vec_->num < vec_->alloc, "insert", TDEF); \
VEC_ASSERT (ix_ <= vec_->num, "insert", TDEF); \
slot_ = &vec_->vec[ix_]; \
- memmove (slot_ + 1, slot_, vec_->num++ - ix_); \
+ memmove (slot_ + 1, slot_, (vec_->num++ - ix_) * sizeof (TDEF)); \
*slot_ = obj_; \
\
return slot_; \
VEC_ASSERT (ix_ < vec_->num, "remove", TDEF); \
slot_ = &vec_->vec[ix_]; \
obj_ = *slot_; \
- memmove (slot_, slot_ + 1, --vec_->num - ix_); \
+ memmove (slot_, slot_ + 1, (--vec_->num - ix_) * sizeof (TDEF)); \
\
return obj_; \
} \
return obj_; \
} \
\
+static inline TDEF *VEC_OP (TDEF,address) \
+ (VEC (TDEF) *vec_) \
+{ \
+ return vec_ ? vec_->vec : 0; \
+} \
+ \
struct vec_swallow_trailing_semi
#endif
static inline void VEC_OP (TDEF,truncate) \
(VEC (TDEF) *vec_, size_t size_) \
{ \
- VEC_ASSERT (vec_->num >= size_, "truncate", TDEF); \
- vec_->num = size_; \
+ VEC_ASSERT (vec_ ? vec_->num >= size_ : !size_, "truncate", TDEF); \
+ if (vec_) \
+ vec_->num = size_; \
} \
\
static inline TDEF *VEC_OP (TDEF,replace) \
VEC_ASSERT (vec_->num < vec_->alloc, "insert", TDEF); \
VEC_ASSERT (ix_ <= vec_->num, "insert", TDEF); \
slot_ = &vec_->vec[ix_]; \
- memmove (slot_ + 1, slot_, vec_->num++ - ix_); \
+ memmove (slot_ + 1, slot_, (vec_->num++ - ix_) * sizeof (TDEF)); \
if (obj_) \
*slot_ = *obj_; \
\
\
VEC_ASSERT (ix_ < vec_->num, "remove", TDEF); \
slot_ = &vec_->vec[ix_]; \
- memmove (slot_, slot_ + 1, --vec_->num - ix_); \
+ memmove (slot_, slot_ + 1, (--vec_->num - ix_) * sizeof (TDEF)); \
} \
\
static inline void VEC_OP (TDEF,unordered_remove) \
vec_->vec[ix_] = vec_->vec[--vec_->num]; \
} \
\
+static inline TDEF *VEC_OP (TDEF,address) \
+ (VEC (TDEF) *vec_) \
+{ \
+ return vec_ ? vec_->vec : 0; \
+} \
+ \
struct vec_swallow_trailing_semi
#endif