52 typedef value_type* pointer;
53 typedef value_type& reference;
54 typedef size_t size_type;
55 typedef ptrdiff_t difference_type;
56 typedef std::random_access_iterator_tag iterator_category;
58 # define DNAMPKS__ ((size_type(1) << pks) - 1)
65 { p = &da; in = ii; pT = p->pt_to(in); }
67 inline size_type index(
void)
const {
return in; }
71 if ((++in)&DNAMPKS__) pT++;
else pT=p->pt_to(in);
return tmp;
76 if ((in--)&DNAMPKS__) pT--;
else pT=p->pt_to(in);
return tmp;
80 {
if ((++in)&DNAMPKS__) pT++;
else pT=p->pt_to(in);
return *
this; }
83 {
if ((in--)&DNAMPKS__) pT--;
else pT=p->pt_to(in);
return *
this; }
86 { in += i; pT=p->pt_to(in);
return *
this; }
89 { in -= i; pT=p->pt_to(in);
return *
this; }
98 {
return difference_type(in - i.in); }
100 reference operator *()
const {
return (*pT); }
101 pointer operator ->()
const {
return pT; }
102 reference operator [](size_type ii)
const {
return (*p)[in+ii]; }
104 bool operator ==(
const dna_iterator &i)
const {
return (i.in==in);}
105 bool operator !=(
const dna_iterator &i)
const {
return (i.in!=in);}
106 bool operator < (
const dna_iterator &i)
const {
return ( in<i.in);}
111 typedef T value_type;
112 typedef const value_type* pointer;
113 typedef const value_type& reference;
114 typedef size_t size_type;
115 typedef ptrdiff_t difference_type;
116 typedef std::random_access_iterator_tag iterator_category;
118 # define DNAMPKS__ ((size_type(1) << pks) - 1)
125 { p = &da; in = ii; pT = p->pt_to(in); }
127 : p(it.p), in(it.in), pT(it.pT) {}
129 inline size_type index(
void)
const {
return in; }
132 if ((++in)&DNAMPKS__) pT++;
else pT=p->pt_to(in);
return tmp;
136 if ((in--)&DNAMPKS__) pT--;
else pT=p->pt_to(in);
return tmp;
139 {
if ((++in)&DNAMPKS__) pT++;
else pT=p->pt_to(in);
return *
this; }
141 {
if ((in--)&DNAMPKS__) pT--;
else pT=p->pt_to(in);
return *
this; }
143 { in += i; pT=p->pt_to(in);
return *
this; }
145 { in -= i; pT=p->pt_to(in);
return *
this; }
151 {
return difference_type(in - i.in); }
153 reference operator *()
const {
return (*pT); }
154 pointer operator ->()
const {
return pT; }
155 reference operator [](size_type ii)
const {
return (*p)[in+ii]; }
158 {
return (i.in == in); }
160 {
return (i.in != in); }
162 {
return (in < i.in); }
193 typedef T value_type;
194 typedef value_type* pointer;
195 typedef const value_type* const_pointer;
196 typedef value_type& reference;
197 typedef const value_type& const_reference;
198 typedef size_t size_type;
199 typedef ptrdiff_t difference_type;
200 typedef unsigned char pack_size_type;
201 typedef std::vector<std::unique_ptr<T[]>> pointer_array;
204 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
205 typedef std::reverse_iterator<iterator> reverse_iterator;
209 # define DNAMPKS__ ((size_type(1) << pks) - 1)
214 size_type last_accessed;
219 size_type
size(
void)
const {
return last_accessed; }
220 size_type capacity(
void)
const {
return last_ind; }
221 size_type max_size(
void)
const {
return (size_type(-1)) / 2; }
223 bool empty(
void)
const {
return last_accessed == 0; }
233 reverse_iterator rbegin(
void) {
return reverse_iterator(
end()); }
234 const_reverse_iterator rbegin(
void)
const
235 {
return const_reverse_iterator(
end()); }
236 reverse_iterator rend(
void) {
return reverse_iterator(
begin()); }
237 const_reverse_iterator rend(
void)
const
238 {
return const_reverse_iterator(
begin()); }
240 reference front(
void) {
return *
begin(); }
241 const_reference front(
void)
const {
return *
begin(); }
242 reference back(
void) {
return *(
end() - 1); }
243 const_reference back(
void)
const {
return *(
end() - 1); }
245 void swap(dynamic_array<T,pks> &da);
248 dynamic_array<T,pks> &operator =(
const dynamic_array<T,pks> &da);
253 { last_accessed = last_ind = 0; array.resize(8); ppks = 3; m_ppks = 7; }
258 dynamic_array(
const dynamic_array<T,pks> &da) { init(); *
this = da; }
259 dynamic_array(
void) { init(); }
261 inline pointer pt_to(size_type ii)
262 {
return (ii >=last_ind) ? NULL : &((array[ii>>pks])[ii&DNAMPKS__]); }
263 inline const_pointer pt_to(size_type ii)
const
264 {
return (ii >=last_ind) ? NULL : &((array[ii>>pks])[ii&DNAMPKS__]); }
270 void resize(size_type i) { (*this)[i-1]; }
274 return sizeof(pointer) * array.capacity()
279 void swap(size_type i1, size_type i2)
280 { std::swap((*
this)[i1], (*
this)[i2]); }
289 template<
class T,
unsigned char pks>
290 void dynamic_array<T,pks>::swap(dynamic_array<T,pks> &da) {
291 array.swap(da.array);
292 std::swap(last_ind, da.last_ind);
293 std::swap(last_accessed, da.last_accessed);
294 std::swap(ppks, da.ppks); std::swap(m_ppks, da.m_ppks);
297 template<
class T,
unsigned char pks>
302 array.clear(); init();
307 array.resize(da.array.size());
308 last_ind = da.last_ind;
309 last_accessed = da.last_accessed;
310 ppks = da.ppks; m_ppks = da.m_ppks;
311 typename pointer_array::iterator it = array.begin();
312 typename pointer_array::const_iterator ita = da.array.begin();
313 typename pointer_array::iterator ite = it+ ((last_ind + DNAMPKS__) >> pks);
315 *it = std::unique_ptr<T[]>(
new T[DNAMPKS__+1]);
316 pointer p = it->get(); ++it;
317 pointer pe = p + (DNAMPKS__+1);
318 const_pointer pa = (ita++)->get();
319 while (p != pe) *p++ = *pa++;
324 template<
class T,
unsigned char pks>
325 typename dynamic_array<T,pks>::const_reference
327 THREAD_SAFE_STATIC T f;
328 return (ii<last_ind) ? (array[ii>>pks])[ii&DNAMPKS__] : f;
331 template<
class T,
unsigned char pks>
typename dynamic_array<T,pks>::reference
333 if (ii >= last_accessed) {
334 GMM_ASSERT2(ii < INT_MAX,
"out of range");
336 last_accessed = ii + 1;
337 if (ii >= last_ind) {
338 if ((ii >> (pks+ppks)) > 0) {
339 while ((ii >> (pks+ppks)) > 0) ppks++;
340 array.resize(m_ppks = (
size_type(1) << ppks)); m_ppks--;
342 for (size_type jj = (last_ind >> pks); ii >= last_ind;
343 jj++, last_ind += (DNAMPKS__ + 1)){
344 array[jj] = std::unique_ptr<T[]>(
new T[DNAMPKS__+1]);
348 return (array[ii >> pks])[ii & DNAMPKS__];
356 template<
class T,
unsigned char pks>
361 typename dynamic_array<T,pks>::size_type d = std::min(itxe-itxb,itye-ityb);
364 if (!std::equal(itxb, itxc, ityb))
return false;
365 for (; itxc != itxe; itxc++)
if (*itxc != T())
return false;
366 for (; ityc != itye; ityc++)
if (*ityc != T())
return false;
370 template<
class T,
unsigned char pks>
371 bool operator < (
const dynamic_array<T,pks> &x,
372 const dynamic_array<T,pks> &y)
373 {
return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()); }
375 template<
class T,
unsigned char pks>
inline
376 void swap(
const dynamic_array<T,pks> &x,
const dynamic_array<T,pks> &y)