Annotation of parser3/src/include/pa_array.h, revision 1.10

1.1       paf         1: /*
1.10    ! paf         2:   $Id: pa_array.h,v 1.7 2001/01/29 15:56:03 paf Exp $
1.1       paf         3: */
                      4: 
                      5: /*
                      6: 
                      7:        Array               Chunk0
                      8:        ======              ========
                      9:        head--------------->[ptr]
                     10:        append_here-------->[ptr]
                     11:        link_row            ........
                     12:                        .                       .
                     13:                        .                       [ptr]
                     14:                        ...........>[link to the next chunk]
                     15: 
                     16: */
                     17: 
                     18: #ifndef PA_ARRAY_H
                     19: #define PA_ARRAY_H
                     20: 
                     21: #include <stddef.h>
                     22: 
                     23: #include "pa_types.h"
                     24: 
                     25: class Pool;
                     26: 
1.10    ! paf        27: class Array {
1.1       paf        28: public:
1.7       paf        29: 
1.10    ! paf        30:        typedef void *Item;
        !            31: 
1.1       paf        32:        enum {
1.7       paf        33:                CR_INITIAL_ROWS_DEFAULT=10,
1.1       paf        34:                CR_GROW_PERCENT=60
                     35:        };
                     36: 
1.6       paf        37: public:
                     38: 
1.7       paf        39:        void *operator new(size_t size, Pool *apool);
                     40:        Array(Pool *apool, int initial_rows=CR_INITIAL_ROWS_DEFAULT);
                     41: 
1.6       paf        42:        int size() { return fused_rows; }
                     43:        Array& operator += (Item src);
1.7       paf        44:        Array& operator += (Array& src);
1.6       paf        45:        Item& operator [] (int index);
                     46: 
1.7       paf        47: protected:
1.1       paf        48: 
                     49:        // the pool I'm allocated on
                     50:        Pool *pool;
                     51: 
1.7       paf        52: private:
                     53: 
1.1       paf        54:        struct Chunk {
                     55:                // the number of rows in chunk
                     56:                int count;
                     57:                union Row {
                     58:                        Item item;
                     59:                        Chunk *link;  // link to the next chunk in chain
                     60:                } rows[1];
                     61:                // next rows are here
                     62:        }
                     63:                *head;  // the head chunk of the chunk chain
                     64: 
1.5       paf        65:        // last allocated chunk
                     66:        // helps appending Arrays
                     67:        Chunk *tail;
                     68: 
1.1       paf        69:        // next append would write to this record
                     70:        Chunk::Row *append_here;
                     71:        
                     72:        // the address of place where lies address 
                     73:        // of the link to the next chunk to allocate
                     74:        Chunk::Row *link_row;
                     75: 
                     76: private:
1.7       paf        77: 
1.1       paf        78:        // array size
                     79:        int fused_rows;
                     80: 
1.3       paf        81:        int cache_chunk_base;
                     82:        Chunk *cache_chunk;
1.2       paf        83:        
1.1       paf        84: private:
                     85: 
                     86:        bool chunk_is_full() {
                     87:                return append_here == link_row;
                     88:        }
1.5       paf        89:        void expand(int chunk_rows);
1.2       paf        90: 
1.1       paf        91: private: //disabled
                     92: 
1.7       paf        93:        Array(Array&) {}
                     94:        Array& operator = (Array&) { return *this; }
1.1       paf        95: };
                     96: 
                     97: #endif

E-mail: