3APICALL
void* _ExMalloc(
int Size);
4APICALL
void _ExFree(
void* Ptr);
8void _error_box(
const char* text);
10#define _strict_check(x) if(!(x))_error_box(#x)
12#define _strict_check(x)
15template <
class Elem,
int CellSize=1024>
25 inline void EnsureCapacity(
int N);
29 inline int Add(
const Elem& V);
30 inline int Add(
const Elem& V,
int NTimes);
31 template <
class array>
32 inline void AddRange(array& a);
33 inline Elem& operator [](
int pos);
34 inline const Elem& operator [](
int pos)
const;
35 inline int Count()
const;
37 inline void FastClear();
38 inline void Del(
int pos,
int num);
39 inline void uSet(
int pos,
const Elem& e,
const Elem& Default);
40 inline Elem uGet(
int pos,
const Elem& Default);;
42 Elem& ExpandTo(
int pos,Elem def);
45 void RemoveAt(
const int Index,
const int Count = 1);
46 void Insert(
const int Index,
const Elem& Value,
const int Count = 1);
47 template <
class array>
48 void Copy(
const array& Src);
49 template <
class array>
50 void AddRange(
const array& Src);
51 void SetCount(
const int Count);
52 void SetCount(
int Count,
const Elem& Value);
53 int IndexOf(
const Elem& e);
55 const Elem& GetLast()
const;
60 template <
class Reader>
61 void FromBS(Reader& BS,
int count);
62 template <
class Writer>
63 void ToBS(Writer& BS);
75 bool operator != (
const iterator& itr)
const {
76 return pos != itr.pos;
82 return &(*array)[pos];
89 return iterator(NValues,
this);
95template <
class Elem,
int CellSize>
98 if (std::is_trivially_copy_constructible<Elem>()) {
102 EnsureCapacity(b.Count());
104 for (
int i = 0; i < b.Count(); i++) {
111template <
class Elem,
int CellSize>
113 if (NValues != b.Count())
return false;
114 for(
int i=0;i<NValues;i++) {
115 if ((*
this)[i] != b[i])
return false;
120template <
class Elem,
int CellSize>
122 NValues = MaxCells = MaxValues = 0;
127template <
class Elem,
int CellSize>
130 int n=1+(N/CellSize);
133 MaxCells=std::max(MaxCells+512,n+1);
134 Elem** np=(Elem**)_ExMalloc(MaxCells*
sizeof(Elem*));
135 memset(np,0,MaxCells*
sizeof(Elem*));
137 memcpy(np,Values,n0*
sizeof(Elem*));
142 for(
int i=MaxValues/CellSize;i<n;i++){
143 Values[i]=(Elem*)_ExMalloc(CellSize*
sizeof(Elem));
145 MaxValues=n*CellSize;
149template <
class Elem,
int CellSize>
157template <
class Elem,
int CellSize>
166template <
class Elem,
int CellSize>
171template <
class Elem,
int CellSize>
173 EnsureCapacity(NValues+1);
174 int p1=NValues/CellSize;
175 Values[p1][NValues%CellSize]=V;
180template <
class Elem,
int CellSize>
183 for(
int i=0;i<NTimes;i++){
189template <
class Elem,
int CellSize>
190template <
class array>
193 for (
int i = 0; i < N; i++) {
198template <
class Elem,
int CellSize>
200 _strict_check(pos >= 0 && pos < NValues);
201 return Values[pos/CellSize][pos%CellSize];
204template <
class Elem,
int CellSize>
206 _strict_check(pos >= 0 && pos < NValues);
207 return Values[pos/CellSize][pos%CellSize];
210template <
class Elem,
int CellSize>
215template <
class Elem,
int CellSize>
218 if (std::is_compound<Elem>()) {
219 for (
int i = 0; i < NValues; i++) {
223 for(
int i=0;i<MaxCells;i++){
224 if(Values[i])_ExFree(Values[i]);
234template <
class Elem,
int CellSize>
239template <
class Elem,
int CellSize>
245 if (pos + num > NValues) {
249 for (
int p = pos + num; p < NValues; p++) {
250 (*this)[p - num] = (*this)[p];
255template <
class Elem,
int CellSize>
257 if (pos >= Count())Add(Default, pos - Count() + 1);
261template <
class Elem,
int CellSize>
263 if (pos < 0 || pos >= Count())
return Default;
267template <
class Elem,
int CellSize>
269 if ( pos >= Count() )Add( def, pos - Count() + 1 );
270 return (*
this)[ pos ];
273template <
class Elem,
int CellSize>
278template <
class Elem,
int CellSize>
283template <
class Elem,
int CellSize>
285 EnsureCapacity(NValues + Count);
286 int start = NValues - 1;
288 for (
int k = start; k >= Index; k--) {
289 (*this)[k + Count] = (*this)[k];
291 for(
int k=0;k<Count;k++) {
292 (*this)[k + Index] = Value;
296template <
class Elem,
int CellSize>
297template <
class array>
299 int ns = Src.Count();
302 for (
int i = 0; i < ns; i++) {
307template <
class Elem,
int CellSize>
308template <
class array>
310 int ns = Src.Count();
311 EnsureCapacity(ns + Count());
312 for(
int k=0;k<ns;k++) {
313 (*this)[NValues++] = Src[k];
317template <
class Elem,
int CellSize>
319 EnsureCapacity(Count);
323template <
class Elem,
int CellSize>
325 EnsureCapacity(Count);
327 for(
int i=0;i<Count;i++) {
332template <
class Elem,
int CellSize>
334 for (
int i = 0; i < NValues; i++)
if (e == (*
this)[i])
return i;
338template <
class Elem,
int CellSize>
340 if (NValues)NValues--;
343template <
class Elem,
int CellSize>
345 _strict_check(NValues > 0);
346 return (*
this)[NValues - 1];
349template <
class Elem,
int CellSize>
351 return (*
this)[NValues - 1];
354template <
class Elem,
int CellSize>
356 EnsureCapacity(src.Count());
357 NValues = src.Count();
358 for (
int k = 0, p = 0; k < NValues; k += CellSize, p++) {
359 int nel = std::min(CellSize, NValues - k);
360 memcpy(Values[p], src.Values[p], nel *
sizeof(Elem));
364template <
class Elem,
int CellSize>
366 for (
int k = 0, p = 0; k < NValues; k += CellSize, p++) {
367 int nel = std::min(CellSize, NValues - k);
368 memset(Values[p], 0, nel *
sizeof(Elem));
372template <
class Elem,
int CellSize>
374 for(
int i=0,j=NValues-1;i<j;i++,j--) {
375 std::swap((*
this)[i], (*
this)[j]);
379template <
class Elem,
int CellSize>
380template <
class Reader>
386 int sz = Count() - i;
387 if (sz > CellSize)sz = CellSize;
388 if (sz > 0)BS.Read(Values[i/CellSize], sz *
sizeof(Elem));
395template <
class Elem,
int CellSize>
396template <
class Writer>
399 int sz = Count() - i;
400 if (sz > CellSize)sz = CellSize;
401 if (sz > 0)BS.Write(Values[i/CellSize], sz *
sizeof(Elem));
407template <
class Elem,
int CellSize>
410 to.NValues = NValues;
412 to.MaxValues = MaxValues;
413 to.MaxCells = MaxCells;
414 NValues = MaxCells = MaxValues = 0;
Definition bigdynarray.h:17
Definition bigdynarray.h:66