19 #define __INLINE inline 46 inline const T*
end()
const {
return _end; }
57 T
last()
const {
return *(_end - 1); }
63 if (_end == end_array)
64 resize(2 * (end_array - _begin) + 3);
71 if ((
size_t)(end_array - _begin) != length)
73 size_t old_len = _end -
_begin;
74 T* temp = (T*)realloc(_begin,
sizeof(T) * length);
75 if ((temp ==
nullptr) && ((
sizeof(T) * length) > 0))
77 THROW_OR_RETURN(
"realloc of " << length <<
" failed in resize(). out of memory?");
81 if (old_len < length && _begin + old_len !=
nullptr)
82 memset(_begin + old_len, 0, (length - old_len) *
sizeof(T));
83 _end = _begin + old_len;
84 end_array = _begin + length;
95 for (T* item = _begin; item !=
_end; ++item) item->~T();
100 if (_begin !=
nullptr)
102 for (T* item = _begin; item !=
_end; ++item) item->~T();
105 _begin = _end = end_array =
nullptr;
109 if (_end == end_array)
110 resize(2 * (end_array - _begin) + 3);
111 new (_end++) T(new_ele);
121 size_t i = (a + b) / 2;
127 else if (_begin[i] > ele)
135 if ((size == 0) || (_begin[
a] > ele) || (_begin[a] == ele))
148 if (_end == end_array)
149 resize(2 * (end_array - _begin) + 3);
151 to_move = size - index;
154 memmove(_begin + index + 1, _begin + index,
155 to_move *
sizeof(T));
157 _begin[index] = new_ele;
168 if (index == this->
size())
171 if (_begin[index] == ele)
181 return {
nullptr,
nullptr,
nullptr, 0};
212 memcpy_s(v.
_end, v.
size() - (num *
sizeof(T)),
_begin, num *
sizeof(T));
214 memcpy(v.
_end, _begin, num *
sizeof(T));
222 v.
_begin = calloc_or_throw<T>(length);
230 if (stack._end != stack._begin)
231 return *(--stack._end);
246 std::ostream& operator<<(std::ostream& os, const v_array<T>& v)
249 for (T* i = v._begin; i != v._end; ++i) os <<
' ' << *i;
254 template <
class T,
class U>
255 std::ostream& operator<<(std::ostream& os, const v_array<std::pair<T, U> >& v)
258 for (std::pair<T, U>* i = v._begin; i != v._end; ++i) os <<
' ' << i->first <<
':' << i->second;
267 v_string res = v_init<unsigned char>();
276 for (
unsigned char* i = v_s.
_begin; i != v_s.
_end; ++i) res.push_back(*i);
void resize(size_t length)
void copy_array(v_array< T > &dst, const v_array< T > &src)
v_array< unsigned char > v_string
void push_many(v_array< T > &v, const T *_begin, size_t num)
void copy_array_no_memcpy(v_array< T > &dst, const v_array< T > &src)
void push_back(const T &new_ele)
size_t find_sorted(const T &ele) const
v_string string2v_string(const std::string &s)
void calloc_reserve(v_array< T > &v, size_t length)
T & operator[](size_t i) const
#define THROW_OR_RETURN(...)
bool v_array_contains(v_array< T > &A, T x)
std::string v_string2string(const v_string &v_s)
bool contain_sorted(const T &ele, size_t &index)
size_t unique_add_sorted(const T &new_ele)
void push_back_unchecked(const T &new_ele)