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; }
225 iterator
begin(
void) {
return iterator(*
this, 0); }
227 const_iterator
begin(
void)
const {
return const_iterator(*
this, 0); }
229 iterator
end(
void) {
return iterator(*
this, size()); }
231 const_iterator
end(
void)
const 232 {
return const_iterator(*
this, size()); }
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); }
253 { last_accessed = last_ind = 0; array.resize(8); ppks = 3; m_ppks = 7; }
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__]); }
267 const_reference operator [](size_type ii)
const;
269 reference operator [](size_type ii);
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>
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 register pointer p = it->get(); ++it;
317 register pointer pe = p + (DNAMPKS__+1);
318 register 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 DEFINE_STATIC_THREAD_LOCAL_INITIALIZED(std::shared_ptr<T>,pf,NULL);
328 if (pf.get() == NULL) { pf = std::make_shared<T>(); }
329 return (ii<last_ind) ? (array[ii>>pks])[ii&DNAMPKS__] : *pf;
332 template<
class T,
unsigned char pks>
typename dynamic_array<T,pks>::reference
334 if (ii >= last_accessed) {
335 GMM_ASSERT2(ii < INT_MAX,
"out of range");
337 last_accessed = ii + 1;
338 if (ii >= last_ind) {
339 if ((ii >> (pks+ppks)) > 0) {
340 while ((ii >> (pks+ppks)) > 0) ppks++;
341 array.resize(m_ppks = (size_type(1) << ppks)); m_ppks--;
343 for (size_type jj = (last_ind >> pks); ii >= last_ind;
344 jj++, last_ind += (DNAMPKS__ + 1))
345 { 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,
373 {
return std::lexicographical_compare(x.begin(),x.end(),y.
begin(),y.
end()); }
375 template<
class T,
unsigned char pks>
inline bool empty(void) const
True if no space is allocated.
const_reference operator[](size_type ii) const
Gives a constant reference on element ii.
dna_iterator & operator-=(difference_type i)
go i elements backward.
Constant iterator class for dynamic array.
Iterator class for dynamic array.
dna_iterator operator+(difference_type i) const
gives an iterator pointing i elements forward.
Tools for multithreaded, OpenMP and Boost based parallelization.
void swap(size_type i1, size_type i2)
Swap element i1 and i2.
defines and typedefs for namespace dal
dna_iterator operator-(difference_type i) const
gives an iterator pointing i elements backward.
size_type memsize(void) const
Gives the total memory occupied by the array.
dna_iterator & operator--()
previous element.
size_type size(void) const
Number of allocated elements.
const_iterator end(void) const
Constant iterator on the last + 1 element.
iterator end(void)
Iterator on the last + 1 element.
dna_iterator & operator+=(difference_type i)
go i elements forward.
dna_iterator & operator++()
next element.
iterator begin(void)
Iterator on the first element.
void clear(void)
Clear and desallocate all the elements.
const_iterator begin(void) const
Constant iterator on the first element.