--- parser3/src/main/Attic/pa_array.C 2001/02/22 15:17:40 1.18 +++ parser3/src/main/Attic/pa_array.C 2001/03/24 19:12:19 1.27 @@ -1,8 +1,14 @@ -/* - $Id: pa_array.C,v 1.18 2001/02/22 15:17:40 paf Exp $ +/** @file + Parser: array class. + + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + + Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: pa_array.C,v 1.27 2001/03/24 19:12:19 paf Exp $ */ -#include +#include "pa_config_includes.h" #include "pa_pool.h" #include "pa_array.h" @@ -23,6 +29,9 @@ Array::Array(Pool& apool, int initial_ro } void Array::expand(int chunk_rows) { + if(chunk_rows( malloc(sizeof(int)+sizeof(Chunk::Row)*chunk_rows+sizeof(Chunk *))); chunk->count=chunk_rows; @@ -117,10 +126,11 @@ Array& Array::append_array(const Array& if(rows_to_copy_now>0) memcpy(dest_rows, src_chunk->rows+rows_left_to_skip, sizeof(Chunk::Row)*rows_to_copy_now); + else + rows_left_to_skip-=src_count; + dest_rows+=rows_to_copy_now; rows_left_to_copy-=src_count; - rows_left_to_skip-=src_count; - src_chunk=next_chunk; } else { // the last source chunk @@ -137,3 +147,40 @@ Array& Array::append_array(const Array& return *this; } + +void Array::for_each(For_each_func func, void *info) { + Chunk *chunk=head; + while(true) { + if(chunk==tail) { // last chunk? + for(Chunk::Row *row=chunk->rows; row!=append_here; row++) + (*func)(row->item, info); + break; + } else { + int count=chunk->count; + for(int i=0; irows[i].item, info); + chunk=chunk->rows[count].link; + } + } +} + +Array::Item* Array::first_that(First_that_func func, const void *info) { + Chunk *chunk=head; + while(true) { + if(chunk==tail) { // last chunk? + for(Chunk::Row *row=chunk->rows; row!=append_here; row++) + if((*func)(row->item, info)) + return row->item; + break; + } else { + int count=chunk->count; + for(int i=0; irows[i].item; + if((*func)(item, info)) + return item; + } + chunk=chunk->rows[count].link; + } + } + return 0; +}