diff options
author | David Walter Seikel | 2014-01-13 19:47:58 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-01-13 19:47:58 +1000 |
commit | f9158592e1478b2013afc7041d9ed041cf2d2f4a (patch) | |
tree | b16e389d7988700e21b4c9741044cefa536dcbae /libraries/irrlicht-1.8.1/doc/html/irr_array_8h_source.html | |
parent | Libraries readme updated with change markers and more of the Irrlicht changes. (diff) | |
download | SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.zip SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.gz SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.bz2 SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.xz |
Update Irrlicht to 1.8.1. Include actual change markers this time. lol
Diffstat (limited to 'libraries/irrlicht-1.8.1/doc/html/irr_array_8h_source.html')
-rw-r--r-- | libraries/irrlicht-1.8.1/doc/html/irr_array_8h_source.html | 643 |
1 files changed, 643 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/doc/html/irr_array_8h_source.html b/libraries/irrlicht-1.8.1/doc/html/irr_array_8h_source.html new file mode 100644 index 0000000..b6e4ed9 --- /dev/null +++ b/libraries/irrlicht-1.8.1/doc/html/irr_array_8h_source.html | |||
@@ -0,0 +1,643 @@ | |||
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
2 | <html xmlns="http://www.w3.org/1999/xhtml"> | ||
3 | <head> | ||
4 | <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> | ||
5 | <title>Irrlicht 3D Engine: irrArray.h Source File</title> | ||
6 | |||
7 | <link href="tabs.css" rel="stylesheet" type="text/css"/> | ||
8 | <link href="doxygen.css" rel="stylesheet" type="text/css" /> | ||
9 | <link href="navtree.css" rel="stylesheet" type="text/css"/> | ||
10 | <script type="text/javascript" src="jquery.js"></script> | ||
11 | <script type="text/javascript" src="resize.js"></script> | ||
12 | <script type="text/javascript" src="navtree.js"></script> | ||
13 | <script type="text/javascript"> | ||
14 | $(document).ready(initResizable); | ||
15 | </script> | ||
16 | <link href="search/search.css" rel="stylesheet" type="text/css"/> | ||
17 | <script type="text/javascript" src="search/search.js"></script> | ||
18 | <script type="text/javascript"> | ||
19 | $(document).ready(function() { searchBox.OnSelectItem(0); }); | ||
20 | </script> | ||
21 | |||
22 | </head> | ||
23 | <body> | ||
24 | <div id="top"><!-- do not remove this div! --> | ||
25 | |||
26 | |||
27 | <div id="titlearea"> | ||
28 | <table cellspacing="0" cellpadding="0"> | ||
29 | <tbody> | ||
30 | <tr style="height: 56px;"> | ||
31 | |||
32 | <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td> | ||
33 | |||
34 | |||
35 | <td style="padding-left: 0.5em;"> | ||
36 | <div id="projectname">Irrlicht 3D Engine | ||
37 | |||
38 | </div> | ||
39 | |||
40 | </td> | ||
41 | |||
42 | |||
43 | |||
44 | |||
45 | <td> <div id="MSearchBox" class="MSearchBoxInactive"> | ||
46 | <span class="left"> | ||
47 | <img id="MSearchSelect" src="search/mag_sel.png" | ||
48 | onmouseover="return searchBox.OnSearchSelectShow()" | ||
49 | onmouseout="return searchBox.OnSearchSelectHide()" | ||
50 | alt=""/> | ||
51 | <input type="text" id="MSearchField" value="Search" accesskey="S" | ||
52 | onfocus="searchBox.OnSearchFieldFocus(true)" | ||
53 | onblur="searchBox.OnSearchFieldFocus(false)" | ||
54 | onkeyup="searchBox.OnSearchFieldChange(event)"/> | ||
55 | </span><span class="right"> | ||
56 | <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> | ||
57 | </span> | ||
58 | </div> | ||
59 | </td> | ||
60 | |||
61 | |||
62 | </tr> | ||
63 | </tbody> | ||
64 | </table> | ||
65 | </div> | ||
66 | |||
67 | <!-- Generated by Doxygen 1.7.5.1 --> | ||
68 | <script type="text/javascript"> | ||
69 | var searchBox = new SearchBox("searchBox", "search",false,'Search'); | ||
70 | </script> | ||
71 | <script type="text/javascript" src="dynsections.js"></script> | ||
72 | </div> | ||
73 | <div id="side-nav" class="ui-resizable side-nav-resizable"> | ||
74 | <div id="nav-tree"> | ||
75 | <div id="nav-tree-contents"> | ||
76 | </div> | ||
77 | </div> | ||
78 | <div id="splitbar" style="-moz-user-select:none;" | ||
79 | class="ui-resizable-handle"> | ||
80 | </div> | ||
81 | </div> | ||
82 | <script type="text/javascript"> | ||
83 | initNavTree('irr_array_8h.html',''); | ||
84 | </script> | ||
85 | <div id="doc-content"> | ||
86 | <div class="header"> | ||
87 | <div class="headertitle"> | ||
88 | <div class="title">irrArray.h</div> </div> | ||
89 | </div> | ||
90 | <div class="contents"> | ||
91 | <a href="irr_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">// Copyright (C) 2002-2012 Nikolaus Gebhardt</span> | ||
92 | <a name="l00002"></a>00002 <span class="comment">// This file is part of the "Irrlicht Engine" and the "irrXML" project.</span> | ||
93 | <a name="l00003"></a>00003 <span class="comment">// For conditions of distribution and use, see copyright notice in irrlicht.h and irrXML.h</span> | ||
94 | <a name="l00004"></a>00004 | ||
95 | <a name="l00005"></a>00005 <span class="preprocessor">#ifndef __IRR_ARRAY_H_INCLUDED__</span> | ||
96 | <a name="l00006"></a>00006 <span class="preprocessor"></span><span class="preprocessor">#define __IRR_ARRAY_H_INCLUDED__</span> | ||
97 | <a name="l00007"></a>00007 <span class="preprocessor"></span> | ||
98 | <a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="irr_types_8h.html">irrTypes.h</a>"</span> | ||
99 | <a name="l00009"></a>00009 <span class="preprocessor">#include "<a class="code" href="heapsort_8h.html">heapsort.h</a>"</span> | ||
100 | <a name="l00010"></a>00010 <span class="preprocessor">#include "<a class="code" href="irr_allocator_8h.html">irrAllocator.h</a>"</span> | ||
101 | <a name="l00011"></a>00011 <span class="preprocessor">#include "<a class="code" href="irr_math_8h.html">irrMath.h</a>"</span> | ||
102 | <a name="l00012"></a>00012 | ||
103 | <a name="l00013"></a>00013 <span class="keyword">namespace </span>irr | ||
104 | <a name="l00014"></a>00014 { | ||
105 | <a name="l00015"></a>00015 <span class="keyword">namespace </span>core | ||
106 | <a name="l00016"></a>00016 { | ||
107 | <a name="l00017"></a>00017 | ||
108 | <a name="l00019"></a>00019 | ||
109 | <a name="l00021"></a>00021 <span class="keyword">template</span> <<span class="keyword">class</span> T, <span class="keyword">typename</span> TAlloc = irrAllocator<T> > | ||
110 | <a name="l00022"></a><a class="code" href="classirr_1_1core_1_1array.html">00022</a> <span class="keyword">class </span><a class="code" href="classirr_1_1core_1_1array.html" title="Self reallocating template array (like stl vector) with additional features.">array</a> | ||
111 | <a name="l00023"></a>00023 { | ||
112 | <a name="l00024"></a>00024 | ||
113 | <a name="l00025"></a>00025 <span class="keyword">public</span>: | ||
114 | <a name="l00026"></a>00026 | ||
115 | <a name="l00028"></a><a class="code" href="classirr_1_1core_1_1array.html#a5e0dd817352068af92448a08716f1252">00028</a> <a class="code" href="classirr_1_1core_1_1array.html#a5e0dd817352068af92448a08716f1252" title="Default constructor for empty array.">array</a>() | ||
116 | <a name="l00029"></a>00029 : data(0), allocated(0), used(0), | ||
117 | <a name="l00030"></a>00030 strategy(<a class="code" href="namespaceirr_1_1core.html#aa2e91971d5e6e84de235bfabe3c7adbaa1fa5aed132891361601560ed3e067fe8">ALLOC_STRATEGY_DOUBLE</a>), free_when_destroyed(true), is_sorted(true) | ||
118 | <a name="l00031"></a>00031 { | ||
119 | <a name="l00032"></a>00032 } | ||
120 | <a name="l00033"></a>00033 | ||
121 | <a name="l00034"></a>00034 | ||
122 | <a name="l00036"></a>00036 | ||
123 | <a name="l00037"></a><a class="code" href="classirr_1_1core_1_1array.html#ab58c4b2c09693190b43ee16e99722b43">00037</a> <a class="code" href="classirr_1_1core_1_1array.html#a5e0dd817352068af92448a08716f1252" title="Default constructor for empty array.">array</a>(<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> start_count) | ||
124 | <a name="l00038"></a>00038 : data(0), allocated(0), used(0), | ||
125 | <a name="l00039"></a>00039 strategy(<a class="code" href="namespaceirr_1_1core.html#aa2e91971d5e6e84de235bfabe3c7adbaa1fa5aed132891361601560ed3e067fe8">ALLOC_STRATEGY_DOUBLE</a>), free_when_destroyed(true), is_sorted(true) | ||
126 | <a name="l00040"></a>00040 { | ||
127 | <a name="l00041"></a>00041 <a class="code" href="classirr_1_1core_1_1array.html#ada5735f409eca82b9031d993ee8b31c3" title="Reallocates the array, make it bigger or smaller.">reallocate</a>(start_count); | ||
128 | <a name="l00042"></a>00042 } | ||
129 | <a name="l00043"></a>00043 | ||
130 | <a name="l00044"></a>00044 | ||
131 | <a name="l00046"></a><a class="code" href="classirr_1_1core_1_1array.html#a4e584fd375dd5f994b6bd7afd7f7a60c">00046</a> <a class="code" href="classirr_1_1core_1_1array.html#a5e0dd817352068af92448a08716f1252" title="Default constructor for empty array.">array</a>(<span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1array.html" title="Self reallocating template array (like stl vector) with additional features.">array<T, TAlloc></a>& other) : data(0) | ||
132 | <a name="l00047"></a>00047 { | ||
133 | <a name="l00048"></a>00048 *<span class="keyword">this</span> = other; | ||
134 | <a name="l00049"></a>00049 } | ||
135 | <a name="l00050"></a>00050 | ||
136 | <a name="l00051"></a>00051 | ||
137 | <a name="l00053"></a>00053 | ||
138 | <a name="l00055"></a><a class="code" href="classirr_1_1core_1_1array.html#aac1853f45d4c18feaacac9859efe9836">00055</a> <a class="code" href="classirr_1_1core_1_1array.html#aac1853f45d4c18feaacac9859efe9836" title="Destructor.">~array</a>() | ||
139 | <a name="l00056"></a>00056 { | ||
140 | <a name="l00057"></a>00057 <a class="code" href="classirr_1_1core_1_1array.html#a236e08ca44ddf3c2b47b726f90db8d39" title="Clears the array and deletes all allocated memory.">clear</a>(); | ||
141 | <a name="l00058"></a>00058 } | ||
142 | <a name="l00059"></a>00059 | ||
143 | <a name="l00060"></a>00060 | ||
144 | <a name="l00062"></a>00062 | ||
145 | <a name="l00067"></a><a class="code" href="classirr_1_1core_1_1array.html#ada5735f409eca82b9031d993ee8b31c3">00067</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#ada5735f409eca82b9031d993ee8b31c3" title="Reallocates the array, make it bigger or smaller.">reallocate</a>(<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> new_size, <span class="keywordtype">bool</span> canShrink=<span class="keyword">true</span>) | ||
146 | <a name="l00068"></a>00068 { | ||
147 | <a name="l00069"></a>00069 <span class="keywordflow">if</span> (allocated==new_size) | ||
148 | <a name="l00070"></a>00070 <span class="keywordflow">return</span>; | ||
149 | <a name="l00071"></a>00071 <span class="keywordflow">if</span> (!canShrink && (new_size < allocated)) | ||
150 | <a name="l00072"></a>00072 <span class="keywordflow">return</span>; | ||
151 | <a name="l00073"></a>00073 | ||
152 | <a name="l00074"></a>00074 T* old_data = data; | ||
153 | <a name="l00075"></a>00075 | ||
154 | <a name="l00076"></a>00076 data = allocator.allocate(new_size); <span class="comment">//new T[new_size];</span> | ||
155 | <a name="l00077"></a>00077 allocated = new_size; | ||
156 | <a name="l00078"></a>00078 | ||
157 | <a name="l00079"></a>00079 <span class="comment">// copy old data</span> | ||
158 | <a name="l00080"></a>00080 <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> end = used < new_size ? used : new_size; | ||
159 | <a name="l00081"></a>00081 | ||
160 | <a name="l00082"></a>00082 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i=0; i<end; ++i) | ||
161 | <a name="l00083"></a>00083 { | ||
162 | <a name="l00084"></a>00084 <span class="comment">// data[i] = old_data[i];</span> | ||
163 | <a name="l00085"></a>00085 allocator.construct(&data[i], old_data[i]); | ||
164 | <a name="l00086"></a>00086 } | ||
165 | <a name="l00087"></a>00087 | ||
166 | <a name="l00088"></a>00088 <span class="comment">// destruct old data</span> | ||
167 | <a name="l00089"></a>00089 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> j=0; j<used; ++j) | ||
168 | <a name="l00090"></a>00090 allocator.destruct(&old_data[j]); | ||
169 | <a name="l00091"></a>00091 | ||
170 | <a name="l00092"></a>00092 <span class="keywordflow">if</span> (allocated < used) | ||
171 | <a name="l00093"></a>00093 used = allocated; | ||
172 | <a name="l00094"></a>00094 | ||
173 | <a name="l00095"></a>00095 allocator.deallocate(old_data); <span class="comment">//delete [] old_data;</span> | ||
174 | <a name="l00096"></a>00096 } | ||
175 | <a name="l00097"></a>00097 | ||
176 | <a name="l00098"></a>00098 | ||
177 | <a name="l00100"></a>00100 | ||
178 | <a name="l00103"></a><a class="code" href="classirr_1_1core_1_1array.html#a7aef3e5dbf91f8d1e8f365039e2497ae">00103</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#a7aef3e5dbf91f8d1e8f365039e2497ae" title="set a new allocation strategy">setAllocStrategy</a> ( <a class="code" href="namespaceirr_1_1core.html#aa2e91971d5e6e84de235bfabe3c7adba" title="defines an allocation strategy">eAllocStrategy</a> newStrategy = <a class="code" href="namespaceirr_1_1core.html#aa2e91971d5e6e84de235bfabe3c7adbaa1fa5aed132891361601560ed3e067fe8">ALLOC_STRATEGY_DOUBLE</a> ) | ||
179 | <a name="l00104"></a>00104 { | ||
180 | <a name="l00105"></a>00105 strategy = newStrategy; | ||
181 | <a name="l00106"></a>00106 } | ||
182 | <a name="l00107"></a>00107 | ||
183 | <a name="l00108"></a>00108 | ||
184 | <a name="l00110"></a>00110 | ||
185 | <a name="l00112"></a><a class="code" href="classirr_1_1core_1_1array.html#ad2c9dff8592b95c25c59f5383fc633fe">00112</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#ad2c9dff8592b95c25c59f5383fc633fe" title="Adds an element at back of array.">push_back</a>(<span class="keyword">const</span> T& element) | ||
186 | <a name="l00113"></a>00113 { | ||
187 | <a name="l00114"></a>00114 <a class="code" href="classirr_1_1core_1_1array.html#a3b0f73c95dd449a4de576c6b1943566c" title="Insert item into array at specified position.">insert</a>(element, used); | ||
188 | <a name="l00115"></a>00115 } | ||
189 | <a name="l00116"></a>00116 | ||
190 | <a name="l00117"></a>00117 | ||
191 | <a name="l00119"></a>00119 | ||
192 | <a name="l00123"></a><a class="code" href="classirr_1_1core_1_1array.html#a31b686ce4b1ebae930f22bc40d30efbd">00123</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#a31b686ce4b1ebae930f22bc40d30efbd" title="Adds an element at the front of the array.">push_front</a>(<span class="keyword">const</span> T& element) | ||
193 | <a name="l00124"></a>00124 { | ||
194 | <a name="l00125"></a>00125 <a class="code" href="classirr_1_1core_1_1array.html#a3b0f73c95dd449a4de576c6b1943566c" title="Insert item into array at specified position.">insert</a>(element); | ||
195 | <a name="l00126"></a>00126 } | ||
196 | <a name="l00127"></a>00127 | ||
197 | <a name="l00128"></a>00128 | ||
198 | <a name="l00130"></a>00130 | ||
199 | <a name="l00135"></a><a class="code" href="classirr_1_1core_1_1array.html#a3b0f73c95dd449a4de576c6b1943566c">00135</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#a3b0f73c95dd449a4de576c6b1943566c" title="Insert item into array at specified position.">insert</a>(<span class="keyword">const</span> T& element, <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> index=0) | ||
200 | <a name="l00136"></a>00136 { | ||
201 | <a name="l00137"></a>00137 <a class="code" href="irr_types_8h.html#a12f3b5fd18ca108f90c5c74db602267e" title="define a break macro for debugging.">_IRR_DEBUG_BREAK_IF</a>(index>used) <span class="comment">// access violation</span> | ||
202 | <a name="l00138"></a>00138 | ||
203 | <a name="l00139"></a>00139 <span class="keywordflow">if</span> (used + 1 > allocated) | ||
204 | <a name="l00140"></a>00140 { | ||
205 | <a name="l00141"></a>00141 <span class="comment">// this doesn't work if the element is in the same</span> | ||
206 | <a name="l00142"></a>00142 <span class="comment">// array. So we'll copy the element first to be sure</span> | ||
207 | <a name="l00143"></a>00143 <span class="comment">// we'll get no data corruption</span> | ||
208 | <a name="l00144"></a>00144 <span class="keyword">const</span> T e(element); | ||
209 | <a name="l00145"></a>00145 | ||
210 | <a name="l00146"></a>00146 <span class="comment">// increase data block</span> | ||
211 | <a name="l00147"></a>00147 <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> newAlloc; | ||
212 | <a name="l00148"></a>00148 <span class="keywordflow">switch</span> ( strategy ) | ||
213 | <a name="l00149"></a>00149 { | ||
214 | <a name="l00150"></a>00150 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1core.html#aa2e91971d5e6e84de235bfabe3c7adbaa1fa5aed132891361601560ed3e067fe8">ALLOC_STRATEGY_DOUBLE</a>: | ||
215 | <a name="l00151"></a>00151 newAlloc = used + 1 + (allocated < 500 ? | ||
216 | <a name="l00152"></a>00152 (allocated < 5 ? 5 : used) : used >> 2); | ||
217 | <a name="l00153"></a>00153 <span class="keywordflow">break</span>; | ||
218 | <a name="l00154"></a>00154 <span class="keywordflow">default</span>: | ||
219 | <a name="l00155"></a>00155 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1core.html#aa2e91971d5e6e84de235bfabe3c7adbaabfc6be96075564e1e0d92477e657f746">ALLOC_STRATEGY_SAFE</a>: | ||
220 | <a name="l00156"></a>00156 newAlloc = used + 1; | ||
221 | <a name="l00157"></a>00157 <span class="keywordflow">break</span>; | ||
222 | <a name="l00158"></a>00158 } | ||
223 | <a name="l00159"></a>00159 <a class="code" href="classirr_1_1core_1_1array.html#ada5735f409eca82b9031d993ee8b31c3" title="Reallocates the array, make it bigger or smaller.">reallocate</a>( newAlloc); | ||
224 | <a name="l00160"></a>00160 | ||
225 | <a name="l00161"></a>00161 <span class="comment">// move array content and construct new element</span> | ||
226 | <a name="l00162"></a>00162 <span class="comment">// first move end one up</span> | ||
227 | <a name="l00163"></a>00163 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=used; i>index; --i) | ||
228 | <a name="l00164"></a>00164 { | ||
229 | <a name="l00165"></a>00165 <span class="keywordflow">if</span> (i<used) | ||
230 | <a name="l00166"></a>00166 allocator.destruct(&data[i]); | ||
231 | <a name="l00167"></a>00167 allocator.construct(&data[i], data[i-1]); <span class="comment">// data[i] = data[i-1];</span> | ||
232 | <a name="l00168"></a>00168 } | ||
233 | <a name="l00169"></a>00169 <span class="comment">// then add new element</span> | ||
234 | <a name="l00170"></a>00170 <span class="keywordflow">if</span> (used > index) | ||
235 | <a name="l00171"></a>00171 allocator.destruct(&data[index]); | ||
236 | <a name="l00172"></a>00172 allocator.construct(&data[index], e); <span class="comment">// data[index] = e;</span> | ||
237 | <a name="l00173"></a>00173 } | ||
238 | <a name="l00174"></a>00174 <span class="keywordflow">else</span> | ||
239 | <a name="l00175"></a>00175 { | ||
240 | <a name="l00176"></a>00176 <span class="comment">// element inserted not at end</span> | ||
241 | <a name="l00177"></a>00177 <span class="keywordflow">if</span> ( used > index ) | ||
242 | <a name="l00178"></a>00178 { | ||
243 | <a name="l00179"></a>00179 <span class="comment">// create one new element at the end</span> | ||
244 | <a name="l00180"></a>00180 allocator.construct(&data[used], data[used-1]); | ||
245 | <a name="l00181"></a>00181 | ||
246 | <a name="l00182"></a>00182 <span class="comment">// move the rest of the array content</span> | ||
247 | <a name="l00183"></a>00183 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=used-1; i>index; --i) | ||
248 | <a name="l00184"></a>00184 { | ||
249 | <a name="l00185"></a>00185 data[i] = data[i-1]; | ||
250 | <a name="l00186"></a>00186 } | ||
251 | <a name="l00187"></a>00187 <span class="comment">// insert the new element</span> | ||
252 | <a name="l00188"></a>00188 data[index] = element; | ||
253 | <a name="l00189"></a>00189 } | ||
254 | <a name="l00190"></a>00190 <span class="keywordflow">else</span> | ||
255 | <a name="l00191"></a>00191 { | ||
256 | <a name="l00192"></a>00192 <span class="comment">// insert the new element to the end</span> | ||
257 | <a name="l00193"></a>00193 allocator.construct(&data[index], element); | ||
258 | <a name="l00194"></a>00194 } | ||
259 | <a name="l00195"></a>00195 } | ||
260 | <a name="l00196"></a>00196 <span class="comment">// set to false as we don't know if we have the comparison operators</span> | ||
261 | <a name="l00197"></a>00197 is_sorted = <span class="keyword">false</span>; | ||
262 | <a name="l00198"></a>00198 ++used; | ||
263 | <a name="l00199"></a>00199 } | ||
264 | <a name="l00200"></a>00200 | ||
265 | <a name="l00201"></a>00201 | ||
266 | <a name="l00203"></a><a class="code" href="classirr_1_1core_1_1array.html#a236e08ca44ddf3c2b47b726f90db8d39">00203</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#a236e08ca44ddf3c2b47b726f90db8d39" title="Clears the array and deletes all allocated memory.">clear</a>() | ||
267 | <a name="l00204"></a>00204 { | ||
268 | <a name="l00205"></a>00205 <span class="keywordflow">if</span> (free_when_destroyed) | ||
269 | <a name="l00206"></a>00206 { | ||
270 | <a name="l00207"></a>00207 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=0; i<used; ++i) | ||
271 | <a name="l00208"></a>00208 allocator.destruct(&data[i]); | ||
272 | <a name="l00209"></a>00209 | ||
273 | <a name="l00210"></a>00210 allocator.deallocate(data); <span class="comment">// delete [] data;</span> | ||
274 | <a name="l00211"></a>00211 } | ||
275 | <a name="l00212"></a>00212 data = 0; | ||
276 | <a name="l00213"></a>00213 used = 0; | ||
277 | <a name="l00214"></a>00214 allocated = 0; | ||
278 | <a name="l00215"></a>00215 is_sorted = <span class="keyword">true</span>; | ||
279 | <a name="l00216"></a>00216 } | ||
280 | <a name="l00217"></a>00217 | ||
281 | <a name="l00218"></a>00218 | ||
282 | <a name="l00220"></a>00220 | ||
283 | <a name="l00228"></a><a class="code" href="classirr_1_1core_1_1array.html#a75df5c46b08225d1ebe3c1381d85d9ff">00228</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#a75df5c46b08225d1ebe3c1381d85d9ff" title="Sets pointer to new array, using this as new workspace.">set_pointer</a>(T* newPointer, <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> <a class="code" href="classirr_1_1core_1_1array.html#abc592bab637d54799b6c86d6d0e8adf8" title="Get number of occupied elements of the array.">size</a>, <span class="keywordtype">bool</span> _is_sorted=<span class="keyword">false</span>, <span class="keywordtype">bool</span> _free_when_destroyed=<span class="keyword">true</span>) | ||
284 | <a name="l00229"></a>00229 { | ||
285 | <a name="l00230"></a>00230 <a class="code" href="classirr_1_1core_1_1array.html#a236e08ca44ddf3c2b47b726f90db8d39" title="Clears the array and deletes all allocated memory.">clear</a>(); | ||
286 | <a name="l00231"></a>00231 data = newPointer; | ||
287 | <a name="l00232"></a>00232 allocated = <a class="code" href="classirr_1_1core_1_1array.html#abc592bab637d54799b6c86d6d0e8adf8" title="Get number of occupied elements of the array.">size</a>; | ||
288 | <a name="l00233"></a>00233 used = <a class="code" href="classirr_1_1core_1_1array.html#abc592bab637d54799b6c86d6d0e8adf8" title="Get number of occupied elements of the array.">size</a>; | ||
289 | <a name="l00234"></a>00234 is_sorted = _is_sorted; | ||
290 | <a name="l00235"></a>00235 free_when_destroyed=_free_when_destroyed; | ||
291 | <a name="l00236"></a>00236 } | ||
292 | <a name="l00237"></a>00237 | ||
293 | <a name="l00238"></a>00238 | ||
294 | <a name="l00240"></a>00240 | ||
295 | <a name="l00247"></a><a class="code" href="classirr_1_1core_1_1array.html#afddd43e25d3ad6b1a3d75ceab13e6c56">00247</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#afddd43e25d3ad6b1a3d75ceab13e6c56" title="Sets if the array should delete the memory it uses upon destruction.">set_free_when_destroyed</a>(<span class="keywordtype">bool</span> f) | ||
296 | <a name="l00248"></a>00248 { | ||
297 | <a name="l00249"></a>00249 free_when_destroyed = f; | ||
298 | <a name="l00250"></a>00250 } | ||
299 | <a name="l00251"></a>00251 | ||
300 | <a name="l00252"></a>00252 | ||
301 | <a name="l00254"></a>00254 | ||
302 | <a name="l00257"></a><a class="code" href="classirr_1_1core_1_1array.html#a64d70ab89f03e2ec4deae3b6c0161305">00257</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#a64d70ab89f03e2ec4deae3b6c0161305" title="Sets the size of the array and allocates new elements if necessary.">set_used</a>(<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> usedNow) | ||
303 | <a name="l00258"></a>00258 { | ||
304 | <a name="l00259"></a>00259 <span class="keywordflow">if</span> (allocated < usedNow) | ||
305 | <a name="l00260"></a>00260 <a class="code" href="classirr_1_1core_1_1array.html#ada5735f409eca82b9031d993ee8b31c3" title="Reallocates the array, make it bigger or smaller.">reallocate</a>(usedNow); | ||
306 | <a name="l00261"></a>00261 | ||
307 | <a name="l00262"></a>00262 used = usedNow; | ||
308 | <a name="l00263"></a>00263 } | ||
309 | <a name="l00264"></a>00264 | ||
310 | <a name="l00265"></a>00265 | ||
311 | <a name="l00267"></a><a class="code" href="classirr_1_1core_1_1array.html#a51c964d180507ebdef872d93886c23b2">00267</a> <span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1array.html" title="Self reallocating template array (like stl vector) with additional features.">array<T, TAlloc></a>& <a class="code" href="classirr_1_1core_1_1array.html#a51c964d180507ebdef872d93886c23b2" title="Assignment operator.">operator=</a>(<span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1array.html" title="Self reallocating template array (like stl vector) with additional features.">array<T, TAlloc></a>& other) | ||
312 | <a name="l00268"></a>00268 { | ||
313 | <a name="l00269"></a>00269 <span class="keywordflow">if</span> (<span class="keyword">this</span> == &other) | ||
314 | <a name="l00270"></a>00270 <span class="keywordflow">return</span> *<span class="keyword">this</span>; | ||
315 | <a name="l00271"></a>00271 strategy = other.strategy; | ||
316 | <a name="l00272"></a>00272 | ||
317 | <a name="l00273"></a>00273 <span class="keywordflow">if</span> (data) | ||
318 | <a name="l00274"></a>00274 <a class="code" href="classirr_1_1core_1_1array.html#a236e08ca44ddf3c2b47b726f90db8d39" title="Clears the array and deletes all allocated memory.">clear</a>(); | ||
319 | <a name="l00275"></a>00275 | ||
320 | <a name="l00276"></a>00276 <span class="comment">//if (allocated < other.allocated)</span> | ||
321 | <a name="l00277"></a>00277 <span class="keywordflow">if</span> (other.allocated == 0) | ||
322 | <a name="l00278"></a>00278 data = 0; | ||
323 | <a name="l00279"></a>00279 <span class="keywordflow">else</span> | ||
324 | <a name="l00280"></a>00280 data = allocator.allocate(other.allocated); <span class="comment">// new T[other.allocated];</span> | ||
325 | <a name="l00281"></a>00281 | ||
326 | <a name="l00282"></a>00282 used = other.used; | ||
327 | <a name="l00283"></a>00283 free_when_destroyed = <span class="keyword">true</span>; | ||
328 | <a name="l00284"></a>00284 is_sorted = other.is_sorted; | ||
329 | <a name="l00285"></a>00285 allocated = other.allocated; | ||
330 | <a name="l00286"></a>00286 | ||
331 | <a name="l00287"></a>00287 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=0; i<other.used; ++i) | ||
332 | <a name="l00288"></a>00288 allocator.construct(&data[i], other.data[i]); <span class="comment">// data[i] = other.data[i];</span> | ||
333 | <a name="l00289"></a>00289 | ||
334 | <a name="l00290"></a>00290 <span class="keywordflow">return</span> *<span class="keyword">this</span>; | ||
335 | <a name="l00291"></a>00291 } | ||
336 | <a name="l00292"></a>00292 | ||
337 | <a name="l00293"></a>00293 | ||
338 | <a name="l00295"></a><a class="code" href="classirr_1_1core_1_1array.html#a718e705f3e3561c49ceee75afe0c3251">00295</a> <span class="keywordtype">bool</span> <a class="code" href="classirr_1_1core_1_1array.html#a718e705f3e3561c49ceee75afe0c3251" title="Equality operator.">operator == </a>(<span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1array.html" title="Self reallocating template array (like stl vector) with additional features.">array<T, TAlloc></a>& other)<span class="keyword"> const</span> | ||
339 | <a name="l00296"></a>00296 <span class="keyword"> </span>{ | ||
340 | <a name="l00297"></a>00297 <span class="keywordflow">if</span> (used != other.used) | ||
341 | <a name="l00298"></a>00298 <span class="keywordflow">return</span> <span class="keyword">false</span>; | ||
342 | <a name="l00299"></a>00299 | ||
343 | <a name="l00300"></a>00300 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=0; i<other.used; ++i) | ||
344 | <a name="l00301"></a>00301 <span class="keywordflow">if</span> (data[i] != other[i]) | ||
345 | <a name="l00302"></a>00302 <span class="keywordflow">return</span> <span class="keyword">false</span>; | ||
346 | <a name="l00303"></a>00303 <span class="keywordflow">return</span> <span class="keyword">true</span>; | ||
347 | <a name="l00304"></a>00304 } | ||
348 | <a name="l00305"></a>00305 | ||
349 | <a name="l00306"></a>00306 | ||
350 | <a name="l00308"></a><a class="code" href="classirr_1_1core_1_1array.html#a20f435e8fabd821b66ef34227c1fceae">00308</a> <span class="keywordtype">bool</span> <a class="code" href="classirr_1_1core_1_1array.html#a20f435e8fabd821b66ef34227c1fceae" title="Inequality operator.">operator != </a>(<span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1array.html" title="Self reallocating template array (like stl vector) with additional features.">array<T, TAlloc></a>& other)<span class="keyword"> const</span> | ||
351 | <a name="l00309"></a>00309 <span class="keyword"> </span>{ | ||
352 | <a name="l00310"></a>00310 <span class="keywordflow">return</span> !(*<span class="keyword">this</span>==other); | ||
353 | <a name="l00311"></a>00311 } | ||
354 | <a name="l00312"></a>00312 | ||
355 | <a name="l00313"></a>00313 | ||
356 | <a name="l00315"></a><a class="code" href="classirr_1_1core_1_1array.html#a1e09dc5cc93e88fd3a37cad011b3b531">00315</a> T& <a class="code" href="classirr_1_1core_1_1array.html#a1e09dc5cc93e88fd3a37cad011b3b531" title="Direct access operator.">operator []</a>(<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> index) | ||
357 | <a name="l00316"></a>00316 { | ||
358 | <a name="l00317"></a>00317 <a class="code" href="irr_types_8h.html#a12f3b5fd18ca108f90c5c74db602267e" title="define a break macro for debugging.">_IRR_DEBUG_BREAK_IF</a>(index>=used) <span class="comment">// access violation</span> | ||
359 | <a name="l00318"></a>00318 | ||
360 | <a name="l00319"></a>00319 <span class="keywordflow">return</span> data[index]; | ||
361 | <a name="l00320"></a>00320 } | ||
362 | <a name="l00321"></a>00321 | ||
363 | <a name="l00322"></a>00322 | ||
364 | <a name="l00324"></a><a class="code" href="classirr_1_1core_1_1array.html#a432981694ff74f416764bfbf71c76b4c">00324</a> <span class="keyword">const</span> T& <a class="code" href="classirr_1_1core_1_1array.html#a1e09dc5cc93e88fd3a37cad011b3b531" title="Direct access operator.">operator []</a>(<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> index)<span class="keyword"> const</span> | ||
365 | <a name="l00325"></a>00325 <span class="keyword"> </span>{ | ||
366 | <a name="l00326"></a>00326 <a class="code" href="irr_types_8h.html#a12f3b5fd18ca108f90c5c74db602267e" title="define a break macro for debugging.">_IRR_DEBUG_BREAK_IF</a>(index>=used) <span class="comment">// access violation</span> | ||
367 | <a name="l00327"></a>00327 | ||
368 | <a name="l00328"></a>00328 <span class="keywordflow">return</span> data[index]; | ||
369 | <a name="l00329"></a>00329 } | ||
370 | <a name="l00330"></a>00330 | ||
371 | <a name="l00331"></a>00331 | ||
372 | <a name="l00333"></a><a class="code" href="classirr_1_1core_1_1array.html#ad87dc5db8bf6ec1033c945a0d3724e09">00333</a> T& <a class="code" href="classirr_1_1core_1_1array.html#ad87dc5db8bf6ec1033c945a0d3724e09" title="Gets last element.">getLast</a>() | ||
373 | <a name="l00334"></a>00334 { | ||
374 | <a name="l00335"></a>00335 <a class="code" href="irr_types_8h.html#a12f3b5fd18ca108f90c5c74db602267e" title="define a break macro for debugging.">_IRR_DEBUG_BREAK_IF</a>(!used) <span class="comment">// access violation</span> | ||
375 | <a name="l00336"></a>00336 | ||
376 | <a name="l00337"></a>00337 <span class="keywordflow">return</span> data[used-1]; | ||
377 | <a name="l00338"></a>00338 } | ||
378 | <a name="l00339"></a>00339 | ||
379 | <a name="l00340"></a>00340 | ||
380 | <a name="l00342"></a><a class="code" href="classirr_1_1core_1_1array.html#ad531932175e210c17429878411490932">00342</a> <span class="keyword">const</span> T& <a class="code" href="classirr_1_1core_1_1array.html#ad87dc5db8bf6ec1033c945a0d3724e09" title="Gets last element.">getLast</a>()<span class="keyword"> const</span> | ||
381 | <a name="l00343"></a>00343 <span class="keyword"> </span>{ | ||
382 | <a name="l00344"></a>00344 <a class="code" href="irr_types_8h.html#a12f3b5fd18ca108f90c5c74db602267e" title="define a break macro for debugging.">_IRR_DEBUG_BREAK_IF</a>(!used) <span class="comment">// access violation</span> | ||
383 | <a name="l00345"></a>00345 | ||
384 | <a name="l00346"></a>00346 <span class="keywordflow">return</span> data[used-1]; | ||
385 | <a name="l00347"></a>00347 } | ||
386 | <a name="l00348"></a>00348 | ||
387 | <a name="l00349"></a>00349 | ||
388 | <a name="l00351"></a>00351 | ||
389 | <a name="l00352"></a><a class="code" href="classirr_1_1core_1_1array.html#a7b29797486e1c2ab3e7821082dab998c">00352</a> T* <a class="code" href="classirr_1_1core_1_1array.html#a7b29797486e1c2ab3e7821082dab998c" title="Gets a pointer to the array.">pointer</a>() | ||
390 | <a name="l00353"></a>00353 { | ||
391 | <a name="l00354"></a>00354 <span class="keywordflow">return</span> data; | ||
392 | <a name="l00355"></a>00355 } | ||
393 | <a name="l00356"></a>00356 | ||
394 | <a name="l00357"></a>00357 | ||
395 | <a name="l00359"></a>00359 | ||
396 | <a name="l00360"></a><a class="code" href="classirr_1_1core_1_1array.html#a8bf5bc844936a56632038524942f89f1">00360</a> <span class="keyword">const</span> T* <a class="code" href="classirr_1_1core_1_1array.html#a8bf5bc844936a56632038524942f89f1" title="Gets a const pointer to the array.">const_pointer</a>()<span class="keyword"> const</span> | ||
397 | <a name="l00361"></a>00361 <span class="keyword"> </span>{ | ||
398 | <a name="l00362"></a>00362 <span class="keywordflow">return</span> data; | ||
399 | <a name="l00363"></a>00363 } | ||
400 | <a name="l00364"></a>00364 | ||
401 | <a name="l00365"></a>00365 | ||
402 | <a name="l00367"></a>00367 | ||
403 | <a name="l00368"></a><a class="code" href="classirr_1_1core_1_1array.html#abc592bab637d54799b6c86d6d0e8adf8">00368</a> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> <a class="code" href="classirr_1_1core_1_1array.html#abc592bab637d54799b6c86d6d0e8adf8" title="Get number of occupied elements of the array.">size</a>()<span class="keyword"> const</span> | ||
404 | <a name="l00369"></a>00369 <span class="keyword"> </span>{ | ||
405 | <a name="l00370"></a>00370 <span class="keywordflow">return</span> used; | ||
406 | <a name="l00371"></a>00371 } | ||
407 | <a name="l00372"></a>00372 | ||
408 | <a name="l00373"></a>00373 | ||
409 | <a name="l00375"></a>00375 | ||
410 | <a name="l00377"></a><a class="code" href="classirr_1_1core_1_1array.html#a2a15ea5df83792bce4366969d5b164c4">00377</a> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> <a class="code" href="classirr_1_1core_1_1array.html#a2a15ea5df83792bce4366969d5b164c4" title="Get amount of memory allocated.">allocated_size</a>()<span class="keyword"> const</span> | ||
411 | <a name="l00378"></a>00378 <span class="keyword"> </span>{ | ||
412 | <a name="l00379"></a>00379 <span class="keywordflow">return</span> allocated; | ||
413 | <a name="l00380"></a>00380 } | ||
414 | <a name="l00381"></a>00381 | ||
415 | <a name="l00382"></a>00382 | ||
416 | <a name="l00384"></a>00384 | ||
417 | <a name="l00385"></a><a class="code" href="classirr_1_1core_1_1array.html#a1de2f5999968e104bf0ec6f057f097c2">00385</a> <span class="keywordtype">bool</span> <a class="code" href="classirr_1_1core_1_1array.html#a1de2f5999968e104bf0ec6f057f097c2" title="Check if array is empty.">empty</a>()<span class="keyword"> const</span> | ||
418 | <a name="l00386"></a>00386 <span class="keyword"> </span>{ | ||
419 | <a name="l00387"></a>00387 <span class="keywordflow">return</span> used == 0; | ||
420 | <a name="l00388"></a>00388 } | ||
421 | <a name="l00389"></a>00389 | ||
422 | <a name="l00390"></a>00390 | ||
423 | <a name="l00392"></a>00392 | ||
424 | <a name="l00394"></a><a class="code" href="classirr_1_1core_1_1array.html#a870e52dd57dd67a9d59e5ca5f82bca94">00394</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#a870e52dd57dd67a9d59e5ca5f82bca94" title="Sorts the array using heapsort.">sort</a>() | ||
425 | <a name="l00395"></a>00395 { | ||
426 | <a name="l00396"></a>00396 <span class="keywordflow">if</span> (!is_sorted && used>1) | ||
427 | <a name="l00397"></a>00397 <a class="code" href="namespaceirr_1_1core.html#aee38facdb42325b97626099d72f9a872" title="Sorts an array with size 'size' using heapsort.">heapsort</a>(data, used); | ||
428 | <a name="l00398"></a>00398 is_sorted = <span class="keyword">true</span>; | ||
429 | <a name="l00399"></a>00399 } | ||
430 | <a name="l00400"></a>00400 | ||
431 | <a name="l00401"></a>00401 | ||
432 | <a name="l00403"></a>00403 | ||
433 | <a name="l00409"></a><a class="code" href="classirr_1_1core_1_1array.html#a35412f669b983eaaf3792b82966db24a">00409</a> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="classirr_1_1core_1_1array.html#a35412f669b983eaaf3792b82966db24a" title="Performs a binary search for an element, returns -1 if not found.">binary_search</a>(<span class="keyword">const</span> T& element) | ||
434 | <a name="l00410"></a>00410 { | ||
435 | <a name="l00411"></a>00411 <a class="code" href="classirr_1_1core_1_1array.html#a870e52dd57dd67a9d59e5ca5f82bca94" title="Sorts the array using heapsort.">sort</a>(); | ||
436 | <a name="l00412"></a>00412 <span class="keywordflow">return</span> <a class="code" href="classirr_1_1core_1_1array.html#a35412f669b983eaaf3792b82966db24a" title="Performs a binary search for an element, returns -1 if not found.">binary_search</a>(element, 0, used-1); | ||
437 | <a name="l00413"></a>00413 } | ||
438 | <a name="l00414"></a>00414 | ||
439 | <a name="l00415"></a>00415 | ||
440 | <a name="l00417"></a>00417 | ||
441 | <a name="l00422"></a><a class="code" href="classirr_1_1core_1_1array.html#af9cd0644165ab0d40f97799acd3f2c22">00422</a> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="classirr_1_1core_1_1array.html#a35412f669b983eaaf3792b82966db24a" title="Performs a binary search for an element, returns -1 if not found.">binary_search</a>(<span class="keyword">const</span> T& element)<span class="keyword"> const</span> | ||
442 | <a name="l00423"></a>00423 <span class="keyword"> </span>{ | ||
443 | <a name="l00424"></a>00424 <span class="keywordflow">if</span> (is_sorted) | ||
444 | <a name="l00425"></a>00425 <span class="keywordflow">return</span> <a class="code" href="classirr_1_1core_1_1array.html#a35412f669b983eaaf3792b82966db24a" title="Performs a binary search for an element, returns -1 if not found.">binary_search</a>(element, 0, used-1); | ||
445 | <a name="l00426"></a>00426 <span class="keywordflow">else</span> | ||
446 | <a name="l00427"></a>00427 <span class="keywordflow">return</span> <a class="code" href="classirr_1_1core_1_1array.html#a06327f3b1a87117a57a617cbb7738beb" title="Finds an element in linear time, which is very slow.">linear_search</a>(element); | ||
447 | <a name="l00428"></a>00428 } | ||
448 | <a name="l00429"></a>00429 | ||
449 | <a name="l00430"></a>00430 | ||
450 | <a name="l00432"></a>00432 | ||
451 | <a name="l00437"></a><a class="code" href="classirr_1_1core_1_1array.html#ae2f68111b6899a63454d2956ee58ba6c">00437</a> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="classirr_1_1core_1_1array.html#a35412f669b983eaaf3792b82966db24a" title="Performs a binary search for an element, returns -1 if not found.">binary_search</a>(<span class="keyword">const</span> T& element, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> left, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> right)<span class="keyword"> const</span> | ||
452 | <a name="l00438"></a>00438 <span class="keyword"> </span>{ | ||
453 | <a name="l00439"></a>00439 <span class="keywordflow">if</span> (!used) | ||
454 | <a name="l00440"></a>00440 <span class="keywordflow">return</span> -1; | ||
455 | <a name="l00441"></a>00441 | ||
456 | <a name="l00442"></a>00442 <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> m; | ||
457 | <a name="l00443"></a>00443 | ||
458 | <a name="l00444"></a>00444 <span class="keywordflow">do</span> | ||
459 | <a name="l00445"></a>00445 { | ||
460 | <a name="l00446"></a>00446 m = (left+right)>>1; | ||
461 | <a name="l00447"></a>00447 | ||
462 | <a name="l00448"></a>00448 <span class="keywordflow">if</span> (element < data[m]) | ||
463 | <a name="l00449"></a>00449 right = m - 1; | ||
464 | <a name="l00450"></a>00450 <span class="keywordflow">else</span> | ||
465 | <a name="l00451"></a>00451 left = m + 1; | ||
466 | <a name="l00452"></a>00452 | ||
467 | <a name="l00453"></a>00453 } <span class="keywordflow">while</span>((element < data[m] || data[m] < element) && left<=right); | ||
468 | <a name="l00454"></a>00454 <span class="comment">// this last line equals to:</span> | ||
469 | <a name="l00455"></a>00455 <span class="comment">// " while((element != array[m]) && left<=right);"</span> | ||
470 | <a name="l00456"></a>00456 <span class="comment">// but we only want to use the '<' operator.</span> | ||
471 | <a name="l00457"></a>00457 <span class="comment">// the same in next line, it is "(element == array[m])"</span> | ||
472 | <a name="l00458"></a>00458 | ||
473 | <a name="l00459"></a>00459 | ||
474 | <a name="l00460"></a>00460 <span class="keywordflow">if</span> (!(element < data[m]) && !(data[m] < element)) | ||
475 | <a name="l00461"></a>00461 <span class="keywordflow">return</span> m; | ||
476 | <a name="l00462"></a>00462 | ||
477 | <a name="l00463"></a>00463 <span class="keywordflow">return</span> -1; | ||
478 | <a name="l00464"></a>00464 } | ||
479 | <a name="l00465"></a>00465 | ||
480 | <a name="l00466"></a>00466 | ||
481 | <a name="l00469"></a>00469 | ||
482 | <a name="l00475"></a><a class="code" href="classirr_1_1core_1_1array.html#a62821cac92125dd76f96f21e60ca94a4">00475</a> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="classirr_1_1core_1_1array.html#a62821cac92125dd76f96f21e60ca94a4">binary_search_multi</a>(<span class="keyword">const</span> T& element, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> &last) | ||
483 | <a name="l00476"></a>00476 { | ||
484 | <a name="l00477"></a>00477 <a class="code" href="classirr_1_1core_1_1array.html#a870e52dd57dd67a9d59e5ca5f82bca94" title="Sorts the array using heapsort.">sort</a>(); | ||
485 | <a name="l00478"></a>00478 <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> index = <a class="code" href="classirr_1_1core_1_1array.html#a35412f669b983eaaf3792b82966db24a" title="Performs a binary search for an element, returns -1 if not found.">binary_search</a>(element, 0, used-1); | ||
486 | <a name="l00479"></a>00479 <span class="keywordflow">if</span> ( index < 0 ) | ||
487 | <a name="l00480"></a>00480 <span class="keywordflow">return</span> index; | ||
488 | <a name="l00481"></a>00481 | ||
489 | <a name="l00482"></a>00482 <span class="comment">// The search can be somewhere in the middle of the set</span> | ||
490 | <a name="l00483"></a>00483 <span class="comment">// look linear previous and past the index</span> | ||
491 | <a name="l00484"></a>00484 last = index; | ||
492 | <a name="l00485"></a>00485 | ||
493 | <a name="l00486"></a>00486 <span class="keywordflow">while</span> ( index > 0 && !(element < data[index - 1]) && !(data[index - 1] < element) ) | ||
494 | <a name="l00487"></a>00487 { | ||
495 | <a name="l00488"></a>00488 index -= 1; | ||
496 | <a name="l00489"></a>00489 } | ||
497 | <a name="l00490"></a>00490 <span class="comment">// look linear up</span> | ||
498 | <a name="l00491"></a>00491 <span class="keywordflow">while</span> ( last < (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>) used - 1 && !(element < data[last + 1]) && !(data[last + 1] < element) ) | ||
499 | <a name="l00492"></a>00492 { | ||
500 | <a name="l00493"></a>00493 last += 1; | ||
501 | <a name="l00494"></a>00494 } | ||
502 | <a name="l00495"></a>00495 | ||
503 | <a name="l00496"></a>00496 <span class="keywordflow">return</span> index; | ||
504 | <a name="l00497"></a>00497 } | ||
505 | <a name="l00498"></a>00498 | ||
506 | <a name="l00499"></a>00499 | ||
507 | <a name="l00501"></a>00501 | ||
508 | <a name="l00506"></a><a class="code" href="classirr_1_1core_1_1array.html#a06327f3b1a87117a57a617cbb7738beb">00506</a> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="classirr_1_1core_1_1array.html#a06327f3b1a87117a57a617cbb7738beb" title="Finds an element in linear time, which is very slow.">linear_search</a>(<span class="keyword">const</span> T& element)<span class="keyword"> const</span> | ||
509 | <a name="l00507"></a>00507 <span class="keyword"> </span>{ | ||
510 | <a name="l00508"></a>00508 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=0; i<used; ++i) | ||
511 | <a name="l00509"></a>00509 <span class="keywordflow">if</span> (element == data[i]) | ||
512 | <a name="l00510"></a>00510 <span class="keywordflow">return</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>)i; | ||
513 | <a name="l00511"></a>00511 | ||
514 | <a name="l00512"></a>00512 <span class="keywordflow">return</span> -1; | ||
515 | <a name="l00513"></a>00513 } | ||
516 | <a name="l00514"></a>00514 | ||
517 | <a name="l00515"></a>00515 | ||
518 | <a name="l00517"></a>00517 | ||
519 | <a name="l00522"></a><a class="code" href="classirr_1_1core_1_1array.html#ac4a756f807ae06a74cc71cfd05dc22de">00522</a> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="classirr_1_1core_1_1array.html#ac4a756f807ae06a74cc71cfd05dc22de" title="Finds an element in linear time, which is very slow.">linear_reverse_search</a>(<span class="keyword">const</span> T& element)<span class="keyword"> const</span> | ||
520 | <a name="l00523"></a>00523 <span class="keyword"> </span>{ | ||
521 | <a name="l00524"></a>00524 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i=used-1; i>=0; --i) | ||
522 | <a name="l00525"></a>00525 <span class="keywordflow">if</span> (data[i] == element) | ||
523 | <a name="l00526"></a>00526 <span class="keywordflow">return</span> i; | ||
524 | <a name="l00527"></a>00527 | ||
525 | <a name="l00528"></a>00528 <span class="keywordflow">return</span> -1; | ||
526 | <a name="l00529"></a>00529 } | ||
527 | <a name="l00530"></a>00530 | ||
528 | <a name="l00531"></a>00531 | ||
529 | <a name="l00533"></a>00533 | ||
530 | <a name="l00536"></a><a class="code" href="classirr_1_1core_1_1array.html#a5ba14e37dddaecd9c3e813a78c157dc8">00536</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#a5ba14e37dddaecd9c3e813a78c157dc8" title="Erases an element from the array.">erase</a>(<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> index) | ||
531 | <a name="l00537"></a>00537 { | ||
532 | <a name="l00538"></a>00538 <a class="code" href="irr_types_8h.html#a12f3b5fd18ca108f90c5c74db602267e" title="define a break macro for debugging.">_IRR_DEBUG_BREAK_IF</a>(index>=used) <span class="comment">// access violation</span> | ||
533 | <a name="l00539"></a>00539 | ||
534 | <a name="l00540"></a>00540 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=index+1; i<used; ++i) | ||
535 | <a name="l00541"></a>00541 { | ||
536 | <a name="l00542"></a>00542 allocator.destruct(&data[i-1]); | ||
537 | <a name="l00543"></a>00543 allocator.construct(&data[i-1], data[i]); <span class="comment">// data[i-1] = data[i];</span> | ||
538 | <a name="l00544"></a>00544 } | ||
539 | <a name="l00545"></a>00545 | ||
540 | <a name="l00546"></a>00546 allocator.destruct(&data[used-1]); | ||
541 | <a name="l00547"></a>00547 | ||
542 | <a name="l00548"></a>00548 --used; | ||
543 | <a name="l00549"></a>00549 } | ||
544 | <a name="l00550"></a>00550 | ||
545 | <a name="l00551"></a>00551 | ||
546 | <a name="l00553"></a>00553 | ||
547 | <a name="l00557"></a><a class="code" href="classirr_1_1core_1_1array.html#ab9bb8cb0e6ebc4839fa2f7bc8e626800">00557</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#a5ba14e37dddaecd9c3e813a78c157dc8" title="Erases an element from the array.">erase</a>(<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> index, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> count) | ||
548 | <a name="l00558"></a>00558 { | ||
549 | <a name="l00559"></a>00559 <span class="keywordflow">if</span> (index>=used || count<1) | ||
550 | <a name="l00560"></a>00560 <span class="keywordflow">return</span>; | ||
551 | <a name="l00561"></a>00561 <span class="keywordflow">if</span> (index+count>used) | ||
552 | <a name="l00562"></a>00562 count = used-index; | ||
553 | <a name="l00563"></a>00563 | ||
554 | <a name="l00564"></a>00564 <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i; | ||
555 | <a name="l00565"></a>00565 <span class="keywordflow">for</span> (i=index; i<index+count; ++i) | ||
556 | <a name="l00566"></a>00566 allocator.destruct(&data[i]); | ||
557 | <a name="l00567"></a>00567 | ||
558 | <a name="l00568"></a>00568 <span class="keywordflow">for</span> (i=index+count; i<used; ++i) | ||
559 | <a name="l00569"></a>00569 { | ||
560 | <a name="l00570"></a>00570 <span class="keywordflow">if</span> (i-count >= index+count) <span class="comment">// not already destructed before loop</span> | ||
561 | <a name="l00571"></a>00571 allocator.destruct(&data[i-count]); | ||
562 | <a name="l00572"></a>00572 | ||
563 | <a name="l00573"></a>00573 allocator.construct(&data[i-count], data[i]); <span class="comment">// data[i-count] = data[i];</span> | ||
564 | <a name="l00574"></a>00574 | ||
565 | <a name="l00575"></a>00575 <span class="keywordflow">if</span> (i >= used-count) <span class="comment">// those which are not overwritten</span> | ||
566 | <a name="l00576"></a>00576 allocator.destruct(&data[i]); | ||
567 | <a name="l00577"></a>00577 } | ||
568 | <a name="l00578"></a>00578 | ||
569 | <a name="l00579"></a>00579 used-= count; | ||
570 | <a name="l00580"></a>00580 } | ||
571 | <a name="l00581"></a>00581 | ||
572 | <a name="l00582"></a>00582 | ||
573 | <a name="l00584"></a><a class="code" href="classirr_1_1core_1_1array.html#ab73d5838db931996f66f9efcc7127b49">00584</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#ab73d5838db931996f66f9efcc7127b49" title="Sets if the array is sorted.">set_sorted</a>(<span class="keywordtype">bool</span> _is_sorted) | ||
574 | <a name="l00585"></a>00585 { | ||
575 | <a name="l00586"></a>00586 is_sorted = _is_sorted; | ||
576 | <a name="l00587"></a>00587 } | ||
577 | <a name="l00588"></a>00588 | ||
578 | <a name="l00589"></a>00589 | ||
579 | <a name="l00591"></a>00591 | ||
580 | <a name="l00594"></a><a class="code" href="classirr_1_1core_1_1array.html#a8857046f500a2990fc9930b204a3dbad">00594</a> <span class="keywordtype">void</span> <a class="code" href="classirr_1_1core_1_1array.html#a8857046f500a2990fc9930b204a3dbad" title="Swap the content of this array container with the content of another array.">swap</a>(<a class="code" href="classirr_1_1core_1_1array.html" title="Self reallocating template array (like stl vector) with additional features.">array<T, TAlloc></a>& other) | ||
581 | <a name="l00595"></a>00595 { | ||
582 | <a name="l00596"></a>00596 <a class="code" href="classirr_1_1core_1_1array.html#a8857046f500a2990fc9930b204a3dbad" title="Swap the content of this array container with the content of another array.">core::swap</a>(data, other.data); | ||
583 | <a name="l00597"></a>00597 <a class="code" href="classirr_1_1core_1_1array.html#a8857046f500a2990fc9930b204a3dbad" title="Swap the content of this array container with the content of another array.">core::swap</a>(allocated, other.allocated); | ||
584 | <a name="l00598"></a>00598 <a class="code" href="classirr_1_1core_1_1array.html#a8857046f500a2990fc9930b204a3dbad" title="Swap the content of this array container with the content of another array.">core::swap</a>(used, other.used); | ||
585 | <a name="l00599"></a>00599 <a class="code" href="classirr_1_1core_1_1array.html#a8857046f500a2990fc9930b204a3dbad" title="Swap the content of this array container with the content of another array.">core::swap</a>(allocator, other.allocator); <span class="comment">// memory is still released by the same allocator used for allocation</span> | ||
586 | <a name="l00600"></a>00600 <a class="code" href="namespaceirr_1_1core.html#aa2e91971d5e6e84de235bfabe3c7adba" title="defines an allocation strategy">eAllocStrategy</a> helper_strategy(strategy); <span class="comment">// can't use core::swap with bitfields</span> | ||
587 | <a name="l00601"></a>00601 strategy = other.strategy; | ||
588 | <a name="l00602"></a>00602 other.strategy = helper_strategy; | ||
589 | <a name="l00603"></a>00603 <span class="keywordtype">bool</span> helper_free_when_destroyed(free_when_destroyed); | ||
590 | <a name="l00604"></a>00604 free_when_destroyed = other.free_when_destroyed; | ||
591 | <a name="l00605"></a>00605 other.free_when_destroyed = helper_free_when_destroyed; | ||
592 | <a name="l00606"></a>00606 <span class="keywordtype">bool</span> helper_is_sorted(is_sorted); | ||
593 | <a name="l00607"></a>00607 is_sorted = other.is_sorted; | ||
594 | <a name="l00608"></a>00608 other.is_sorted = helper_is_sorted; | ||
595 | <a name="l00609"></a>00609 } | ||
596 | <a name="l00610"></a>00610 | ||
597 | <a name="l00611"></a>00611 | ||
598 | <a name="l00612"></a>00612 <span class="keyword">private</span>: | ||
599 | <a name="l00613"></a>00613 T* data; | ||
600 | <a name="l00614"></a>00614 <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> allocated; | ||
601 | <a name="l00615"></a>00615 <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> used; | ||
602 | <a name="l00616"></a>00616 TAlloc allocator; | ||
603 | <a name="l00617"></a>00617 <a class="code" href="namespaceirr_1_1core.html#aa2e91971d5e6e84de235bfabe3c7adba" title="defines an allocation strategy">eAllocStrategy</a> strategy:4; | ||
604 | <a name="l00618"></a>00618 <span class="keywordtype">bool</span> free_when_destroyed:1; | ||
605 | <a name="l00619"></a>00619 <span class="keywordtype">bool</span> is_sorted:1; | ||
606 | <a name="l00620"></a>00620 }; | ||
607 | <a name="l00621"></a>00621 | ||
608 | <a name="l00622"></a>00622 | ||
609 | <a name="l00623"></a>00623 } <span class="comment">// end namespace core</span> | ||
610 | <a name="l00624"></a>00624 } <span class="comment">// end namespace irr</span> | ||
611 | <a name="l00625"></a>00625 | ||
612 | <a name="l00626"></a>00626 <span class="preprocessor">#endif</span> | ||
613 | <a name="l00627"></a>00627 <span class="preprocessor"></span> | ||
614 | </pre></div></div> | ||
615 | </div> | ||
616 | <div id="nav-path" class="navpath"> | ||
617 | <ul> | ||
618 | <li class="navelem"><a class="el" href="irr_array_8h.html">irrArray.h</a> </li> | ||
619 | <!-- window showing the filter options --> | ||
620 | <div id="MSearchSelectWindow" | ||
621 | onmouseover="return searchBox.OnSearchSelectShow()" | ||
622 | onmouseout="return searchBox.OnSearchSelectHide()" | ||
623 | onkeydown="return searchBox.OnSearchSelectKey(event)"> | ||
624 | <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark"> </span>Defines</a></div> | ||
625 | |||
626 | <!-- iframe showing the search results (closed by default) --> | ||
627 | <div id="MSearchResultsWindow"> | ||
628 | <iframe src="javascript:void(0)" frameborder="0" | ||
629 | name="MSearchResults" id="MSearchResults"> | ||
630 | </iframe> | ||
631 | </div> | ||
632 | |||
633 | |||
634 | <li class="footer"> | ||
635 | <a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht | ||
636 | Engine</a> Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on Sun Nov 17 2013 20:18:39 for Irrlicht 3D Engine by | ||
637 | <a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li> | ||
638 | </ul> | ||
639 | </div> | ||
640 | |||
641 | |||
642 | </body> | ||
643 | </html> | ||