--- parser3/src/include/pa_array.h 2001/01/27 15:21:05 1.2 +++ parser3/src/include/pa_array.h 2001/01/29 15:56:03 1.7 @@ -1,5 +1,5 @@ /* - $Id: pa_array.h,v 1.2 2001/01/27 15:21:05 paf Exp $ + $Id: pa_array.h,v 1.7 2001/01/29 15:56:03 paf Exp $ */ /* @@ -26,19 +26,31 @@ class Pool; class Array { public: + typedef void *Item; enum { - CR_PREALLOCATED_COUNT=10, + CR_INITIAL_ROWS_DEFAULT=10, CR_GROW_PERCENT=60 }; -private: - friend Pool; +public: + + void *operator new(size_t size, Pool *apool); + Array(Pool *apool, int initial_rows=CR_INITIAL_ROWS_DEFAULT); + + int size() { return fused_rows; } + Array& operator += (Item src); + Array& operator += (Array& src); + Item& operator [] (int index); + +protected: // the pool I'm allocated on Pool *pool; +private: + struct Chunk { // the number of rows in chunk int count; @@ -50,6 +62,10 @@ private: } *head; // the head chunk of the chunk chain + // last allocated chunk + // helps appending Arrays + Chunk *tail; + // next append would write to this record Chunk::Row *append_here; @@ -58,50 +74,24 @@ private: Chunk::Row *link_row; private: - // last chank allocated count - int curr_chunk_rows; // array size int fused_rows; - int cache_index; - Chunk::Row *cache_row; - int cache_countdown; - Chunk::Row *cache_link_row; + int cache_chunk_base; + Chunk *cache_chunk; private: - // new&constructors made private to enforce factory manufacturing at pool - void *operator new(size_t size, Pool *apool); - - void construct(Pool *apool, int initial_rows); - Array(Pool *apool) { - construct(apool, CR_PREALLOCATED_COUNT); - } - Array(Pool *apool, int initial_rows) { - construct(apool, initial_rows); - } - bool chunk_is_full() { return append_here == link_row; } - void expand(); - -public: - - int size() { return fused_rows; } - Array& operator += (Item src); - - /* - void put(int index, Item item); - Item get(int index); - */ - Item& operator [] (int index); + void expand(int chunk_rows); private: //disabled - Array& operator = (Array& src) { return *this; } - Array(Array& src) {} + Array(Array&) {} + Array& operator = (Array&) { return *this; } }; #endif