|
|
| version 1.95, 2024/09/21 23:51:04 | version 1.100, 2024/11/04 03:53:25 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: Array & Array_iterator classes decls. | Parser: Array & Array_iterator classes decls. |
| Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) |
| Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru> | Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru> |
| */ | */ |
| Line 108 public: | Line 108 public: |
| } | } |
| /// append other Array portion to this one. starting from offset | /// append other Array portion to this one. starting from offset |
| Array& append(const Array& src, | void append(const Array& src, size_t offset=0, size_t limit=ARRAY_OPTION_LIMIT_ALL) { //< zero limit means 'nothing' |
| size_t offset=0, | |
| size_t limit=ARRAY_OPTION_LIMIT_ALL) { //< zero limit means 'nothing' | |
| size_t src_count=src.count(); | size_t src_count=src.count(); |
| // skip tivials | // skip tivials |
| if(!src_count || !limit || offset>=src_count) | if(!src_count || !limit || offset>=src_count) |
| return *this; | return; |
| // max(limit) | // max(limit) |
| size_t m=src_count-offset; | size_t m=src_count-offset; |
| // fix limit | // fix limit |
| Line 123 public: | Line 120 public: |
| limit=m; | limit=m; |
| fit(fsize-1+limit); | fit(fsize-1+limit); |
| memcpy(felements+fsize, src.felements+offset, limit * sizeof(T)); | |
| T* from=&src.felements[offset]; | |
| T* to=&felements[fsize]; | |
| for(T* from_end=from+limit; from<from_end;) | |
| *to++=*from++; | |
| fsize+=limit; | fsize+=limit; |
| return *this; | |
| } | } |
| /// get index-element | /// get index-element |
| Line 221 protected: | Line 213 protected: |
| } | } |
| inline void expand() { | inline void expand() { |
| resize(fallocated>0 ? fallocated+fallocated/4+2 : 3); // 3 is PAF default, confirmed by tests | resize(fallocated>0 ? fallocated+fallocated/2+2 : 3); // 3 is PAF default, confirmed by tests |
| } | } |
| inline void fit(size_t index){ | inline void fit(size_t index){ |
| if(index >= fallocated) | if(index >= fallocated) |
| resize(max(this->fallocated + this->fallocated/4, index+1)); | resize(max(fallocated+fallocated/4, index+1)); |
| } | } |
| void resize(size_t asize) { | void resize(size_t asize) { |
| Line 259 template<typename T> char* pa_itoa(T n, | Line 251 template<typename T> char* pa_itoa(T n, |
| } | } |
| do { | do { |
| *(--pos)=(n % base) + '0'; | *(--pos)=(char)(n % base) + '0'; |
| n/=base; | n/=base; |
| } while (n > 0); | } while (n > 0); |
| Line 275 template<typename T> char* pa_uitoa(T n, | Line 267 template<typename T> char* pa_uitoa(T n, |
| *pos='\0'; | *pos='\0'; |
| do { | do { |
| *(--pos)=(n % base) + '0'; | *(--pos)=(char)(n % base) + '0'; |
| n/=base; | n/=base; |
| } while (n > 0); | } while (n > 0); |