--- parser3/src/include/pa_array.h 2023/09/26 20:49:06 1.87 +++ parser3/src/include/pa_array.h 2024/09/07 16:30:26 1.89 @@ -8,7 +8,7 @@ #ifndef PA_ARRAY_H #define PA_ARRAY_H -#define IDENT_PA_ARRAY_H "$Id: pa_array.h,v 1.87 2023/09/26 20:49:06 moko Exp $" +#define IDENT_PA_ARRAY_H "$Id: pa_array.h,v 1.89 2024/09/07 16:30:26 moko Exp $" // includes @@ -40,6 +40,8 @@ protected: size_t fused; public: + typedef Array_iterator Iterator; + struct Action_options { size_t offset; size_t limit; //< ARRAY_OPTION_LIMIT_ALL means 'all'. zero limit means 'nothing' @@ -209,11 +211,26 @@ public: return felements + index; } + void fit(size_t index, T element){ + if(index >= fallocated){ + size_t new_allocated=fallocated>0 ? fallocated : 3; + while(new_allocated <= index){ + new_allocated+=2 + new_allocated/32; + } + expand(new_allocated - fallocated); + } + felements[index]=element; + if(index >= fused){ + fused=index+1; + } + } + protected: bool is_full() { return fused == fallocated; } + void expand(size_t delta) { if(fallocated){ size_t new_allocated=fallocated+delta; @@ -235,7 +252,7 @@ private: //disabled /** Array iterator, usage: @code // Array a; - for(Array_iterator i(a); i.has_next(); ) { + for(Array_iterator i(a); i; ) { T& element=i.next(); ... } @@ -255,14 +272,24 @@ public: } /// there are still elements - bool has_next() { + operator bool () { return fcurrent