annotate src/share/vm/utilities/array.hpp @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents ad8c8ca4ab0f
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 470
diff changeset
2 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 470
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 470
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 470
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // correct linkage required to compile w/o warnings
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // (must be on file level - cannot be local)
a61af66fc99e Initial load
duke
parents:
diff changeset
27 extern "C" { typedef int (*ftype)(const void*, const void*); }
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 class ResourceArray: public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
31 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
32 int _length; // the number of array elements
a61af66fc99e Initial load
duke
parents:
diff changeset
33 void* _data; // the array memory
a61af66fc99e Initial load
duke
parents:
diff changeset
34 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
35 int _nesting; // the resource area nesting level
a61af66fc99e Initial load
duke
parents:
diff changeset
36 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // creation
a61af66fc99e Initial load
duke
parents:
diff changeset
39 ResourceArray() {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 _length = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 _data = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 DEBUG_ONLY(init_nesting();)
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
43 // client may call initialize, at most once
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 ResourceArray(size_t esize, int length) {
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
48 DEBUG_ONLY(_data = NULL);
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
49 initialize(esize, length);
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
50 }
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
51
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
52 void initialize(size_t esize, int length) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
53 assert(length >= 0, "illegal length");
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
54 assert(_data == NULL, "must be new object");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
55 _length = length;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 _data = resource_allocate_bytes(esize * length);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 DEBUG_ONLY(init_nesting();)
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
61 void init_nesting();
a61af66fc99e Initial load
duke
parents:
diff changeset
62 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // helper functions
a61af66fc99e Initial load
duke
parents:
diff changeset
65 void sort (size_t esize, ftype f); // sort the array
a61af66fc99e Initial load
duke
parents:
diff changeset
66 void expand (size_t esize, int i, int& size);// expand the array to include slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
67 void remove_at(size_t esize, int i); // remove the element in slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // standard operations
a61af66fc99e Initial load
duke
parents:
diff changeset
71 int length() const { return _length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 bool is_empty() const { return length() == 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 };
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 class CHeapArray: public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
78 int _length; // the number of array elements
a61af66fc99e Initial load
duke
parents:
diff changeset
79 void* _data; // the array memory
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // creation
a61af66fc99e Initial load
duke
parents:
diff changeset
82 CHeapArray() {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 _length = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 _data = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 CHeapArray(size_t esize, int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 assert(length >= 0, "illegal length");
a61af66fc99e Initial load
duke
parents:
diff changeset
90 _length = length;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _data = (void*) NEW_C_HEAP_ARRAY(char *, esize * length);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
95 void init_nesting();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // helper functions
a61af66fc99e Initial load
duke
parents:
diff changeset
99 void sort (size_t esize, ftype f); // sort the array
a61af66fc99e Initial load
duke
parents:
diff changeset
100 void expand (size_t esize, int i, int& size);// expand the array to include slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
101 void remove_at(size_t esize, int i); // remove the element in slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // standard operations
a61af66fc99e Initial load
duke
parents:
diff changeset
105 int length() const { return _length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 bool is_empty() const { return length() == 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 };
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 #define define_generic_array(array_name,element_type, base_class) \
a61af66fc99e Initial load
duke
parents:
diff changeset
110 class array_name: public base_class { \
a61af66fc99e Initial load
duke
parents:
diff changeset
111 protected: \
a61af66fc99e Initial load
duke
parents:
diff changeset
112 typedef element_type etype; \
a61af66fc99e Initial load
duke
parents:
diff changeset
113 enum { esize = sizeof(etype) }; \
a61af66fc99e Initial load
duke
parents:
diff changeset
114 \
a61af66fc99e Initial load
duke
parents:
diff changeset
115 void base_remove_at(size_t size, int i) { base_class::remove_at(size, i); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
116 \
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public: \
a61af66fc99e Initial load
duke
parents:
diff changeset
118 /* creation */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
119 array_name() : base_class() {} \
a61af66fc99e Initial load
duke
parents:
diff changeset
120 array_name(const int length) : base_class(esize, length) {} \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
121 array_name(const int length, const etype fx) { initialize(length, fx); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
122 void initialize(const int length) { base_class::initialize(esize, length); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
123 void initialize(const int length, const etype fx) { \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
124 initialize(length); \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
125 for (int i = 0; i < length; i++) ((etype*)_data)[i] = fx; \
a61af66fc99e Initial load
duke
parents:
diff changeset
126 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
127 \
a61af66fc99e Initial load
duke
parents:
diff changeset
128 /* standard operations */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
129 etype& operator [] (const int i) const { \
a61af66fc99e Initial load
duke
parents:
diff changeset
130 assert(0 <= i && i < length(), "index out of bounds"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return ((etype*)_data)[i]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
132 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
133 \
a61af66fc99e Initial load
duke
parents:
diff changeset
134 int index_of(const etype x) const { \
a61af66fc99e Initial load
duke
parents:
diff changeset
135 int i = length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
136 while (i-- > 0 && ((etype*)_data)[i] != x) ; \
a61af66fc99e Initial load
duke
parents:
diff changeset
137 /* i < 0 || ((etype*)_data)_data[i] == x */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return i; \
a61af66fc99e Initial load
duke
parents:
diff changeset
139 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
140 \
a61af66fc99e Initial load
duke
parents:
diff changeset
141 void sort(int f(etype*, etype*)) { base_class::sort(esize, (ftype)f); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
142 bool contains(const etype x) const { return index_of(x) >= 0; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
143 \
a61af66fc99e Initial load
duke
parents:
diff changeset
144 /* deprecated operations - for compatibility with GrowableArray only */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
145 etype at(const int i) const { return (*this)[i]; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
146 void at_put(const int i, const etype x) { (*this)[i] = x; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
147 etype* adr_at(const int i) { return &(*this)[i]; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
148 int find(const etype x) { return index_of(x); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }; \
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 #define define_array(array_name,element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
153 define_generic_array(array_name, element_type, ResourceArray)
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 #define define_stack(stack_name,array_name) \
a61af66fc99e Initial load
duke
parents:
diff changeset
157 class stack_name: public array_name { \
a61af66fc99e Initial load
duke
parents:
diff changeset
158 protected: \
a61af66fc99e Initial load
duke
parents:
diff changeset
159 int _size; \
a61af66fc99e Initial load
duke
parents:
diff changeset
160 \
a61af66fc99e Initial load
duke
parents:
diff changeset
161 void grow(const int i, const etype fx) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
162 assert(i >= length(), "index too small"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
163 if (i >= size()) expand(esize, i, _size); \
a61af66fc99e Initial load
duke
parents:
diff changeset
164 for (int j = length(); j <= i; j++) ((etype*)_data)[j] = fx; \
a61af66fc99e Initial load
duke
parents:
diff changeset
165 _length = i+1; \
a61af66fc99e Initial load
duke
parents:
diff changeset
166 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
167 \
a61af66fc99e Initial load
duke
parents:
diff changeset
168 public: \
a61af66fc99e Initial load
duke
parents:
diff changeset
169 /* creation */ \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
170 stack_name() : array_name() { _size = 0; } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
171 stack_name(const int size) { initialize(size); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
172 stack_name(const int size, const etype fx) { initialize(size, fx); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
173 void initialize(const int size, const etype fx) { \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
174 _size = size; \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
175 array_name::initialize(size, fx); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
176 /* _length == size, allocation and size are the same */ \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
177 } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
178 void initialize(const int size) { \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
179 _size = size; \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
180 array_name::initialize(size); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
181 _length = 0; /* reset length to zero; _size records the allocation */ \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
182 } \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
183 \
a61af66fc99e Initial load
duke
parents:
diff changeset
184 /* standard operations */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
185 int size() const { return _size; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
186 \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
187 int push(const etype x) { \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
188 int len = length(); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
189 if (len >= size()) expand(esize, len, _size); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
190 ((etype*)_data)[len] = x; \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
191 _length = len+1; \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
192 return len; \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
193 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
194 \
a61af66fc99e Initial load
duke
parents:
diff changeset
195 etype pop() { \
a61af66fc99e Initial load
duke
parents:
diff changeset
196 assert(!is_empty(), "stack is empty"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
197 return ((etype*)_data)[--_length]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
198 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
199 \
a61af66fc99e Initial load
duke
parents:
diff changeset
200 etype top() const { \
a61af66fc99e Initial load
duke
parents:
diff changeset
201 assert(!is_empty(), "stack is empty"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
202 return ((etype*)_data)[length() - 1]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
203 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
204 \
a61af66fc99e Initial load
duke
parents:
diff changeset
205 void push_all(const stack_name* stack) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
206 const int l = stack->length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
207 for (int i = 0; i < l; i++) push(((etype*)(stack->_data))[i]); \
a61af66fc99e Initial load
duke
parents:
diff changeset
208 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
209 \
a61af66fc99e Initial load
duke
parents:
diff changeset
210 etype at_grow(const int i, const etype fx) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
211 if (i >= length()) grow(i, fx); \
a61af66fc99e Initial load
duke
parents:
diff changeset
212 return ((etype*)_data)[i]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
213 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
214 \
a61af66fc99e Initial load
duke
parents:
diff changeset
215 void at_put_grow(const int i, const etype x, const etype fx) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
216 if (i >= length()) grow(i, fx); \
a61af66fc99e Initial load
duke
parents:
diff changeset
217 ((etype*)_data)[i] = x; \
a61af66fc99e Initial load
duke
parents:
diff changeset
218 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
219 \
a61af66fc99e Initial load
duke
parents:
diff changeset
220 void truncate(const int length) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
221 assert(0 <= length && length <= this->length(), "illegal length"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
222 _length = length; \
a61af66fc99e Initial load
duke
parents:
diff changeset
223 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
224 \
a61af66fc99e Initial load
duke
parents:
diff changeset
225 void remove_at(int i) { base_remove_at(esize, i); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
226 void remove(etype x) { remove_at(index_of(x)); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
227 \
a61af66fc99e Initial load
duke
parents:
diff changeset
228 /* inserts the given element before the element at index i */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
229 void insert_before(const int i, const etype el) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
230 int len = length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
231 int new_length = len + 1; \
a61af66fc99e Initial load
duke
parents:
diff changeset
232 if (new_length >= size()) expand(esize, new_length, _size); \
a61af66fc99e Initial load
duke
parents:
diff changeset
233 for (int j = len - 1; j >= i; j--) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
234 ((etype*)_data)[j + 1] = ((etype*)_data)[j]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
235 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
236 _length = new_length; \
a61af66fc99e Initial load
duke
parents:
diff changeset
237 at_put(i, el); \
a61af66fc99e Initial load
duke
parents:
diff changeset
238 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
239 \
a61af66fc99e Initial load
duke
parents:
diff changeset
240 /* inserts contents of the given stack before the element at index i */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
241 void insert_before(const int i, const stack_name *st) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
242 if (st->length() == 0) return; \
a61af66fc99e Initial load
duke
parents:
diff changeset
243 int len = length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
244 int st_len = st->length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
245 int new_length = len + st_len; \
a61af66fc99e Initial load
duke
parents:
diff changeset
246 if (new_length >= size()) expand(esize, new_length, _size); \
a61af66fc99e Initial load
duke
parents:
diff changeset
247 int j; \
a61af66fc99e Initial load
duke
parents:
diff changeset
248 for (j = len - 1; j >= i; j--) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
249 ((etype*)_data)[j + st_len] = ((etype*)_data)[j]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
250 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
251 for (j = 0; j < st_len; j++) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
252 ((etype*)_data)[i + j] = ((etype*)st->_data)[j]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
253 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
254 _length = new_length; \
a61af66fc99e Initial load
duke
parents:
diff changeset
255 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
256 \
a61af66fc99e Initial load
duke
parents:
diff changeset
257 /* deprecated operations - for compatibility with GrowableArray only */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
258 int capacity() const { return size(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
259 void clear() { truncate(0); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
260 void trunc_to(const int length) { truncate(length); } \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
261 int append(const etype x) { return push(x); } \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
262 void appendAll(const stack_name* stack) { push_all(stack); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
263 etype last() const { return top(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }; \
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 #define define_resource_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
268 define_generic_array(element_type##Array, element_type, ResourceArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
269 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 #define define_resource_pointer_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
272 define_generic_array(element_type##Array, element_type *, ResourceArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
273 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 #define define_c_heap_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
276 define_generic_array(element_type##Array, element_type, CHeapArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
277 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 #define define_c_heap_pointer_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
280 define_generic_array(element_type##Array, element_type *, CHeapArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
281 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // Arrays for basic types
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 define_array(boolArray, bool) define_stack(boolStack, boolArray)
a61af66fc99e Initial load
duke
parents:
diff changeset
287 define_array(intArray , int ) define_stack(intStack , intArray )