aboutsummaryrefslogtreecommitdiff
path: root/docs/source_docs/files/bt_aligned_object_array_8h-source.html
blob: 40c69d13e5570e9abd13955237c162e40f33cfa5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
<html>
	<head>
		<title>NVIDIA(R) Blast(R) SDK 1.1 Source Reference: sdk/extensions/authoring/source/VHACD/inc/btAlignedObjectArray.h Source File</title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<LINK HREF="NVIDIA.css" REL="stylesheet" TYPE="text/css">
	</head>

	<body bgcolor="#FFFFFF">
		<div id="header">
			<hr class="first">
			<img alt="" src="blast_logo.png">
			<br>
			<center>
				<a class="qindex" href="main.html">Main Page</a> &nbsp; 
				<!-- <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; //-->
				<a class="qindex" href="annotated.html">Class List</a> &nbsp; 
				<a class="qindex" href="functions.html">Class Members</a> &nbsp;  
			</center>
			<hr class="second">
		</div>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>User's&nbsp;Guide</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>sdk/extensions/authoring/source/VHACD/inc/btAlignedObjectArray.h</h1><a href="bt_aligned_object_array_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">Bullet Continuous Collision Detection and Physics Library</span>
<a name="l00003"></a>00003 <span class="comment">Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">This software is provided 'as-is', without any express or implied warranty.</span>
<a name="l00006"></a>00006 <span class="comment">In no event will the authors be held liable for any damages arising from the use of this software.</span>
<a name="l00007"></a>00007 <span class="comment">Permission is granted to anyone to use this software for any purpose, </span>
<a name="l00008"></a>00008 <span class="comment">including commercial applications, and to alter it and redistribute it freely, </span>
<a name="l00009"></a>00009 <span class="comment">subject to the following restrictions:</span>
<a name="l00010"></a>00010 <span class="comment"></span>
<a name="l00011"></a>00011 <span class="comment">1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.</span>
<a name="l00012"></a>00012 <span class="comment">2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.</span>
<a name="l00013"></a>00013 <span class="comment">3. This notice may not be removed or altered from any source distribution.</span>
<a name="l00014"></a>00014 <span class="comment">*/</span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="preprocessor">#ifndef BT_OBJECT_ARRAY__</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span><span class="preprocessor">#define BT_OBJECT_ARRAY__</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span>
<a name="l00019"></a>00019 <span class="preprocessor">#include "<a class="code" href="bt_aligned_allocator_8h.html">btAlignedAllocator.h</a>"</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="bt_scalar_8h.html">btScalar.h</a>"</span> <span class="comment">// has definitions like SIMD_FORCE_INLINE</span>
<a name="l00021"></a>00021 
<a name="l00027"></a>00027 
<a name="l00028"></a><a class="code" href="bt_aligned_object_array_8h.html#bbaa34c72a791d366573e6e25e0bf702">00028</a> <span class="preprocessor">#define BT_USE_PLACEMENT_NEW 1</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">//#define BT_USE_MEMCPY 1 //disable, because it is cumbersome to find out for each platform where memcpy is defined. It can be in &lt;memory.h&gt; or &lt;string.h&gt; or otherwise...</span>
<a name="l00030"></a><a class="code" href="bt_aligned_object_array_8h.html#f679f7a130fd285561d684b76238ecd4">00030</a> <span class="preprocessor">#define BT_ALLOW_ARRAY_COPY_OPERATOR // enabling this can accidently perform deep copies of data if you are not careful</span>
<a name="l00031"></a>00031 <span class="preprocessor"></span>
<a name="l00032"></a>00032 <span class="preprocessor">#ifdef BT_USE_MEMCPY</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#include &lt;memory.h&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#endif //BT_USE_MEMCPY</span>
<a name="l00036"></a>00036 <span class="preprocessor"></span>
<a name="l00037"></a>00037 <span class="preprocessor">#ifdef BT_USE_PLACEMENT_NEW</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#include &lt;new&gt;</span> <span class="comment">//for placement new</span>
<a name="l00039"></a>00039 <span class="preprocessor">#endif //BT_USE_PLACEMENT_NEW</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span>
<a name="l00043"></a>00043 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00044"></a>00044 <span class="comment">//template &lt;class T&gt;</span>
<a name="l00045"></a><a class="code" href="classbt_aligned_object_array.html">00045</a> <span class="keyword">class </span><a class="code" href="classbt_aligned_object_array.html">btAlignedObjectArray</a> {
<a name="l00046"></a>00046     <a class="code" href="classbt_aligned_allocator.html">btAlignedAllocator&lt;T, 16&gt;</a> m_allocator;
<a name="l00047"></a>00047 
<a name="l00048"></a>00048     int32_t m_size;
<a name="l00049"></a>00049     int32_t m_capacity;
<a name="l00050"></a>00050     T* m_data;
<a name="l00051"></a>00051     <span class="comment">//PCK: added this line</span>
<a name="l00052"></a>00052     <span class="keywordtype">bool</span> m_ownsMemory;
<a name="l00053"></a>00053 
<a name="l00054"></a>00054 <span class="preprocessor">#ifdef BT_ALLOW_ARRAY_COPY_OPERATOR</span>
<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="keyword">public</span>:
<a name="l00056"></a><a class="code" href="classbt_aligned_object_array.html#b6ea335622f18386671194eb6bd6a41b">00056</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <a class="code" href="classbt_aligned_object_array.html">btAlignedObjectArray&lt;T&gt;</a>&amp; <a class="code" href="classbt_aligned_object_array.html#b6ea335622f18386671194eb6bd6a41b">operator=</a>(<span class="keyword">const</span> <a class="code" href="classbt_aligned_object_array.html">btAlignedObjectArray&lt;T&gt;</a>&amp; other)
<a name="l00057"></a>00057     {
<a name="l00058"></a>00058         <a class="code" href="classbt_aligned_object_array.html#1464bd66b0e5e3880b4c7aa4a2ce13a1">copyFromArray</a>(other);
<a name="l00059"></a>00059         <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00060"></a>00060     }
<a name="l00061"></a>00061 <span class="preprocessor">#else //BT_ALLOW_ARRAY_COPY_OPERATOR</span>
<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="keyword">private</span>:
<a name="l00063"></a>00063     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <a class="code" href="classbt_aligned_object_array.html">btAlignedObjectArray&lt;T&gt;</a>&amp; <a class="code" href="classbt_aligned_object_array.html#b6ea335622f18386671194eb6bd6a41b">operator=</a>(<span class="keyword">const</span> <a class="code" href="classbt_aligned_object_array.html">btAlignedObjectArray&lt;T&gt;</a>&amp; other);
<a name="l00064"></a>00064 <span class="preprocessor">#endif //BT_ALLOW_ARRAY_COPY_OPERATOR</span>
<a name="l00065"></a>00065 <span class="preprocessor"></span>
<a name="l00066"></a>00066 <span class="keyword">protected</span>:
<a name="l00067"></a><a class="code" href="classbt_aligned_object_array.html#a719fb250e71cf4c524fc10883d3f9cc">00067</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> int32_t <a class="code" href="classbt_aligned_object_array.html#a719fb250e71cf4c524fc10883d3f9cc">allocSize</a>(int32_t <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>)
<a name="l00068"></a>00068     {
<a name="l00069"></a>00069         <span class="keywordflow">return</span> (size ? size * 2 : 1);
<a name="l00070"></a>00070     }
<a name="l00071"></a><a class="code" href="classbt_aligned_object_array.html#edc2708d688e8cc816d97ecb05ace68f">00071</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#edc2708d688e8cc816d97ecb05ace68f">copy</a>(int32_t start, int32_t end, T* dest)<span class="keyword"> const</span>
<a name="l00072"></a>00072 <span class="keyword">    </span>{
<a name="l00073"></a>00073         int32_t i;
<a name="l00074"></a>00074         <span class="keywordflow">for</span> (i = start; i &lt; end; ++i)
<a name="l00075"></a>00075 #ifdef <a class="code" href="bt_aligned_object_array_8h.html#bbaa34c72a791d366573e6e25e0bf702">BT_USE_PLACEMENT_NEW</a>
<a name="l00076"></a>00076             <span class="keyword">new</span> (&amp;dest[i]) T(m_data[i]);
<a name="l00077"></a>00077 <span class="preprocessor">#else</span>
<a name="l00078"></a>00078 <span class="preprocessor"></span>            dest[i] = m_data[i];
<a name="l00079"></a>00079 <span class="preprocessor">#endif //BT_USE_PLACEMENT_NEW</span>
<a name="l00080"></a>00080 <span class="preprocessor"></span>    }
<a name="l00081"></a>00081 
<a name="l00082"></a><a class="code" href="classbt_aligned_object_array.html#336631607f9f5f08001866ed11b5fd64">00082</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#336631607f9f5f08001866ed11b5fd64">init</a>()
<a name="l00083"></a>00083     {
<a name="l00084"></a>00084         <span class="comment">//PCK: added this line</span>
<a name="l00085"></a>00085         m_ownsMemory = <span class="keyword">true</span>;
<a name="l00086"></a>00086         m_data = 0;
<a name="l00087"></a>00087         m_size = 0;
<a name="l00088"></a>00088         m_capacity = 0;
<a name="l00089"></a>00089     }
<a name="l00090"></a><a class="code" href="classbt_aligned_object_array.html#8ef274b9d73a61593c17b9b21442e0a7">00090</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#8ef274b9d73a61593c17b9b21442e0a7">destroy</a>(int32_t first, int32_t last)
<a name="l00091"></a>00091     {
<a name="l00092"></a>00092         int32_t i;
<a name="l00093"></a>00093         <span class="keywordflow">for</span> (i = first; i &lt; last; i++) {
<a name="l00094"></a>00094             m_data[i].~T();
<a name="l00095"></a>00095         }
<a name="l00096"></a>00096     }
<a name="l00097"></a>00097 
<a name="l00098"></a><a class="code" href="classbt_aligned_object_array.html#2302b4abe7664283231e150ecadc4576">00098</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keywordtype">void</span>* <a class="code" href="classbt_aligned_object_array.html#2302b4abe7664283231e150ecadc4576">allocate</a>(int32_t <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>)
<a name="l00099"></a>00099     {
<a name="l00100"></a>00100         <span class="keywordflow">if</span> (size)
<a name="l00101"></a>00101             <span class="keywordflow">return</span> m_allocator.<a class="code" href="classbt_aligned_allocator.html#5b14474126ff00cd364dfb74304ec6c3">allocate</a>(size);
<a name="l00102"></a>00102         <span class="keywordflow">return</span> 0;
<a name="l00103"></a>00103     }
<a name="l00104"></a>00104 
<a name="l00105"></a><a class="code" href="classbt_aligned_object_array.html#cebca91940aecdb1c11718bc08b511c9">00105</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#cebca91940aecdb1c11718bc08b511c9">deallocate</a>()
<a name="l00106"></a>00106     {
<a name="l00107"></a>00107         <span class="keywordflow">if</span> (m_data) {
<a name="l00108"></a>00108             <span class="comment">//PCK: enclosed the deallocation in this block</span>
<a name="l00109"></a>00109             <span class="keywordflow">if</span> (m_ownsMemory) {
<a name="l00110"></a>00110                 m_allocator.<a class="code" href="classbt_aligned_allocator.html#9aa2ce10c6b68eb249116f8712008724">deallocate</a>(m_data);
<a name="l00111"></a>00111             }
<a name="l00112"></a>00112             m_data = 0;
<a name="l00113"></a>00113         }
<a name="l00114"></a>00114     }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 <span class="keyword">public</span>:
<a name="l00117"></a><a class="code" href="classbt_aligned_object_array.html#d596d8e3e18bf81d9aa3fd21e57e5735">00117</a>     <a class="code" href="classbt_aligned_object_array.html#d596d8e3e18bf81d9aa3fd21e57e5735">btAlignedObjectArray</a>()
<a name="l00118"></a>00118     {
<a name="l00119"></a>00119         <a class="code" href="classbt_aligned_object_array.html#336631607f9f5f08001866ed11b5fd64">init</a>();
<a name="l00120"></a>00120     }
<a name="l00121"></a>00121 
<a name="l00122"></a><a class="code" href="classbt_aligned_object_array.html#2a7ab868dd49dcf6e2e711d19eac9e54">00122</a>     <a class="code" href="classbt_aligned_object_array.html#2a7ab868dd49dcf6e2e711d19eac9e54">~btAlignedObjectArray</a>()
<a name="l00123"></a>00123     {
<a name="l00124"></a>00124         <a class="code" href="classbt_aligned_object_array.html#12123db01dda7758f0df5e3bba10cc0a" title="clear the array, deallocated memory. Generally it is better to use array.resize(0)...">clear</a>();
<a name="l00125"></a>00125     }
<a name="l00126"></a>00126 
<a name="l00128"></a><a class="code" href="classbt_aligned_object_array.html#e91d1383db8069a02d23caf915bc2ce3">00128</a>     <a class="code" href="classbt_aligned_object_array.html#d596d8e3e18bf81d9aa3fd21e57e5735">btAlignedObjectArray</a>(<span class="keyword">const</span> <a class="code" href="classbt_aligned_object_array.html">btAlignedObjectArray</a>&amp; otherArray)
<a name="l00129"></a>00129     {
<a name="l00130"></a>00130         <a class="code" href="classbt_aligned_object_array.html#336631607f9f5f08001866ed11b5fd64">init</a>();
<a name="l00131"></a>00131 
<a name="l00132"></a>00132         int32_t otherSize = otherArray.<a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>();
<a name="l00133"></a>00133         <a class="code" href="classbt_aligned_object_array.html#cb69833ed110d6db213a71533a8c804a">resize</a>(otherSize);
<a name="l00134"></a>00134         otherArray.<a class="code" href="classbt_aligned_object_array.html#edc2708d688e8cc816d97ecb05ace68f">copy</a>(0, otherSize, m_data);
<a name="l00135"></a>00135     }
<a name="l00136"></a>00136 
<a name="l00138"></a><a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620">00138</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> int32_t <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>()<span class="keyword"> const</span>
<a name="l00139"></a>00139 <span class="keyword">    </span>{
<a name="l00140"></a>00140         <span class="keywordflow">return</span> m_size;
<a name="l00141"></a>00141     }
<a name="l00142"></a>00142 
<a name="l00143"></a><a class="code" href="classbt_aligned_object_array.html#3a25600ae43d660965d4e5a0810848c4">00143</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keyword">const</span> T&amp; <a class="code" href="classbt_aligned_object_array.html#3a25600ae43d660965d4e5a0810848c4">at</a>(int32_t n)<span class="keyword"> const</span>
<a name="l00144"></a>00144 <span class="keyword">    </span>{
<a name="l00145"></a>00145         <a class="code" href="bt_scalar_8h.html#ff3e6078c073f6ba0edb95353f2c2c62">btAssert</a>(n &gt;= 0);
<a name="l00146"></a>00146         <a class="code" href="bt_scalar_8h.html#ff3e6078c073f6ba0edb95353f2c2c62">btAssert</a>(n &lt; <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>());
<a name="l00147"></a>00147         <span class="keywordflow">return</span> m_data[n];
<a name="l00148"></a>00148     }
<a name="l00149"></a>00149 
<a name="l00150"></a><a class="code" href="classbt_aligned_object_array.html#9ab50f401fff737aa8d15c6ea1c8de79">00150</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> T&amp; <a class="code" href="classbt_aligned_object_array.html#3a25600ae43d660965d4e5a0810848c4">at</a>(int32_t n)
<a name="l00151"></a>00151     {
<a name="l00152"></a>00152         <a class="code" href="bt_scalar_8h.html#ff3e6078c073f6ba0edb95353f2c2c62">btAssert</a>(n &gt;= 0);
<a name="l00153"></a>00153         <a class="code" href="bt_scalar_8h.html#ff3e6078c073f6ba0edb95353f2c2c62">btAssert</a>(n &lt; <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>());
<a name="l00154"></a>00154         <span class="keywordflow">return</span> m_data[n];
<a name="l00155"></a>00155     }
<a name="l00156"></a>00156 
<a name="l00157"></a><a class="code" href="classbt_aligned_object_array.html#c36b30021258cd933453ee23dd78ae5f">00157</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keyword">const</span> T&amp; <a class="code" href="classbt_aligned_object_array.html#c36b30021258cd933453ee23dd78ae5f">operator[]</a>(int32_t n)<span class="keyword"> const</span>
<a name="l00158"></a>00158 <span class="keyword">    </span>{
<a name="l00159"></a>00159         <a class="code" href="bt_scalar_8h.html#ff3e6078c073f6ba0edb95353f2c2c62">btAssert</a>(n &gt;= 0);
<a name="l00160"></a>00160         <a class="code" href="bt_scalar_8h.html#ff3e6078c073f6ba0edb95353f2c2c62">btAssert</a>(n &lt; <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>());
<a name="l00161"></a>00161         <span class="keywordflow">return</span> m_data[n];
<a name="l00162"></a>00162     }
<a name="l00163"></a>00163 
<a name="l00164"></a><a class="code" href="classbt_aligned_object_array.html#d6e2888f43fb2b23967ef23d6fe905ed">00164</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> T&amp; <a class="code" href="classbt_aligned_object_array.html#c36b30021258cd933453ee23dd78ae5f">operator[]</a>(int32_t n)
<a name="l00165"></a>00165     {
<a name="l00166"></a>00166         <a class="code" href="bt_scalar_8h.html#ff3e6078c073f6ba0edb95353f2c2c62">btAssert</a>(n &gt;= 0);
<a name="l00167"></a>00167         <a class="code" href="bt_scalar_8h.html#ff3e6078c073f6ba0edb95353f2c2c62">btAssert</a>(n &lt; <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>());
<a name="l00168"></a>00168         <span class="keywordflow">return</span> m_data[n];
<a name="l00169"></a>00169     }
<a name="l00170"></a>00170 
<a name="l00172"></a><a class="code" href="classbt_aligned_object_array.html#12123db01dda7758f0df5e3bba10cc0a">00172</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#12123db01dda7758f0df5e3bba10cc0a" title="clear the array, deallocated memory. Generally it is better to use array.resize(0)...">clear</a>()
<a name="l00173"></a>00173     {
<a name="l00174"></a>00174         <a class="code" href="classbt_aligned_object_array.html#8ef274b9d73a61593c17b9b21442e0a7">destroy</a>(0, <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>());
<a name="l00175"></a>00175 
<a name="l00176"></a>00176         <a class="code" href="classbt_aligned_object_array.html#cebca91940aecdb1c11718bc08b511c9">deallocate</a>();
<a name="l00177"></a>00177 
<a name="l00178"></a>00178         <a class="code" href="classbt_aligned_object_array.html#336631607f9f5f08001866ed11b5fd64">init</a>();
<a name="l00179"></a>00179     }
<a name="l00180"></a>00180 
<a name="l00181"></a><a class="code" href="classbt_aligned_object_array.html#6169be905e03b84ea3bc8d8f7c7fc39d">00181</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#6169be905e03b84ea3bc8d8f7c7fc39d">pop_back</a>()
<a name="l00182"></a>00182     {
<a name="l00183"></a>00183         <a class="code" href="bt_scalar_8h.html#ff3e6078c073f6ba0edb95353f2c2c62">btAssert</a>(m_size &gt; 0);
<a name="l00184"></a>00184         m_size--;
<a name="l00185"></a>00185         m_data[m_size].~T();
<a name="l00186"></a>00186     }
<a name="l00187"></a>00187 
<a name="l00190"></a><a class="code" href="classbt_aligned_object_array.html#cb69833ed110d6db213a71533a8c804a">00190</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#cb69833ed110d6db213a71533a8c804a">resize</a>(int32_t newsize, <span class="keyword">const</span> T&amp; fillData = T())
<a name="l00191"></a>00191     {
<a name="l00192"></a>00192         int32_t curSize = <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>();
<a name="l00193"></a>00193 
<a name="l00194"></a>00194         <span class="keywordflow">if</span> (newsize &lt; curSize) {
<a name="l00195"></a>00195             <span class="keywordflow">for</span> (int32_t i = newsize; i &lt; curSize; i++) {
<a name="l00196"></a>00196                 m_data[i].~T();
<a name="l00197"></a>00197             }
<a name="l00198"></a>00198         }
<a name="l00199"></a>00199         <span class="keywordflow">else</span> {
<a name="l00200"></a>00200             <span class="keywordflow">if</span> (newsize &gt; <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>()) {
<a name="l00201"></a>00201                 <a class="code" href="classbt_aligned_object_array.html#8385df1a28956061def9b78cb55ea7df">reserve</a>(newsize);
<a name="l00202"></a>00202             }
<a name="l00203"></a>00203 <span class="preprocessor">#ifdef BT_USE_PLACEMENT_NEW</span>
<a name="l00204"></a>00204 <span class="preprocessor"></span>            <span class="keywordflow">for</span> (int32_t i = curSize; i &lt; newsize; i++) {
<a name="l00205"></a>00205                 <span class="keyword">new</span> (&amp;m_data[i]) T(fillData);
<a name="l00206"></a>00206             }
<a name="l00207"></a>00207 <span class="preprocessor">#endif //BT_USE_PLACEMENT_NEW</span>
<a name="l00208"></a>00208 <span class="preprocessor"></span>        }
<a name="l00209"></a>00209 
<a name="l00210"></a>00210         m_size = newsize;
<a name="l00211"></a>00211     }
<a name="l00212"></a>00212 
<a name="l00213"></a><a class="code" href="classbt_aligned_object_array.html#d1f99f070780c42619386fd2a4336bec">00213</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> T&amp; <a class="code" href="classbt_aligned_object_array.html#d1f99f070780c42619386fd2a4336bec">expandNonInitializing</a>()
<a name="l00214"></a>00214     {
<a name="l00215"></a>00215         int32_t sz = <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>();
<a name="l00216"></a>00216         <span class="keywordflow">if</span> (sz == <a class="code" href="classbt_aligned_object_array.html#55308568e3b168e2f0aca895b255ecca" title="return the pre-allocated (reserved) elements, this is at least as large as the total...">capacity</a>()) {
<a name="l00217"></a>00217             <a class="code" href="classbt_aligned_object_array.html#8385df1a28956061def9b78cb55ea7df">reserve</a>(<a class="code" href="classbt_aligned_object_array.html#a719fb250e71cf4c524fc10883d3f9cc">allocSize</a>(<a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>()));
<a name="l00218"></a>00218         }
<a name="l00219"></a>00219         m_size++;
<a name="l00220"></a>00220 
<a name="l00221"></a>00221         <span class="keywordflow">return</span> m_data[sz];
<a name="l00222"></a>00222     }
<a name="l00223"></a>00223 
<a name="l00224"></a><a class="code" href="classbt_aligned_object_array.html#d64affb4ed3f9db81f832cbac6b62527">00224</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> T&amp; <a class="code" href="classbt_aligned_object_array.html#d64affb4ed3f9db81f832cbac6b62527">expand</a>(<span class="keyword">const</span> T&amp; fillValue = T())
<a name="l00225"></a>00225     {
<a name="l00226"></a>00226         int32_t sz = <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>();
<a name="l00227"></a>00227         <span class="keywordflow">if</span> (sz == <a class="code" href="classbt_aligned_object_array.html#55308568e3b168e2f0aca895b255ecca" title="return the pre-allocated (reserved) elements, this is at least as large as the total...">capacity</a>()) {
<a name="l00228"></a>00228             <a class="code" href="classbt_aligned_object_array.html#8385df1a28956061def9b78cb55ea7df">reserve</a>(<a class="code" href="classbt_aligned_object_array.html#a719fb250e71cf4c524fc10883d3f9cc">allocSize</a>(<a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>()));
<a name="l00229"></a>00229         }
<a name="l00230"></a>00230         m_size++;
<a name="l00231"></a>00231 <span class="preprocessor">#ifdef BT_USE_PLACEMENT_NEW</span>
<a name="l00232"></a>00232 <span class="preprocessor"></span>        <span class="keyword">new</span> (&amp;m_data[sz]) T(fillValue); <span class="comment">//use the in-place new (not really allocating heap memory)</span>
<a name="l00233"></a>00233 <span class="preprocessor">#endif</span>
<a name="l00234"></a>00234 <span class="preprocessor"></span>
<a name="l00235"></a>00235         <span class="keywordflow">return</span> m_data[sz];
<a name="l00236"></a>00236     }
<a name="l00237"></a>00237 
<a name="l00238"></a><a class="code" href="classbt_aligned_object_array.html#d61e10166e2c00f487095d3482b9edd1">00238</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#d61e10166e2c00f487095d3482b9edd1">push_back</a>(<span class="keyword">const</span> T&amp; _Val)
<a name="l00239"></a>00239     {
<a name="l00240"></a>00240         int32_t sz = <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>();
<a name="l00241"></a>00241         <span class="keywordflow">if</span> (sz == <a class="code" href="classbt_aligned_object_array.html#55308568e3b168e2f0aca895b255ecca" title="return the pre-allocated (reserved) elements, this is at least as large as the total...">capacity</a>()) {
<a name="l00242"></a>00242             <a class="code" href="classbt_aligned_object_array.html#8385df1a28956061def9b78cb55ea7df">reserve</a>(<a class="code" href="classbt_aligned_object_array.html#a719fb250e71cf4c524fc10883d3f9cc">allocSize</a>(<a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>()));
<a name="l00243"></a>00243         }
<a name="l00244"></a>00244 
<a name="l00245"></a>00245 <span class="preprocessor">#ifdef BT_USE_PLACEMENT_NEW</span>
<a name="l00246"></a>00246 <span class="preprocessor"></span>        <span class="keyword">new</span> (&amp;m_data[m_size]) T(_Val);
<a name="l00247"></a>00247 <span class="preprocessor">#else</span>
<a name="l00248"></a>00248 <span class="preprocessor"></span>        m_data[<a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>()] = _Val;
<a name="l00249"></a>00249 <span class="preprocessor">#endif //BT_USE_PLACEMENT_NEW</span>
<a name="l00250"></a>00250 <span class="preprocessor"></span>
<a name="l00251"></a>00251         m_size++;
<a name="l00252"></a>00252     }
<a name="l00253"></a>00253 
<a name="l00255"></a><a class="code" href="classbt_aligned_object_array.html#55308568e3b168e2f0aca895b255ecca">00255</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> int32_t <a class="code" href="classbt_aligned_object_array.html#55308568e3b168e2f0aca895b255ecca" title="return the pre-allocated (reserved) elements, this is at least as large as the total...">capacity</a>()<span class="keyword"> const</span>
<a name="l00256"></a>00256 <span class="keyword">    </span>{
<a name="l00257"></a>00257         <span class="keywordflow">return</span> m_capacity;
<a name="l00258"></a>00258     }
<a name="l00259"></a>00259 
<a name="l00260"></a><a class="code" href="classbt_aligned_object_array.html#8385df1a28956061def9b78cb55ea7df">00260</a>     <a class="code" href="bt_scalar_8h.html#8a6a3e8b28846a3d7271e376c738ec40">SIMD_FORCE_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#8385df1a28956061def9b78cb55ea7df">reserve</a>(int32_t _Count)
<a name="l00261"></a>00261     { <span class="comment">// determine new minimum length of allocated storage</span>
<a name="l00262"></a>00262         <span class="keywordflow">if</span> (<a class="code" href="classbt_aligned_object_array.html#55308568e3b168e2f0aca895b255ecca" title="return the pre-allocated (reserved) elements, this is at least as large as the total...">capacity</a>() &lt; _Count) { <span class="comment">// not enough room, reallocate</span>
<a name="l00263"></a>00263             T* s = (T*)<a class="code" href="classbt_aligned_object_array.html#2302b4abe7664283231e150ecadc4576">allocate</a>(_Count);
<a name="l00264"></a>00264 
<a name="l00265"></a>00265             <a class="code" href="classbt_aligned_object_array.html#edc2708d688e8cc816d97ecb05ace68f">copy</a>(0, <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>(), s);
<a name="l00266"></a>00266 
<a name="l00267"></a>00267             <a class="code" href="classbt_aligned_object_array.html#8ef274b9d73a61593c17b9b21442e0a7">destroy</a>(0, <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>());
<a name="l00268"></a>00268 
<a name="l00269"></a>00269             <a class="code" href="classbt_aligned_object_array.html#cebca91940aecdb1c11718bc08b511c9">deallocate</a>();
<a name="l00270"></a>00270 
<a name="l00271"></a>00271             <span class="comment">//PCK: added this line</span>
<a name="l00272"></a>00272             m_ownsMemory = <span class="keyword">true</span>;
<a name="l00273"></a>00273 
<a name="l00274"></a>00274             m_data = s;
<a name="l00275"></a>00275 
<a name="l00276"></a>00276             m_capacity = _Count;
<a name="l00277"></a>00277         }
<a name="l00278"></a>00278     }
<a name="l00279"></a>00279 
<a name="l00280"></a><a class="code" href="classbt_aligned_object_array_1_1less.html">00280</a>     <span class="keyword">class </span><a class="code" href="classbt_aligned_object_array_1_1less.html">less</a> {
<a name="l00281"></a>00281     <span class="keyword">public</span>:
<a name="l00282"></a><a class="code" href="classbt_aligned_object_array_1_1less.html#bb5dd559201b5e57b68afe2a76509ef7">00282</a>         <span class="keywordtype">bool</span> <a class="code" href="classbt_aligned_object_array_1_1less.html#bb5dd559201b5e57b68afe2a76509ef7">operator()</a>(<span class="keyword">const</span> T&amp; a, <span class="keyword">const</span> T&amp; b)
<a name="l00283"></a>00283         {
<a name="l00284"></a>00284             <span class="keywordflow">return</span> (a &lt; b);
<a name="l00285"></a>00285         }
<a name="l00286"></a>00286     };
<a name="l00287"></a>00287 
<a name="l00288"></a>00288     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> L&gt;
<a name="l00289"></a><a class="code" href="classbt_aligned_object_array.html#c3fdb03c03d2cc75821d903c77f3476a">00289</a>     <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#c3fdb03c03d2cc75821d903c77f3476a">quickSortInternal</a>(<span class="keyword">const</span> L&amp; CompareFunc, int32_t lo, int32_t hi)
<a name="l00290"></a>00290     {
<a name="l00291"></a>00291         <span class="comment">//  lo is the lower index, hi is the upper index</span>
<a name="l00292"></a>00292         <span class="comment">//  of the region of array a that is to be sorted</span>
<a name="l00293"></a>00293         int32_t i = lo, j = hi;
<a name="l00294"></a>00294         T <a class="code" href="bt_vector3_8h.html#0d05bb202a57e1c47ae0eeeec2502c1b" title="Return the x value.">x</a> = m_data[(lo + hi) / 2];
<a name="l00295"></a>00295 
<a name="l00296"></a>00296         <span class="comment">//  partition</span>
<a name="l00297"></a>00297         <span class="keywordflow">do</span> {
<a name="l00298"></a>00298             <span class="keywordflow">while</span> (CompareFunc(m_data[i], x))
<a name="l00299"></a>00299                 i++;
<a name="l00300"></a>00300             <span class="keywordflow">while</span> (CompareFunc(x, m_data[j]))
<a name="l00301"></a>00301                 j--;
<a name="l00302"></a>00302             <span class="keywordflow">if</span> (i &lt;= j) {
<a name="l00303"></a>00303                 <a class="code" href="classbt_aligned_object_array.html#ff6f6234bb9c7cd1cea1cf00f07c1c09">swap</a>(i, j);
<a name="l00304"></a>00304                 i++;
<a name="l00305"></a>00305                 j--;
<a name="l00306"></a>00306             }
<a name="l00307"></a>00307         } <span class="keywordflow">while</span> (i &lt;= j);
<a name="l00308"></a>00308 
<a name="l00309"></a>00309         <span class="comment">//  recursion</span>
<a name="l00310"></a>00310         <span class="keywordflow">if</span> (lo &lt; j)
<a name="l00311"></a>00311             <a class="code" href="classbt_aligned_object_array.html#c3fdb03c03d2cc75821d903c77f3476a">quickSortInternal</a>(CompareFunc, lo, j);
<a name="l00312"></a>00312         <span class="keywordflow">if</span> (i &lt; hi)
<a name="l00313"></a>00313             <a class="code" href="classbt_aligned_object_array.html#c3fdb03c03d2cc75821d903c77f3476a">quickSortInternal</a>(CompareFunc, i, hi);
<a name="l00314"></a>00314     }
<a name="l00315"></a>00315 
<a name="l00316"></a>00316     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> L&gt;
<a name="l00317"></a><a class="code" href="classbt_aligned_object_array.html#228f2a824ac397c1de311a9c2b775dc4">00317</a>     <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#228f2a824ac397c1de311a9c2b775dc4">quickSort</a>(<span class="keyword">const</span> L&amp; CompareFunc)
<a name="l00318"></a>00318     {
<a name="l00319"></a>00319         <span class="comment">//don't sort 0 or 1 elements</span>
<a name="l00320"></a>00320         <span class="keywordflow">if</span> (<a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>() &gt; 1) {
<a name="l00321"></a>00321             <a class="code" href="classbt_aligned_object_array.html#c3fdb03c03d2cc75821d903c77f3476a">quickSortInternal</a>(CompareFunc, 0, <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>() - 1);
<a name="l00322"></a>00322         }
<a name="l00323"></a>00323     }
<a name="l00324"></a>00324 
<a name="l00326"></a>00326     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> L&gt;
<a name="l00327"></a><a class="code" href="classbt_aligned_object_array.html#45bd16505782854511491c25e0223ff8">00327</a>     <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#45bd16505782854511491c25e0223ff8" title="heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/">downHeap</a>(T* pArr, int32_t k, int32_t n, <span class="keyword">const</span> L&amp; CompareFunc)
<a name="l00328"></a>00328     {
<a name="l00329"></a>00329         <span class="comment">/*  PRE: a[k+1..N] is a heap */</span>
<a name="l00330"></a>00330         <span class="comment">/* POST:  a[k..N]  is a heap */</span>
<a name="l00331"></a>00331 
<a name="l00332"></a>00332         T temp = pArr[k - 1];
<a name="l00333"></a>00333         <span class="comment">/* k has child(s) */</span>
<a name="l00334"></a>00334         <span class="keywordflow">while</span> (k &lt;= n / 2) {
<a name="l00335"></a>00335             int32_t child = 2 * k;
<a name="l00336"></a>00336 
<a name="l00337"></a>00337             <span class="keywordflow">if</span> ((child &lt; n) &amp;&amp; CompareFunc(pArr[child - 1], pArr[child])) {
<a name="l00338"></a>00338                 child++;
<a name="l00339"></a>00339             }
<a name="l00340"></a>00340             <span class="comment">/* pick larger child */</span>
<a name="l00341"></a>00341             <span class="keywordflow">if</span> (CompareFunc(temp, pArr[child - 1])) {
<a name="l00342"></a>00342                 <span class="comment">/* move child up */</span>
<a name="l00343"></a>00343                 pArr[k - 1] = pArr[child - 1];
<a name="l00344"></a>00344                 k = child;
<a name="l00345"></a>00345             }
<a name="l00346"></a>00346             <span class="keywordflow">else</span> {
<a name="l00347"></a>00347                 <span class="keywordflow">break</span>;
<a name="l00348"></a>00348             }
<a name="l00349"></a>00349         }
<a name="l00350"></a>00350         pArr[k - 1] = temp;
<a name="l00351"></a>00351     } <span class="comment">/*downHeap*/</span>
<a name="l00352"></a>00352 
<a name="l00353"></a><a class="code" href="classbt_aligned_object_array.html#ff6f6234bb9c7cd1cea1cf00f07c1c09">00353</a>     <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#ff6f6234bb9c7cd1cea1cf00f07c1c09">swap</a>(int32_t index0, int32_t index1)
<a name="l00354"></a>00354     {
<a name="l00355"></a>00355 <span class="preprocessor">#ifdef BT_USE_MEMCPY</span>
<a name="l00356"></a>00356 <span class="preprocessor"></span>        <span class="keywordtype">char</span> temp[<span class="keyword">sizeof</span>(T)];
<a name="l00357"></a>00357         memcpy(temp, &amp;m_data[index0], <span class="keyword">sizeof</span>(T));
<a name="l00358"></a>00358         memcpy(&amp;m_data[index0], &amp;m_data[index1], <span class="keyword">sizeof</span>(T));
<a name="l00359"></a>00359         memcpy(&amp;m_data[index1], temp, <span class="keyword">sizeof</span>(T));
<a name="l00360"></a>00360 <span class="preprocessor">#else</span>
<a name="l00361"></a>00361 <span class="preprocessor"></span>        T temp = m_data[index0];
<a name="l00362"></a>00362         m_data[index0] = m_data[index1];
<a name="l00363"></a>00363         m_data[index1] = temp;
<a name="l00364"></a>00364 <span class="preprocessor">#endif //BT_USE_PLACEMENT_NEW</span>
<a name="l00365"></a>00365 <span class="preprocessor"></span>    }
<a name="l00366"></a>00366 
<a name="l00367"></a>00367     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> L&gt;
<a name="l00368"></a><a class="code" href="classbt_aligned_object_array.html#3c338461ca225909d18955f1991a3acc">00368</a>     <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#3c338461ca225909d18955f1991a3acc">heapSort</a>(<span class="keyword">const</span> L&amp; CompareFunc)
<a name="l00369"></a>00369     {
<a name="l00370"></a>00370         <span class="comment">/* sort a[0..N-1],  N.B. 0 to N-1 */</span>
<a name="l00371"></a>00371         int32_t k;
<a name="l00372"></a>00372         int32_t n = m_size;
<a name="l00373"></a>00373         <span class="keywordflow">for</span> (k = n / 2; k &gt; 0; k--) {
<a name="l00374"></a>00374             <a class="code" href="classbt_aligned_object_array.html#45bd16505782854511491c25e0223ff8" title="heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/">downHeap</a>(m_data, k, n, CompareFunc);
<a name="l00375"></a>00375         }
<a name="l00376"></a>00376 
<a name="l00377"></a>00377         <span class="comment">/* a[1..N] is now a heap */</span>
<a name="l00378"></a>00378         <span class="keywordflow">while</span> (n &gt;= 1) {
<a name="l00379"></a>00379             <a class="code" href="classbt_aligned_object_array.html#ff6f6234bb9c7cd1cea1cf00f07c1c09">swap</a>(0, n - 1); <span class="comment">/* largest of a[0..n-1] */</span>
<a name="l00380"></a>00380 
<a name="l00381"></a>00381             n = n - 1;
<a name="l00382"></a>00382             <span class="comment">/* restore a[1..i-1] heap */</span>
<a name="l00383"></a>00383             <a class="code" href="classbt_aligned_object_array.html#45bd16505782854511491c25e0223ff8" title="heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/">downHeap</a>(m_data, 1, n, CompareFunc);
<a name="l00384"></a>00384         }
<a name="l00385"></a>00385     }
<a name="l00386"></a>00386 
<a name="l00388"></a><a class="code" href="classbt_aligned_object_array.html#3166625bc9a4f5aeca8a39c68f97228f">00388</a>     int32_t <a class="code" href="classbt_aligned_object_array.html#3166625bc9a4f5aeca8a39c68f97228f" title="non-recursive binary search, assumes sorted array">findBinarySearch</a>(<span class="keyword">const</span> T&amp; key)<span class="keyword"> const</span>
<a name="l00389"></a>00389 <span class="keyword">    </span>{
<a name="l00390"></a>00390         int32_t first = 0;
<a name="l00391"></a>00391         int32_t last = <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>() - 1;
<a name="l00392"></a>00392 
<a name="l00393"></a>00393         <span class="comment">//assume sorted array</span>
<a name="l00394"></a>00394         <span class="keywordflow">while</span> (first &lt;= last) {
<a name="l00395"></a>00395             int32_t mid = (first + last) / 2; <span class="comment">// compute mid point.</span>
<a name="l00396"></a>00396             <span class="keywordflow">if</span> (key &gt; m_data[mid])
<a name="l00397"></a>00397                 first = mid + 1; <span class="comment">// repeat search in top half.</span>
<a name="l00398"></a>00398             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (key &lt; m_data[mid])
<a name="l00399"></a>00399                 last = mid - 1; <span class="comment">// repeat search in bottom half.</span>
<a name="l00400"></a>00400             <span class="keywordflow">else</span>
<a name="l00401"></a>00401                 <span class="keywordflow">return</span> mid; <span class="comment">// found it. return position /////</span>
<a name="l00402"></a>00402         }
<a name="l00403"></a>00403         <span class="keywordflow">return</span> <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>(); <span class="comment">// failed to find key</span>
<a name="l00404"></a>00404     }
<a name="l00405"></a>00405 
<a name="l00406"></a><a class="code" href="classbt_aligned_object_array.html#02eddb849aa4b56cc38d4040408fb48a">00406</a>     int32_t <a class="code" href="classbt_aligned_object_array.html#02eddb849aa4b56cc38d4040408fb48a">findLinearSearch</a>(<span class="keyword">const</span> T&amp; key)<span class="keyword"> const</span>
<a name="l00407"></a>00407 <span class="keyword">    </span>{
<a name="l00408"></a>00408         int32_t index = <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>();
<a name="l00409"></a>00409         int32_t i;
<a name="l00410"></a>00410 
<a name="l00411"></a>00411         <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>(); i++) {
<a name="l00412"></a>00412             <span class="keywordflow">if</span> (m_data[i] == key) {
<a name="l00413"></a>00413                 index = i;
<a name="l00414"></a>00414                 <span class="keywordflow">break</span>;
<a name="l00415"></a>00415             }
<a name="l00416"></a>00416         }
<a name="l00417"></a>00417         <span class="keywordflow">return</span> index;
<a name="l00418"></a>00418     }
<a name="l00419"></a>00419 
<a name="l00420"></a><a class="code" href="classbt_aligned_object_array.html#6782242f06df5bab0cffbd23195cd9cd">00420</a>     <span class="keywordtype">void</span> <span class="keyword">remove</span>(<span class="keyword">const</span> T&amp; key)
<a name="l00421"></a>00421     {
<a name="l00422"></a>00422 
<a name="l00423"></a>00423         int32_t findIndex = <a class="code" href="classbt_aligned_object_array.html#02eddb849aa4b56cc38d4040408fb48a">findLinearSearch</a>(key);
<a name="l00424"></a>00424         <span class="keywordflow">if</span> (findIndex &lt; <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>()) {
<a name="l00425"></a>00425             <a class="code" href="classbt_aligned_object_array.html#ff6f6234bb9c7cd1cea1cf00f07c1c09">swap</a>(findIndex, <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>() - 1);
<a name="l00426"></a>00426             <a class="code" href="classbt_aligned_object_array.html#6169be905e03b84ea3bc8d8f7c7fc39d">pop_back</a>();
<a name="l00427"></a>00427         }
<a name="l00428"></a>00428     }
<a name="l00429"></a>00429 
<a name="l00430"></a>00430     <span class="comment">//PCK: whole function</span>
<a name="l00431"></a><a class="code" href="classbt_aligned_object_array.html#2b1b904bdf0a1e4110406860f46615d5">00431</a>     <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#2b1b904bdf0a1e4110406860f46615d5">initializeFromBuffer</a>(<span class="keywordtype">void</span>* buffer, int32_t <a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>, int32_t <a class="code" href="classbt_aligned_object_array.html#55308568e3b168e2f0aca895b255ecca" title="return the pre-allocated (reserved) elements, this is at least as large as the total...">capacity</a>)
<a name="l00432"></a>00432     {
<a name="l00433"></a>00433         <a class="code" href="classbt_aligned_object_array.html#12123db01dda7758f0df5e3bba10cc0a" title="clear the array, deallocated memory. Generally it is better to use array.resize(0)...">clear</a>();
<a name="l00434"></a>00434         m_ownsMemory = <span class="keyword">false</span>;
<a name="l00435"></a>00435         m_data = (T*)buffer;
<a name="l00436"></a>00436         m_size = size;
<a name="l00437"></a>00437         m_capacity = capacity;
<a name="l00438"></a>00438     }
<a name="l00439"></a>00439 
<a name="l00440"></a><a class="code" href="classbt_aligned_object_array.html#1464bd66b0e5e3880b4c7aa4a2ce13a1">00440</a>     <span class="keywordtype">void</span> <a class="code" href="classbt_aligned_object_array.html#1464bd66b0e5e3880b4c7aa4a2ce13a1">copyFromArray</a>(<span class="keyword">const</span> <a class="code" href="classbt_aligned_object_array.html">btAlignedObjectArray</a>&amp; otherArray)
<a name="l00441"></a>00441     {
<a name="l00442"></a>00442         int32_t otherSize = otherArray.<a class="code" href="classbt_aligned_object_array.html#c9fb7ab72fa1b2284ec10fa79f77e620" title="return the number of elements in the array">size</a>();
<a name="l00443"></a>00443         <a class="code" href="classbt_aligned_object_array.html#cb69833ed110d6db213a71533a8c804a">resize</a>(otherSize);
<a name="l00444"></a>00444         otherArray.<a class="code" href="classbt_aligned_object_array.html#edc2708d688e8cc816d97ecb05ace68f">copy</a>(0, otherSize, m_data);
<a name="l00445"></a>00445     }
<a name="l00446"></a>00446 };
<a name="l00447"></a>00447 
<a name="l00448"></a>00448 <span class="preprocessor">#endif //BT_OBJECT_ARRAY__</span>
</pre></div></div>
<!-- start footer part -->
<div class="footer">
Copyright &copy; 2015-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. <a href="http://www.nvidia.com ">www.nvidia.com</a>
</div>
</body>
</html>