Annotation of parser3/src/main/pa_array.C, revision 1.2

1.1       paf         1: /*
1.2     ! paf         2:   $Id: pa_array.C,v 1.1 2001/01/27 15:00:04 paf Exp $
1.1       paf         3: */
                      4: 
                      5: #include <string.h>
                      6: 
                      7: #include "pa_pool.h"
                      8: 
                      9: void *Array::operator new(size_t size, Pool *apool) {
                     10:        return apool->malloc(size);
                     11: }
                     12: 
                     13: void Array::construct(Pool *apool, int initial_rows) {
                     14:        pool=apool;
                     15:        curr_chunk_rows=initial_rows;
                     16:        head=static_cast<Chunk *>(
                     17:                pool->malloc(sizeof(int)+sizeof(Chunk::Row)*curr_chunk_rows+sizeof(Chunk *)));
                     18:        append_here=head->rows;
                     19:        link_row=&head->rows[curr_chunk_rows];
                     20:        link_row->link=0;
                     21:        fused_rows=0;
1.2     ! paf        22: 
        !            23:        cache_index=0;
        !            24:        cache_row=0;
        !            25:        cache_countdown=curr_chunk_rows;
        !            26:        cache_link_row=link_row;
1.1       paf        27: }
                     28: 
                     29: void Array::expand() {
                     30:        curr_chunk_rows+=curr_chunk_rows*CR_GROW_PERCENT/100;
                     31:        Chunk *chunk=static_cast<Chunk *>(
                     32:                pool->malloc(sizeof(int)+sizeof(Chunk::Row)*curr_chunk_rows+sizeof(Chunk *)));
                     33:        chunk->count=curr_chunk_rows;
                     34:        link_row->link=chunk;
                     35:        append_here=chunk->rows;
                     36:        link_row=&chunk->rows[curr_chunk_rows];
                     37:        link_row->link=0;
                     38: }
                     39: 
                     40: 
                     41: Array& Array::operator += (Item src) {
                     42:        if(chunk_is_full())
                     43:                expand();
                     44: 
                     45:        append_here->item=src;
                     46:        append_here++; fused_rows++;
                     47: 
                     48:        return *this;
                     49: }
                     50: 
                     51: /*
                     52: char *Array::c_str() {
                     53:        char *result=static_cast<char *>(pool->malloc(size()+1));
                     54: 
                     55:        char *copy_here=result;
                     56:        Chunk *chunk=&head; 
                     57:        do {
                     58:                Chunk::Row *row=chunk->rows;
                     59:                for(int i=0; i<chunk->count; i++) {
                     60:                        if(row==append_here)
                     61:                                goto break2;
                     62: 
                     63:                        memcpy(copy_here, row->item.ptr, row->item.size);
                     64:                        copy_here+=row->item.size;
                     65:                        row++;
                     66:                }
                     67:                chunk=row->link;
                     68:        } while(chunk);
                     69: break2:
                     70:        *copy_here=0;
                     71:        return result;
                     72: }
1.2     ! paf        73: */
        !            74: /*
        !            75: void Array::put(int index, Item item) {
        !            76: }
        !            77: 
        !            78: Array::Item Array::get(int index) {
        !            79: }
        !            80: */
        !            81: 
        !            82: Array::Item& Array::operator [] (int index) {
        !            83:        // we have cached row&index?
        !            84:        if(index>=cache_index && index<cache_index+cache_countdown) {
        !            85:        }
        !            86: 
        !            87:        int cache_index;
        !            88:        Chunk::Row *cache_row;
        !            89:        int cache_countdown;
        !            90:        Chunk::Row *cache_link_row;
        !            91:        
        !            92:        return 0;
        !            93: }

E-mail: