--- parser3/src/main/Attic/pa_array.C 2001/01/27 15:21:05 1.2 +++ parser3/src/main/Attic/pa_array.C 2001/01/29 09:38:33 1.4 @@ -1,5 +1,5 @@ /* - $Id: pa_array.C,v 1.2 2001/01/27 15:21:05 paf Exp $ + $Id: pa_array.C,v 1.4 2001/01/29 09:38:33 paf Exp $ */ #include @@ -15,15 +15,14 @@ void Array::construct(Pool *apool, int i curr_chunk_rows=initial_rows; head=static_cast( pool->malloc(sizeof(int)+sizeof(Chunk::Row)*curr_chunk_rows+sizeof(Chunk *))); + head->count=curr_chunk_rows; append_here=head->rows; link_row=&head->rows[curr_chunk_rows]; link_row->link=0; fused_rows=0; - cache_index=0; - cache_row=0; - cache_countdown=curr_chunk_rows; - cache_link_row=link_row; + cache_chunk_base=0; + cache_chunk=head; } void Array::expand() { @@ -48,46 +47,61 @@ Array& Array::operator += (Item src) { return *this; } -/* -char *Array::c_str() { - char *result=static_cast(pool->malloc(size()+1)); +Array::Item& Array::operator [] (int index) { + if(!(index>=0 && indexrows; - for(int i=0; icount; i++) { - if(row==append_here) - goto break2; - - memcpy(copy_here, row->item.ptr, row->item.size); - copy_here+=row->item.size; - row++; - } - chunk=row->link; - } while(chunk); -break2: - *copy_here=0; - return result; -} -*/ -/* -void Array::put(int index, Item item) { -} + // if they ask index to the left of cached position, forget cache + if(index=cache_chunk_base && indexcount)) { + int count=cache_chunk->count; + cache_chunk_base+=count; + cache_chunk=cache_chunk->rows[count].link; + } -Array::Item Array::get(int index) { + return cache_chunk->rows[index-cache_chunk_base].item; } -*/ -Array::Item& Array::operator [] (int index) { - // we have cached row&index? - if(index>=cache_index && indexcount; + Chunk *next_chunk=src_chunk->rows[src_count].link; + if(next_chunk) { + // not last source chunk + // taking it all + memcpy(dest_rows, src_chunk->rows, sizeof(Chunk::Row)*src_count); + dest_rows+=src_count; + rows_left_to_copy-=src_count; + + src_chunk=next_chunk; + } else { + // the last source chunk + // taking only those rows of chunk that _left_to_copy + memcpy(dest_rows, src_chunk->rows, sizeof(Chunk::Row)*rows_left_to_copy); + break; + } + } + } else { } - int cache_index; - Chunk::Row *cache_row; - int cache_countdown; - Chunk::Row *cache_link_row; - - return 0; -} \ No newline at end of file + return *this; +} + +void Array::remove(int index, int count=1) { +}