mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-16 23:40:25 +01:00
644 lines
56 KiB
HTML
644 lines
56 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||
|
<title>Irrlicht 3D Engine: irrArray.h Source File</title>
|
||
|
|
||
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
||
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
||
|
<link href="navtree.css" rel="stylesheet" type="text/css"/>
|
||
|
<script type="text/javascript" src="jquery.js"></script>
|
||
|
<script type="text/javascript" src="resize.js"></script>
|
||
|
<script type="text/javascript" src="navtree.js"></script>
|
||
|
<script type="text/javascript">
|
||
|
$(document).ready(initResizable);
|
||
|
</script>
|
||
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
||
|
<script type="text/javascript" src="search/search.js"></script>
|
||
|
<script type="text/javascript">
|
||
|
$(document).ready(function() { searchBox.OnSelectItem(0); });
|
||
|
</script>
|
||
|
|
||
|
</head>
|
||
|
<body>
|
||
|
<div id="top"><!-- do not remove this div! -->
|
||
|
|
||
|
|
||
|
<div id="titlearea">
|
||
|
<table cellspacing="0" cellpadding="0">
|
||
|
<tbody>
|
||
|
<tr style="height: 56px;">
|
||
|
|
||
|
<td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
|
||
|
|
||
|
|
||
|
<td style="padding-left: 0.5em;">
|
||
|
<div id="projectname">Irrlicht 3D Engine
|
||
|
|
||
|
</div>
|
||
|
|
||
|
</td>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<td> <div id="MSearchBox" class="MSearchBoxInactive">
|
||
|
<span class="left">
|
||
|
<img id="MSearchSelect" src="search/mag_sel.png"
|
||
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
||
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
||
|
alt=""/>
|
||
|
<input type="text" id="MSearchField" value="Search" accesskey="S"
|
||
|
onfocus="searchBox.OnSearchFieldFocus(true)"
|
||
|
onblur="searchBox.OnSearchFieldFocus(false)"
|
||
|
onkeyup="searchBox.OnSearchFieldChange(event)"/>
|
||
|
</span><span class="right">
|
||
|
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
|
||
|
</span>
|
||
|
</div>
|
||
|
</td>
|
||
|
|
||
|
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
|
||
|
<!-- Generated by Doxygen 1.7.5.1 -->
|
||
|
<script type="text/javascript">
|
||
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||
|
</script>
|
||
|
<script type="text/javascript" src="dynsections.js"></script>
|
||
|
</div>
|
||
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
||
|
<div id="nav-tree">
|
||
|
<div id="nav-tree-contents">
|
||
|
</div>
|
||
|
</div>
|
||
|
<div id="splitbar" style="-moz-user-select:none;"
|
||
|
class="ui-resizable-handle">
|
||
|
</div>
|
||
|
</div>
|
||
|
<script type="text/javascript">
|
||
|
initNavTree('irr_array_8h.html','');
|
||
|
</script>
|
||
|
<div id="doc-content">
|
||
|
<div class="header">
|
||
|
<div class="headertitle">
|
||
|
<div class="title">irrArray.h</div> </div>
|
||
|
</div>
|
||
|
<div class="contents">
|
||
|
<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>
|
||
|
<a name="l00002"></a>00002 <span class="comment">// This file is part of the "Irrlicht Engine" and the "irrXML" project.</span>
|
||
|
<a name="l00003"></a>00003 <span class="comment">// For conditions of distribution and use, see copyright notice in irrlicht.h and irrXML.h</span>
|
||
|
<a name="l00004"></a>00004
|
||
|
<a name="l00005"></a>00005 <span class="preprocessor">#ifndef __IRR_ARRAY_H_INCLUDED__</span>
|
||
|
<a name="l00006"></a>00006 <span class="preprocessor"></span><span class="preprocessor">#define __IRR_ARRAY_H_INCLUDED__</span>
|
||
|
<a name="l00007"></a>00007 <span class="preprocessor"></span>
|
||
|
<a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="irr_types_8h.html">irrTypes.h</a>"</span>
|
||
|
<a name="l00009"></a>00009 <span class="preprocessor">#include "<a class="code" href="heapsort_8h.html">heapsort.h</a>"</span>
|
||
|
<a name="l00010"></a>00010 <span class="preprocessor">#include "<a class="code" href="irr_allocator_8h.html">irrAllocator.h</a>"</span>
|
||
|
<a name="l00011"></a>00011 <span class="preprocessor">#include "<a class="code" href="irr_math_8h.html">irrMath.h</a>"</span>
|
||
|
<a name="l00012"></a>00012
|
||
|
<a name="l00013"></a>00013 <span class="keyword">namespace </span>irr
|
||
|
<a name="l00014"></a>00014 {
|
||
|
<a name="l00015"></a>00015 <span class="keyword">namespace </span>core
|
||
|
<a name="l00016"></a>00016 {
|
||
|
<a name="l00017"></a>00017
|
||
|
<a name="l00019"></a>00019
|
||
|
<a name="l00021"></a>00021 <span class="keyword">template</span> <<span class="keyword">class</span> T, <span class="keyword">typename</span> TAlloc = irrAllocator<T> >
|
||
|
<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>
|
||
|
<a name="l00023"></a>00023 {
|
||
|
<a name="l00024"></a>00024
|
||
|
<a name="l00025"></a>00025 <span class="keyword">public</span>:
|
||
|
<a name="l00026"></a>00026
|
||
|
<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>()
|
||
|
<a name="l00029"></a>00029 : data(0), allocated(0), used(0),
|
||
|
<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)
|
||
|
<a name="l00031"></a>00031 {
|
||
|
<a name="l00032"></a>00032 }
|
||
|
<a name="l00033"></a>00033
|
||
|
<a name="l00034"></a>00034
|
||
|
<a name="l00036"></a>00036
|
||
|
<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)
|
||
|
<a name="l00038"></a>00038 : data(0), allocated(0), used(0),
|
||
|
<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)
|
||
|
<a name="l00040"></a>00040 {
|
||
|
<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);
|
||
|
<a name="l00042"></a>00042 }
|
||
|
<a name="l00043"></a>00043
|
||
|
<a name="l00044"></a>00044
|
||
|
<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)
|
||
|
<a name="l00047"></a>00047 {
|
||
|
<a name="l00048"></a>00048 *<span class="keyword">this</span> = other;
|
||
|
<a name="l00049"></a>00049 }
|
||
|
<a name="l00050"></a>00050
|
||
|
<a name="l00051"></a>00051
|
||
|
<a name="l00053"></a>00053
|
||
|
<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>()
|
||
|
<a name="l00056"></a>00056 {
|
||
|
<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>();
|
||
|
<a name="l00058"></a>00058 }
|
||
|
<a name="l00059"></a>00059
|
||
|
<a name="l00060"></a>00060
|
||
|
<a name="l00062"></a>00062
|
||
|
<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>)
|
||
|
<a name="l00068"></a>00068 {
|
||
|
<a name="l00069"></a>00069 <span class="keywordflow">if</span> (allocated==new_size)
|
||
|
<a name="l00070"></a>00070 <span class="keywordflow">return</span>;
|
||
|
<a name="l00071"></a>00071 <span class="keywordflow">if</span> (!canShrink && (new_size < allocated))
|
||
|
<a name="l00072"></a>00072 <span class="keywordflow">return</span>;
|
||
|
<a name="l00073"></a>00073
|
||
|
<a name="l00074"></a>00074 T* old_data = data;
|
||
|
<a name="l00075"></a>00075
|
||
|
<a name="l00076"></a>00076 data = allocator.allocate(new_size); <span class="comment">//new T[new_size];</span>
|
||
|
<a name="l00077"></a>00077 allocated = new_size;
|
||
|
<a name="l00078"></a>00078
|
||
|
<a name="l00079"></a>00079 <span class="comment">// copy old data</span>
|
||
|
<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;
|
||
|
<a name="l00081"></a>00081
|
||
|
<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)
|
||
|
<a name="l00083"></a>00083 {
|
||
|
<a name="l00084"></a>00084 <span class="comment">// data[i] = old_data[i];</span>
|
||
|
<a name="l00085"></a>00085 allocator.construct(&data[i], old_data[i]);
|
||
|
<a name="l00086"></a>00086 }
|
||
|
<a name="l00087"></a>00087
|
||
|
<a name="l00088"></a>00088 <span class="comment">// destruct old data</span>
|
||
|
<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)
|
||
|
<a name="l00090"></a>00090 allocator.destruct(&old_data[j]);
|
||
|
<a name="l00091"></a>00091
|
||
|
<a name="l00092"></a>00092 <span class="keywordflow">if</span> (allocated < used)
|
||
|
<a name="l00093"></a>00093 used = allocated;
|
||
|
<a name="l00094"></a>00094
|
||
|
<a name="l00095"></a>00095 allocator.deallocate(old_data); <span class="comment">//delete [] old_data;</span>
|
||
|
<a name="l00096"></a>00096 }
|
||
|
<a name="l00097"></a>00097
|
||
|
<a name="l00098"></a>00098
|
||
|
<a name="l00100"></a>00100
|
||
|
<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> )
|
||
|
<a name="l00104"></a>00104 {
|
||
|
<a name="l00105"></a>00105 strategy = newStrategy;
|
||
|
<a name="l00106"></a>00106 }
|
||
|
<a name="l00107"></a>00107
|
||
|
<a name="l00108"></a>00108
|
||
|
<a name="l00110"></a>00110
|
||
|
<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)
|
||
|
<a name="l00113"></a>00113 {
|
||
|
<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);
|
||
|
<a name="l00115"></a>00115 }
|
||
|
<a name="l00116"></a>00116
|
||
|
<a name="l00117"></a>00117
|
||
|
<a name="l00119"></a>00119
|
||
|
<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)
|
||
|
<a name="l00124"></a>00124 {
|
||
|
<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);
|
||
|
<a name="l00126"></a>00126 }
|
||
|
<a name="l00127"></a>00127
|
||
|
<a name="l00128"></a>00128
|
||
|
<a name="l00130"></a>00130
|
||
|
<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)
|
||
|
<a name="l00136"></a>00136 {
|
||
|
<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>
|
||
|
<a name="l00138"></a>00138
|
||
|
<a name="l00139"></a>00139 <span class="keywordflow">if</span> (used + 1 > allocated)
|
||
|
<a name="l00140"></a>00140 {
|
||
|
<a name="l00141"></a>00141 <span class="comment">// this doesn't work if the element is in the same</span>
|
||
|
<a name="l00142"></a>00142 <span class="comment">// array. So we'll copy the element first to be sure</span>
|
||
|
<a name="l00143"></a>00143 <span class="comment">// we'll get no data corruption</span>
|
||
|
<a name="l00144"></a>00144 <span class="keyword">const</span> T e(element);
|
||
|
<a name="l00145"></a>00145
|
||
|
<a name="l00146"></a>00146 <span class="comment">// increase data block</span>
|
||
|
<a name="l00147"></a>00147 <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> newAlloc;
|
||
|
<a name="l00148"></a>00148 <span class="keywordflow">switch</span> ( strategy )
|
||
|
<a name="l00149"></a>00149 {
|
||
|
<a name="l00150"></a>00150 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1core.html#aa2e91971d5e6e84de235bfabe3c7adbaa1fa5aed132891361601560ed3e067fe8">ALLOC_STRATEGY_DOUBLE</a>:
|
||
|
<a name="l00151"></a>00151 newAlloc = used + 1 + (allocated < 500 ?
|
||
|
<a name="l00152"></a>00152 (allocated < 5 ? 5 : used) : used >> 2);
|
||
|
<a name="l00153"></a>00153 <span class="keywordflow">break</span>;
|
||
|
<a name="l00154"></a>00154 <span class="keywordflow">default</span>:
|
||
|
<a name="l00155"></a>00155 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1core.html#aa2e91971d5e6e84de235bfabe3c7adbaabfc6be96075564e1e0d92477e657f746">ALLOC_STRATEGY_SAFE</a>:
|
||
|
<a name="l00156"></a>00156 newAlloc = used + 1;
|
||
|
<a name="l00157"></a>00157 <span class="keywordflow">break</span>;
|
||
|
<a name="l00158"></a>00158 }
|
||
|
<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);
|
||
|
<a name="l00160"></a>00160
|
||
|
<a name="l00161"></a>00161 <span class="comment">// move array content and construct new element</span>
|
||
|
<a name="l00162"></a>00162 <span class="comment">// first move end one up</span>
|
||
|
<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)
|
||
|
<a name="l00164"></a>00164 {
|
||
|
<a name="l00165"></a>00165 <span class="keywordflow">if</span> (i<used)
|
||
|
<a name="l00166"></a>00166 allocator.destruct(&data[i]);
|
||
|
<a name="l00167"></a>00167 allocator.construct(&data[i], data[i-1]); <span class="comment">// data[i] = data[i-1];</span>
|
||
|
<a name="l00168"></a>00168 }
|
||
|
<a name="l00169"></a>00169 <span class="comment">// then add new element</span>
|
||
|
<a name="l00170"></a>00170 <span class="keywordflow">if</span> (used > index)
|
||
|
<a name="l00171"></a>00171 allocator.destruct(&data[index]);
|
||
|
<a name="l00172"></a>00172 allocator.construct(&data[index], e); <span class="comment">// data[index] = e;</span>
|
||
|
<a name="l00173"></a>00173 }
|
||
|
<a name="l00174"></a>00174 <span class="keywordflow">else</span>
|
||
|
<a name="l00175"></a>00175 {
|
||
|
<a name="l00176"></a>00176 <span class="comment">// element inserted not at end</span>
|
||
|
<a name="l00177"></a>00177 <span class="keywordflow">if</span> ( used > index )
|
||
|
<a name="l00178"></a>00178 {
|
||
|
<a name="l00179"></a>00179 <span class="comment">// create one new element at the end</span>
|
||
|
<a name="l00180"></a>00180 allocator.construct(&data[used], data[used-1]);
|
||
|
<a name="l00181"></a>00181
|
||
|
<a name="l00182"></a>00182 <span class="comment">// move the rest of the array content</span>
|
||
|
<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)
|
||
|
<a name="l00184"></a>00184 {
|
||
|
<a name="l00185"></a>00185 data[i] = data[i-1];
|
||
|
<a name="l00186"></a>00186 }
|
||
|
<a name="l00187"></a>00187 <span class="comment">// insert the new element</span>
|
||
|
<a name="l00188"></a>00188 data[index] = element;
|
||
|
<a name="l00189"></a>00189 }
|
||
|
<a name="l00190"></a>00190 <span class="keywordflow">else</span>
|
||
|
<a name="l00191"></a>00191 {
|
||
|
<a name="l00192"></a>00192 <span class="comment">// insert the new element to the end</span>
|
||
|
<a name="l00193"></a>00193 allocator.construct(&data[index], element);
|
||
|
<a name="l00194"></a>00194 }
|
||
|
<a name="l00195"></a>00195 }
|
||
|
<a name="l00196"></a>00196 <span class="comment">// set to false as we don't know if we have the comparison operators</span>
|
||
|
<a name="l00197"></a>00197 is_sorted = <span class="keyword">false</span>;
|
||
|
<a name="l00198"></a>00198 ++used;
|
||
|
<a name="l00199"></a>00199 }
|
||
|
<a name="l00200"></a>00200
|
||
|
<a name="l00201"></a>00201
|
||
|
<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>()
|
||
|
<a name="l00204"></a>00204 {
|
||
|
<a name="l00205"></a>00205 <span class="keywordflow">if</span> (free_when_destroyed)
|
||
|
<a name="l00206"></a>00206 {
|
||
|
<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)
|
||
|
<a name="l00208"></a>00208 allocator.destruct(&data[i]);
|
||
|
<a name="l00209"></a>00209
|
||
|
<a name="l00210"></a>00210 allocator.deallocate(data); <span class="comment">// delete [] data;</span>
|
||
|
<a name="l00211"></a>00211 }
|
||
|
<a name="l00212"></a>00212 data = 0;
|
||
|
<a name="l00213"></a>00213 used = 0;
|
||
|
<a name="l00214"></a>00214 allocated = 0;
|
||
|
<a name="l00215"></a>00215 is_sorted = <span class="keyword">true</span>;
|
||
|
<a name="l00216"></a>00216 }
|
||
|
<a name="l00217"></a>00217
|
||
|
<a name="l00218"></a>00218
|
||
|
<a name="l00220"></a>00220
|
||
|
<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>)
|
||
|
<a name="l00229"></a>00229 {
|
||
|
<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>();
|
||
|
<a name="l00231"></a>00231 data = newPointer;
|
||
|
<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>;
|
||
|
<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>;
|
||
|
<a name="l00234"></a>00234 is_sorted = _is_sorted;
|
||
|
<a name="l00235"></a>00235 free_when_destroyed=_free_when_destroyed;
|
||
|
<a name="l00236"></a>00236 }
|
||
|
<a name="l00237"></a>00237
|
||
|
<a name="l00238"></a>00238
|
||
|
<a name="l00240"></a>00240
|
||
|
<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)
|
||
|
<a name="l00248"></a>00248 {
|
||
|
<a name="l00249"></a>00249 free_when_destroyed = f;
|
||
|
<a name="l00250"></a>00250 }
|
||
|
<a name="l00251"></a>00251
|
||
|
<a name="l00252"></a>00252
|
||
|
<a name="l00254"></a>00254
|
||
|
<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)
|
||
|
<a name="l00258"></a>00258 {
|
||
|
<a name="l00259"></a>00259 <span class="keywordflow">if</span> (allocated < usedNow)
|
||
|
<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);
|
||
|
<a name="l00261"></a>00261
|
||
|
<a name="l00262"></a>00262 used = usedNow;
|
||
|
<a name="l00263"></a>00263 }
|
||
|
<a name="l00264"></a>00264
|
||
|
<a name="l00265"></a>00265
|
||
|
<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)
|
||
|
<a name="l00268"></a>00268 {
|
||
|
<a name="l00269"></a>00269 <span class="keywordflow">if</span> (<span class="keyword">this</span> == &other)
|
||
|
<a name="l00270"></a>00270 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
|
||
|
<a name="l00271"></a>00271 strategy = other.strategy;
|
||
|
<a name="l00272"></a>00272
|
||
|
<a name="l00273"></a>00273 <span class="keywordflow">if</span> (data)
|
||
|
<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>();
|
||
|
<a name="l00275"></a>00275
|
||
|
<a name="l00276"></a>00276 <span class="comment">//if (allocated < other.allocated)</span>
|
||
|
<a name="l00277"></a>00277 <span class="keywordflow">if</span> (other.allocated == 0)
|
||
|
<a name="l00278"></a>00278 data = 0;
|
||
|
<a name="l00279"></a>00279 <span class="keywordflow">else</span>
|
||
|
<a name="l00280"></a>00280 data = allocator.allocate(other.allocated); <span class="comment">// new T[other.allocated];</span>
|
||
|
<a name="l00281"></a>00281
|
||
|
<a name="l00282"></a>00282 used = other.used;
|
||
|
<a name="l00283"></a>00283 free_when_destroyed = <span class="keyword">true</span>;
|
||
|
<a name="l00284"></a>00284 is_sorted = other.is_sorted;
|
||
|
<a name="l00285"></a>00285 allocated = other.allocated;
|
||
|
<a name="l00286"></a>00286
|
||
|
<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)
|
||
|
<a name="l00288"></a>00288 allocator.construct(&data[i], other.data[i]); <span class="comment">// data[i] = other.data[i];</span>
|
||
|
<a name="l00289"></a>00289
|
||
|
<a name="l00290"></a>00290 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
|
||
|
<a name="l00291"></a>00291 }
|
||
|
<a name="l00292"></a>00292
|
||
|
<a name="l00293"></a>00293
|
||
|
<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>
|
||
|
<a name="l00296"></a>00296 <span class="keyword"> </span>{
|
||
|
<a name="l00297"></a>00297 <span class="keywordflow">if</span> (used != other.used)
|
||
|
<a name="l00298"></a>00298 <span class="keywordflow">return</span> <span class="keyword">false</span>;
|
||
|
<a name="l00299"></a>00299
|
||
|
<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)
|
||
|
<a name="l00301"></a>00301 <span class="keywordflow">if</span> (data[i] != other[i])
|
||
|
<a name="l00302"></a>00302 <span class="keywordflow">return</span> <span class="keyword">false</span>;
|
||
|
<a name="l00303"></a>00303 <span class="keywordflow">return</span> <span class="keyword">true</span>;
|
||
|
<a name="l00304"></a>00304 }
|
||
|
<a name="l00305"></a>00305
|
||
|
<a name="l00306"></a>00306
|
||
|
<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>
|
||
|
<a name="l00309"></a>00309 <span class="keyword"> </span>{
|
||
|
<a name="l00310"></a>00310 <span class="keywordflow">return</span> !(*<span class="keyword">this</span>==other);
|
||
|
<a name="l00311"></a>00311 }
|
||
|
<a name="l00312"></a>00312
|
||
|
<a name="l00313"></a>00313
|
||
|
<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)
|
||
|
<a name="l00316"></a>00316 {
|
||
|
<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>
|
||
|
<a name="l00318"></a>00318
|
||
|
<a name="l00319"></a>00319 <span class="keywordflow">return</span> data[index];
|
||
|
<a name="l00320"></a>00320 }
|
||
|
<a name="l00321"></a>00321
|
||
|
<a name="l00322"></a>00322
|
||
|
<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>
|
||
|
<a name="l00325"></a>00325 <span class="keyword"> </span>{
|
||
|
<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>
|
||
|
<a name="l00327"></a>00327
|
||
|
<a name="l00328"></a>00328 <span class="keywordflow">return</span> data[index];
|
||
|
<a name="l00329"></a>00329 }
|
||
|
<a name="l00330"></a>00330
|
||
|
<a name="l00331"></a>00331
|
||
|
<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>()
|
||
|
<a name="l00334"></a>00334 {
|
||
|
<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>
|
||
|
<a name="l00336"></a>00336
|
||
|
<a name="l00337"></a>00337 <span class="keywordflow">return</span> data[used-1];
|
||
|
<a name="l00338"></a>00338 }
|
||
|
<a name="l00339"></a>00339
|
||
|
<a name="l00340"></a>00340
|
||
|
<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>
|
||
|
<a name="l00343"></a>00343 <span class="keyword"> </span>{
|
||
|
<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>
|
||
|
<a name="l00345"></a>00345
|
||
|
<a name="l00346"></a>00346 <span class="keywordflow">return</span> data[used-1];
|
||
|
<a name="l00347"></a>00347 }
|
||
|
<a name="l00348"></a>00348
|
||
|
<a name="l00349"></a>00349
|
||
|
<a name="l00351"></a>00351
|
||
|
<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>()
|
||
|
<a name="l00353"></a>00353 {
|
||
|
<a name="l00354"></a>00354 <span class="keywordflow">return</span> data;
|
||
|
<a name="l00355"></a>00355 }
|
||
|
<a name="l00356"></a>00356
|
||
|
<a name="l00357"></a>00357
|
||
|
<a name="l00359"></a>00359
|
||
|
<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>
|
||
|
<a name="l00361"></a>00361 <span class="keyword"> </span>{
|
||
|
<a name="l00362"></a>00362 <span class="keywordflow">return</span> data;
|
||
|
<a name="l00363"></a>00363 }
|
||
|
<a name="l00364"></a>00364
|
||
|
<a name="l00365"></a>00365
|
||
|
<a name="l00367"></a>00367
|
||
|
<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>
|
||
|
<a name="l00369"></a>00369 <span class="keyword"> </span>{
|
||
|
<a name="l00370"></a>00370 <span class="keywordflow">return</span> used;
|
||
|
<a name="l00371"></a>00371 }
|
||
|
<a name="l00372"></a>00372
|
||
|
<a name="l00373"></a>00373
|
||
|
<a name="l00375"></a>00375
|
||
|
<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>
|
||
|
<a name="l00378"></a>00378 <span class="keyword"> </span>{
|
||
|
<a name="l00379"></a>00379 <span class="keywordflow">return</span> allocated;
|
||
|
<a name="l00380"></a>00380 }
|
||
|
<a name="l00381"></a>00381
|
||
|
<a name="l00382"></a>00382
|
||
|
<a name="l00384"></a>00384
|
||
|
<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>
|
||
|
<a name="l00386"></a>00386 <span class="keyword"> </span>{
|
||
|
<a name="l00387"></a>00387 <span class="keywordflow">return</span> used == 0;
|
||
|
<a name="l00388"></a>00388 }
|
||
|
<a name="l00389"></a>00389
|
||
|
<a name="l00390"></a>00390
|
||
|
<a name="l00392"></a>00392
|
||
|
<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>()
|
||
|
<a name="l00395"></a>00395 {
|
||
|
<a name="l00396"></a>00396 <span class="keywordflow">if</span> (!is_sorted && used>1)
|
||
|
<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);
|
||
|
<a name="l00398"></a>00398 is_sorted = <span class="keyword">true</span>;
|
||
|
<a name="l00399"></a>00399 }
|
||
|
<a name="l00400"></a>00400
|
||
|
<a name="l00401"></a>00401
|
||
|
<a name="l00403"></a>00403
|
||
|
<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)
|
||
|
<a name="l00410"></a>00410 {
|
||
|
<a name="l00411"></a>00411 <a class="code" href="classirr_1_1core_1_1array.html#a870e52dd57dd67a9d59e5ca5f82bca94" title="Sorts the array using heapsort.">sort</a>();
|
||
|
<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);
|
||
|
<a name="l00413"></a>00413 }
|
||
|
<a name="l00414"></a>00414
|
||
|
<a name="l00415"></a>00415
|
||
|
<a name="l00417"></a>00417
|
||
|
<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>
|
||
|
<a name="l00423"></a>00423 <span class="keyword"> </span>{
|
||
|
<a name="l00424"></a>00424 <span class="keywordflow">if</span> (is_sorted)
|
||
|
<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);
|
||
|
<a name="l00426"></a>00426 <span class="keywordflow">else</span>
|
||
|
<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);
|
||
|
<a name="l00428"></a>00428 }
|
||
|
<a name="l00429"></a>00429
|
||
|
<a name="l00430"></a>00430
|
||
|
<a name="l00432"></a>00432
|
||
|
<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>
|
||
|
<a name="l00438"></a>00438 <span class="keyword"> </span>{
|
||
|
<a name="l00439"></a>00439 <span class="keywordflow">if</span> (!used)
|
||
|
<a name="l00440"></a>00440 <span class="keywordflow">return</span> -1;
|
||
|
<a name="l00441"></a>00441
|
||
|
<a name="l00442"></a>00442 <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> m;
|
||
|
<a name="l00443"></a>00443
|
||
|
<a name="l00444"></a>00444 <span class="keywordflow">do</span>
|
||
|
<a name="l00445"></a>00445 {
|
||
|
<a name="l00446"></a>00446 m = (left+right)>>1;
|
||
|
<a name="l00447"></a>00447
|
||
|
<a name="l00448"></a>00448 <span class="keywordflow">if</span> (element < data[m])
|
||
|
<a name="l00449"></a>00449 right = m - 1;
|
||
|
<a name="l00450"></a>00450 <span class="keywordflow">else</span>
|
||
|
<a name="l00451"></a>00451 left = m + 1;
|
||
|
<a name="l00452"></a>00452
|
||
|
<a name="l00453"></a>00453 } <span class="keywordflow">while</span>((element < data[m] || data[m] < element) && left<=right);
|
||
|
<a name="l00454"></a>00454 <span class="comment">// this last line equals to:</span>
|
||
|
<a name="l00455"></a>00455 <span class="comment">// " while((element != array[m]) && left<=right);"</span>
|
||
|
<a name="l00456"></a>00456 <span class="comment">// but we only want to use the '<' operator.</span>
|
||
|
<a name="l00457"></a>00457 <span class="comment">// the same in next line, it is "(element == array[m])"</span>
|
||
|
<a name="l00458"></a>00458
|
||
|
<a name="l00459"></a>00459
|
||
|
<a name="l00460"></a>00460 <span class="keywordflow">if</span> (!(element < data[m]) && !(data[m] < element))
|
||
|
<a name="l00461"></a>00461 <span class="keywordflow">return</span> m;
|
||
|
<a name="l00462"></a>00462
|
||
|
<a name="l00463"></a>00463 <span class="keywordflow">return</span> -1;
|
||
|
<a name="l00464"></a>00464 }
|
||
|
<a name="l00465"></a>00465
|
||
|
<a name="l00466"></a>00466
|
||
|
<a name="l00469"></a>00469
|
||
|
<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)
|
||
|
<a name="l00476"></a>00476 {
|
||
|
<a name="l00477"></a>00477 <a class="code" href="classirr_1_1core_1_1array.html#a870e52dd57dd67a9d59e5ca5f82bca94" title="Sorts the array using heapsort.">sort</a>();
|
||
|
<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);
|
||
|
<a name="l00479"></a>00479 <span class="keywordflow">if</span> ( index < 0 )
|
||
|
<a name="l00480"></a>00480 <span class="keywordflow">return</span> index;
|
||
|
<a name="l00481"></a>00481
|
||
|
<a name="l00482"></a>00482 <span class="comment">// The search can be somewhere in the middle of the set</span>
|
||
|
<a name="l00483"></a>00483 <span class="comment">// look linear previous and past the index</span>
|
||
|
<a name="l00484"></a>00484 last = index;
|
||
|
<a name="l00485"></a>00485
|
||
|
<a name="l00486"></a>00486 <span class="keywordflow">while</span> ( index > 0 && !(element < data[index - 1]) && !(data[index - 1] < element) )
|
||
|
<a name="l00487"></a>00487 {
|
||
|
<a name="l00488"></a>00488 index -= 1;
|
||
|
<a name="l00489"></a>00489 }
|
||
|
<a name="l00490"></a>00490 <span class="comment">// look linear up</span>
|
||
|
<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) )
|
||
|
<a name="l00492"></a>00492 {
|
||
|
<a name="l00493"></a>00493 last += 1;
|
||
|
<a name="l00494"></a>00494 }
|
||
|
<a name="l00495"></a>00495
|
||
|
<a name="l00496"></a>00496 <span class="keywordflow">return</span> index;
|
||
|
<a name="l00497"></a>00497 }
|
||
|
<a name="l00498"></a>00498
|
||
|
<a name="l00499"></a>00499
|
||
|
<a name="l00501"></a>00501
|
||
|
<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>
|
||
|
<a name="l00507"></a>00507 <span class="keyword"> </span>{
|
||
|
<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)
|
||
|
<a name="l00509"></a>00509 <span class="keywordflow">if</span> (element == data[i])
|
||
|
<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;
|
||
|
<a name="l00511"></a>00511
|
||
|
<a name="l00512"></a>00512 <span class="keywordflow">return</span> -1;
|
||
|
<a name="l00513"></a>00513 }
|
||
|
<a name="l00514"></a>00514
|
||
|
<a name="l00515"></a>00515
|
||
|
<a name="l00517"></a>00517
|
||
|
<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>
|
||
|
<a name="l00523"></a>00523 <span class="keyword"> </span>{
|
||
|
<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)
|
||
|
<a name="l00525"></a>00525 <span class="keywordflow">if</span> (data[i] == element)
|
||
|
<a name="l00526"></a>00526 <span class="keywordflow">return</span> i;
|
||
|
<a name="l00527"></a>00527
|
||
|
<a name="l00528"></a>00528 <span class="keywordflow">return</span> -1;
|
||
|
<a name="l00529"></a>00529 }
|
||
|
<a name="l00530"></a>00530
|
||
|
<a name="l00531"></a>00531
|
||
|
<a name="l00533"></a>00533
|
||
|
<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)
|
||
|
<a name="l00537"></a>00537 {
|
||
|
<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>
|
||
|
<a name="l00539"></a>00539
|
||
|
<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)
|
||
|
<a name="l00541"></a>00541 {
|
||
|
<a name="l00542"></a>00542 allocator.destruct(&data[i-1]);
|
||
|
<a name="l00543"></a>00543 allocator.construct(&data[i-1], data[i]); <span class="comment">// data[i-1] = data[i];</span>
|
||
|
<a name="l00544"></a>00544 }
|
||
|
<a name="l00545"></a>00545
|
||
|
<a name="l00546"></a>00546 allocator.destruct(&data[used-1]);
|
||
|
<a name="l00547"></a>00547
|
||
|
<a name="l00548"></a>00548 --used;
|
||
|
<a name="l00549"></a>00549 }
|
||
|
<a name="l00550"></a>00550
|
||
|
<a name="l00551"></a>00551
|
||
|
<a name="l00553"></a>00553
|
||
|
<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)
|
||
|
<a name="l00558"></a>00558 {
|
||
|
<a name="l00559"></a>00559 <span class="keywordflow">if</span> (index>=used || count<1)
|
||
|
<a name="l00560"></a>00560 <span class="keywordflow">return</span>;
|
||
|
<a name="l00561"></a>00561 <span class="keywordflow">if</span> (index+count>used)
|
||
|
<a name="l00562"></a>00562 count = used-index;
|
||
|
<a name="l00563"></a>00563
|
||
|
<a name="l00564"></a>00564 <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i;
|
||
|
<a name="l00565"></a>00565 <span class="keywordflow">for</span> (i=index; i<index+count; ++i)
|
||
|
<a name="l00566"></a>00566 allocator.destruct(&data[i]);
|
||
|
<a name="l00567"></a>00567
|
||
|
<a name="l00568"></a>00568 <span class="keywordflow">for</span> (i=index+count; i<used; ++i)
|
||
|
<a name="l00569"></a>00569 {
|
||
|
<a name="l00570"></a>00570 <span class="keywordflow">if</span> (i-count >= index+count) <span class="comment">// not already destructed before loop</span>
|
||
|
<a name="l00571"></a>00571 allocator.destruct(&data[i-count]);
|
||
|
<a name="l00572"></a>00572
|
||
|
<a name="l00573"></a>00573 allocator.construct(&data[i-count], data[i]); <span class="comment">// data[i-count] = data[i];</span>
|
||
|
<a name="l00574"></a>00574
|
||
|
<a name="l00575"></a>00575 <span class="keywordflow">if</span> (i >= used-count) <span class="comment">// those which are not overwritten</span>
|
||
|
<a name="l00576"></a>00576 allocator.destruct(&data[i]);
|
||
|
<a name="l00577"></a>00577 }
|
||
|
<a name="l00578"></a>00578
|
||
|
<a name="l00579"></a>00579 used-= count;
|
||
|
<a name="l00580"></a>00580 }
|
||
|
<a name="l00581"></a>00581
|
||
|
<a name="l00582"></a>00582
|
||
|
<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)
|
||
|
<a name="l00585"></a>00585 {
|
||
|
<a name="l00586"></a>00586 is_sorted = _is_sorted;
|
||
|
<a name="l00587"></a>00587 }
|
||
|
<a name="l00588"></a>00588
|
||
|
<a name="l00589"></a>00589
|
||
|
<a name="l00591"></a>00591
|
||
|
<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)
|
||
|
<a name="l00595"></a>00595 {
|
||
|
<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);
|
||
|
<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);
|
||
|
<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);
|
||
|
<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>
|
||
|
<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>
|
||
|
<a name="l00601"></a>00601 strategy = other.strategy;
|
||
|
<a name="l00602"></a>00602 other.strategy = helper_strategy;
|
||
|
<a name="l00603"></a>00603 <span class="keywordtype">bool</span> helper_free_when_destroyed(free_when_destroyed);
|
||
|
<a name="l00604"></a>00604 free_when_destroyed = other.free_when_destroyed;
|
||
|
<a name="l00605"></a>00605 other.free_when_destroyed = helper_free_when_destroyed;
|
||
|
<a name="l00606"></a>00606 <span class="keywordtype">bool</span> helper_is_sorted(is_sorted);
|
||
|
<a name="l00607"></a>00607 is_sorted = other.is_sorted;
|
||
|
<a name="l00608"></a>00608 other.is_sorted = helper_is_sorted;
|
||
|
<a name="l00609"></a>00609 }
|
||
|
<a name="l00610"></a>00610
|
||
|
<a name="l00611"></a>00611
|
||
|
<a name="l00612"></a>00612 <span class="keyword">private</span>:
|
||
|
<a name="l00613"></a>00613 T* data;
|
||
|
<a name="l00614"></a>00614 <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> allocated;
|
||
|
<a name="l00615"></a>00615 <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> used;
|
||
|
<a name="l00616"></a>00616 TAlloc allocator;
|
||
|
<a name="l00617"></a>00617 <a class="code" href="namespaceirr_1_1core.html#aa2e91971d5e6e84de235bfabe3c7adba" title="defines an allocation strategy">eAllocStrategy</a> strategy:4;
|
||
|
<a name="l00618"></a>00618 <span class="keywordtype">bool</span> free_when_destroyed:1;
|
||
|
<a name="l00619"></a>00619 <span class="keywordtype">bool</span> is_sorted:1;
|
||
|
<a name="l00620"></a>00620 };
|
||
|
<a name="l00621"></a>00621
|
||
|
<a name="l00622"></a>00622
|
||
|
<a name="l00623"></a>00623 } <span class="comment">// end namespace core</span>
|
||
|
<a name="l00624"></a>00624 } <span class="comment">// end namespace irr</span>
|
||
|
<a name="l00625"></a>00625
|
||
|
<a name="l00626"></a>00626 <span class="preprocessor">#endif</span>
|
||
|
<a name="l00627"></a>00627 <span class="preprocessor"></span>
|
||
|
</pre></div></div>
|
||
|
</div>
|
||
|
<div id="nav-path" class="navpath">
|
||
|
<ul>
|
||
|
<li class="navelem"><a class="el" href="irr_array_8h.html">irrArray.h</a> </li>
|
||
|
<!-- window showing the filter options -->
|
||
|
<div id="MSearchSelectWindow"
|
||
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
||
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
||
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
||
|
<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>
|
||
|
|
||
|
<!-- iframe showing the search results (closed by default) -->
|
||
|
<div id="MSearchResultsWindow">
|
||
|
<iframe src="javascript:void(0)" frameborder="0"
|
||
|
name="MSearchResults" id="MSearchResults">
|
||
|
</iframe>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<li class="footer">
|
||
|
<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
|
||
|
Engine</a> Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on Tue Jan 19 2016 16:08:45 for Irrlicht 3D Engine by
|
||
|
<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|