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);
74 bool operator != (
const iterator& itr)
const {
75 return pos != itr.pos;
81 return &(*array)[pos];
88 return iterator(NValues,
this);
94template <
class Elem,
int CellSize>
97 if (std::is_trivially_copy_constructible<Elem>()) {
101 EnsureCapacity(b.Count());
103 for (
int i = 0; i < b.Count(); i++) {
110template <
class Elem,
int CellSize>
112 if (NValues != b.Count())
return false;
113 for(
int i=0;i<NValues;i++) {
114 if ((*
this)[i] != b[i])
return false;
119template <
class Elem,
int CellSize>
121 NValues = MaxCells = MaxValues = 0;
126template <
class Elem,
int CellSize>
129 int n=1+(N/CellSize);
132 MaxCells=std::max(MaxCells+512,n+1);
133 Elem** np=(Elem**)_ExMalloc(MaxCells*
sizeof(Elem*));
134 memset(np,0,MaxCells*
sizeof(Elem*));
136 memcpy(np,Values,n0*
sizeof(Elem*));
141 for(
int i=MaxValues/CellSize;i<n;i++){
142 Values[i]=(Elem*)_ExMalloc(CellSize*
sizeof(Elem));
144 MaxValues=n*CellSize;
148template <
class Elem,
int CellSize>
156template <
class Elem,
int CellSize>
165template <
class Elem,
int CellSize>
170template <
class Elem,
int CellSize>
172 EnsureCapacity(NValues+1);
173 int p1=NValues/CellSize;
174 Values[p1][NValues%CellSize]=V;
179template <
class Elem,
int CellSize>
182 for(
int i=0;i<NTimes;i++){
188template <
class Elem,
int CellSize>
189template <
class array>
192 for (
int i = 0; i < N; i++) {
197template <
class Elem,
int CellSize>
199 _strict_check(pos >= 0 && pos < NValues);
200 return Values[pos/CellSize][pos%CellSize];
203template <
class Elem,
int CellSize>
205 _strict_check(pos >= 0 && pos < NValues);
206 return Values[pos/CellSize][pos%CellSize];
209template <
class Elem,
int CellSize>
214template <
class Elem,
int CellSize>
217 if (std::is_compound<Elem>()) {
218 for (
int i = 0; i < NValues; i++) {
222 for(
int i=0;i<MaxCells;i++){
223 if(Values[i])_ExFree(Values[i]);
233template <
class Elem,
int CellSize>
238template <
class Elem,
int CellSize>
244 if (pos + num > NValues) {
248 for (
int p = pos + num; p < NValues; p++) {
249 (*this)[p - num] = (*this)[p];
254template <
class Elem,
int CellSize>
256 if (pos >= Count())Add(Default, pos - Count() + 1);
260template <
class Elem,
int CellSize>
262 if (pos < 0 || pos >= Count())
return Default;
266template <
class Elem,
int CellSize>
268 if ( pos >= Count() )Add( def, pos - Count() + 1 );
269 return (*
this)[ pos ];
272template <
class Elem,
int CellSize>
277template <
class Elem,
int CellSize>
282template <
class Elem,
int CellSize>
284 EnsureCapacity(NValues + Count);
285 int start = NValues - 1;
287 for (
int k = start; k >= Index; k--) {
288 (*this)[k + Count] = (*this)[k];
290 for(
int k=0;k<Count;k++) {
291 (*this)[k + Index] = Value;
295template <
class Elem,
int CellSize>
296template <
class array>
298 int ns = Src.Count();
301 for (
int i = 0; i < ns; i++) {
306template <
class Elem,
int CellSize>
307template <
class array>
309 int ns = Src.Count();
310 EnsureCapacity(ns + Count());
311 for(
int k=0;k<ns;k++) {
312 (*this)[NValues++] = Src[k];
316template <
class Elem,
int CellSize>
318 EnsureCapacity(Count);
322template <
class Elem,
int CellSize>
324 EnsureCapacity(Count);
326 for(
int i=0;i<Count;i++) {
331template <
class Elem,
int CellSize>
333 for (
int i = 0; i < NValues; i++)
if (e == (*
this)[i])
return i;
337template <
class Elem,
int CellSize>
339 if (NValues)NValues--;
342template <
class Elem,
int CellSize>
344 _strict_check(NValues > 0);
345 return (*
this)[NValues - 1];
348template <
class Elem,
int CellSize>
350 return (*
this)[NValues - 1];
353template <
class Elem,
int CellSize>
355 EnsureCapacity(src.Count());
356 NValues = src.Count();
357 for (
int k = 0, p = 0; k < NValues; k += CellSize, p++) {
358 int nel = std::min(CellSize, NValues - k);
359 memcpy(Values[p], src.Values[p], nel *
sizeof(Elem));
363template <
class Elem,
int CellSize>
365 for (
int k = 0, p = 0; k < NValues; k += CellSize, p++) {
366 int nel = std::min(CellSize, NValues - k);
367 memset(Values[p], 0, nel *
sizeof(Elem));
371template <
class Elem,
int CellSize>
373 for(
int i=0,j=NValues-1;i<j;i++,j--) {
374 std::swap((*
this)[i], (*
this)[j]);
378template <
class Elem,
int CellSize>
379template <
class Reader>
385 int sz = Count() - i;
386 if (sz > CellSize)sz = CellSize;
387 if (sz > 0)BS.Read(Values[i/CellSize], sz *
sizeof(Elem));
394template <
class Elem,
int CellSize>
395template <
class Writer>
398 int sz = Count() - i;
399 if (sz > CellSize)sz = CellSize;
400 if (sz > 0)BS.Write(Values[i/CellSize], sz *
sizeof(Elem));
Definition bigdynarray.h:17
Definition bigdynarray.h:65