Annotation of parser3/src/include/pa_array.h, revision 1.2
1.1 paf 1: /*
1.2 ! paf 2: $Id: pa_array.h,v 1.1 2001/01/27 15:00:04 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:
27: class Array {
28: public:
29: typedef void *Item;
30:
31: enum {
32: CR_PREALLOCATED_COUNT=10,
33: CR_GROW_PERCENT=60
34: };
35:
36: private:
37: friend Pool;
38:
39: // the pool I'm allocated on
40: Pool *pool;
41:
42: struct Chunk {
43: // the number of rows in chunk
44: int count;
45: union Row {
46: Item item;
47: Chunk *link; // link to the next chunk in chain
48: } rows[1];
49: // next rows are here
50: }
51: *head; // the head chunk of the chunk chain
52:
53: // next append would write to this record
54: Chunk::Row *append_here;
55:
56: // the address of place where lies address
57: // of the link to the next chunk to allocate
58: Chunk::Row *link_row;
59:
60: private:
61: // last chank allocated count
62: int curr_chunk_rows;
63:
64: // array size
65: int fused_rows;
66:
1.2 ! paf 67: int cache_index;
! 68: Chunk::Row *cache_row;
! 69: int cache_countdown;
! 70: Chunk::Row *cache_link_row;
! 71:
1.1 paf 72: private:
73: // new&constructors made private to enforce factory manufacturing at pool
74: void *operator new(size_t size, Pool *apool);
75:
76: void construct(Pool *apool, int initial_rows);
77: Array(Pool *apool) {
78: construct(apool, CR_PREALLOCATED_COUNT);
79: }
80: Array(Pool *apool, int initial_rows) {
81: construct(apool, initial_rows);
82: }
83:
84:
85: bool chunk_is_full() {
86: return append_here == link_row;
87: }
88: void expand();
89:
1.2 ! paf 90: public:
! 91:
! 92: int size() { return fused_rows; }
! 93: Array& operator += (Item src);
! 94:
! 95: /*
! 96: void put(int index, Item item);
! 97: Item get(int index);
! 98: */
! 99: Item& operator [] (int index);
! 100:
1.1 paf 101: private: //disabled
102:
103: Array& operator = (Array& src) { return *this; }
104: Array(Array& src) {}
105: };
106:
107: #endif
E-mail: