108 lines
68 KiB
HTML
108 lines
68 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"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.8.13"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>entt: src/entt/entity/sparse_set.hpp Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<div id="projectname">entt
|
|
 <span id="projectnumber">2.4.1</span>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.8.13 -->
|
|
<script type="text/javascript">
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
</script>
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
$(function() {
|
|
initMenu('',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</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>
|
|
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_66e9674e8206a335795995fa32a03c91.html">entt</a></li><li class="navelem"><a class="el" href="dir_e3a7bb56c55e5c2286e2fe96e197d4f5.html">entity</a></li> </ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">sparse_set.hpp</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="preprocessor">#ifndef ENTT_ENTITY_SPARSE_SET_HPP</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="preprocessor">#define ENTT_ENTITY_SPARSE_SET_HPP</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> </div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> </div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="preprocessor">#include <algorithm></span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="preprocessor">#include <numeric></span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="preprocessor">#include <utility></span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="preprocessor">#include <vector></span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="preprocessor">#include <cstddef></span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="preprocessor">#include <cassert></span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="preprocessor">#include <type_traits></span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="preprocessor">#include "traits.hpp"</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> </div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> </div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="keyword">namespace </span><a class="code" href="namespaceentt.html">entt</a> {</div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> </div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> </div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="keyword">template</span><<span class="keyword">typename</span>...></div><div class="line"><a name="l00025"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet.html"> 25</a></span> <span class="keyword">class </span><a class="code" href="classentt_1_1SparseSet.html">SparseSet</a>;</div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> </div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> </div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span> <span class="keyword">template</span><<span class="keyword">typename</span> Entity></div><div class="line"><a name="l00056"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html"> 56</a></span> <span class="keyword">class </span><a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html">SparseSet<Entity></a> {</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  <span class="keyword">using</span> <a class="code" href="structentt_1_1entt__traits.html">traits_type</a> = <a class="code" href="structentt_1_1entt__traits.html">entt_traits<Entity></a>;</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span> </div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  <span class="keyword">struct </span>Iterator {</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  <span class="keyword">using</span> value_type = Entity;</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span> </div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  Iterator(<span class="keyword">const</span> std::vector<Entity> *direct, std::size_t pos)</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  : direct{direct}, pos{pos}</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  {}</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span> </div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  Iterator & operator++() noexcept {</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  <span class="keywordflow">return</span> --pos, *<span class="keyword">this</span>;</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  }</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span> </div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  Iterator operator++(<span class="keywordtype">int</span>) noexcept {</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  Iterator orig = *<span class="keyword">this</span>;</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  <span class="keywordflow">return</span> ++(*this), orig;</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  }</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span> </div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> Iterator &other) <span class="keyword">const</span> noexcept {</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  <span class="keywordflow">return</span> other.pos == pos && other.direct == direct;</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  }</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span> </div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  <span class="keywordtype">bool</span> <a class="code" href="namespaceentt.html#a18e1a7cdfcb0c0ba075e0beeda95285f">operator!=</a>(<span class="keyword">const</span> Iterator &other) <span class="keyword">const</span> noexcept {</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  <span class="keywordflow">return</span> !(*<span class="keyword">this</span> == other);</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  }</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span> </div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  value_type operator*() <span class="keyword">const</span> noexcept {</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  <span class="keywordflow">return</span> (*direct)[pos-1];</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  }</div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span> </div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  <span class="keyword">private</span>:</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  <span class="keyword">const</span> std::vector<Entity> *direct;</div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  std::size_t pos;</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  };</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span> </div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  <span class="keyword">static</span> constexpr Entity in_use = (Entity{1} << traits_type::entity_shift);</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span> </div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span> <span class="keyword">public</span>:</div><div class="line"><a name="l00096"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2"> 96</a></span>  <span class="keyword">using</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a> = Entity;</div><div class="line"><a name="l00098"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0"> 98</a></span>  <span class="keyword">using</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">pos_type</a> = <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a>;</div><div class="line"><a name="l00100"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab81c48dcee7a1104ee82794613ee7ed2"> 100</a></span>  <span class="keyword">using</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab81c48dcee7a1104ee82794613ee7ed2">size_type</a> = std::size_t;</div><div class="line"><a name="l00102"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1ad77aed1e49af60b61044c996969b9a"> 102</a></span>  <span class="keyword">using</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1ad77aed1e49af60b61044c996969b9a">iterator_type</a> = Iterator;</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span> </div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a>() noexcept = default;</div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span> </div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  virtual ~<a class="code" href="classentt_1_1SparseSet.html">SparseSet</a>() noexcept = default;</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span> </div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a>(const <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> &) = delete;</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a>(<a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> &&) = default;</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span> </div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> & operator=(const <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> &) = delete;</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> & operator=(<a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> &&) = default;</div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span> </div><div class="line"><a name="l00128"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a56178563cf37f6066828b370e5747541"> 128</a></span>  <span class="keywordtype">void</span> reserve(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab81c48dcee7a1104ee82794613ee7ed2">size_type</a> cap) {</div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  reverse.reserve(cap);</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  direct.reserve(cap);</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  }</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span> </div><div class="line"><a name="l00143"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a337360e8d0f44c373acef65328a3e9f8"> 143</a></span>  <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab81c48dcee7a1104ee82794613ee7ed2">size_type</a> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a337360e8d0f44c373acef65328a3e9f8">size</a>() const noexcept {</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  <span class="keywordflow">return</span> direct.size();</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  }</div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span> </div><div class="line"><a name="l00151"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a9d6b9c98d2645d821c81ff7d3586ca27"> 151</a></span>  <span class="keywordtype">bool</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a9d6b9c98d2645d821c81ff7d3586ca27">empty</a>() const noexcept {</div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  <span class="keywordflow">return</span> direct.empty();</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  }</div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span> </div><div class="line"><a name="l00170"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a6e4dda542e3d725dd963dea57bfb9cb1"> 170</a></span>  <span class="keyword">const</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a> * <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a6e4dda542e3d725dd963dea57bfb9cb1">data</a>() const noexcept {</div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  <span class="keywordflow">return</span> direct.data();</div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  }</div><div class="line"><a name="l00173"></a><span class="lineno"> 173</span> </div><div class="line"><a name="l00186"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1efc9899f2ede4fd8ea1840a7ed8dbc7"> 186</a></span>  <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1ad77aed1e49af60b61044c996969b9a">iterator_type</a> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1efc9899f2ede4fd8ea1840a7ed8dbc7">begin</a>() const noexcept {</div><div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  <span class="keywordflow">return</span> Iterator{&direct, direct.size()};</div><div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  }</div><div class="line"><a name="l00189"></a><span class="lineno"> 189</span> </div><div class="line"><a name="l00203"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a2c54395d55054437bfe179718e102181"> 203</a></span>  <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1ad77aed1e49af60b61044c996969b9a">iterator_type</a> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a2c54395d55054437bfe179718e102181">end</a>() const noexcept {</div><div class="line"><a name="l00204"></a><span class="lineno"> 204</span>  <span class="keywordflow">return</span> Iterator{&direct, 0};</div><div class="line"><a name="l00205"></a><span class="lineno"> 205</span>  }</div><div class="line"><a name="l00206"></a><span class="lineno"> 206</span> </div><div class="line"><a name="l00212"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1b6a33e6e65345bf028877efa74c5a5e"> 212</a></span>  <span class="keywordtype">bool</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1b6a33e6e65345bf028877efa74c5a5e">has</a>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a> entity) <span class="keyword">const</span> noexcept {</div><div class="line"><a name="l00213"></a><span class="lineno"> 213</span>  <span class="keyword">using</span> promotion_type = std::conditional_t<sizeof(size_type) >= <span class="keyword">sizeof</span>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a>), <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab81c48dcee7a1104ee82794613ee7ed2">size_type</a>, <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a>>;</div><div class="line"><a name="l00214"></a><span class="lineno"> 214</span>  <span class="comment">// explicit promotion to avoid warnings with std::uint16_t</span></div><div class="line"><a name="l00215"></a><span class="lineno"> 215</span>  <span class="keyword">const</span> <span class="keyword">auto</span> <a class="code" href="namespaceentt.html">entt</a> = promotion_type{entity} & traits_type::entity_mask;</div><div class="line"><a name="l00216"></a><span class="lineno"> 216</span>  <span class="comment">// the in-use control bit permits to avoid accessing the direct vector</span></div><div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  <span class="keywordflow">return</span> (<a class="code" href="namespaceentt.html">entt</a> < reverse.size()) && (reverse[<a class="code" href="namespaceentt.html">entt</a>] & in_use);</div><div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  }</div><div class="line"><a name="l00219"></a><span class="lineno"> 219</span> </div><div class="line"><a name="l00232"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7aa0a2c4f286228fc47d32761552bc13"> 232</a></span>  <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">pos_type</a> <span class="keyword">get</span>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a> entity) <span class="keyword">const</span> noexcept {</div><div class="line"><a name="l00233"></a><span class="lineno"> 233</span>  assert(has(entity));</div><div class="line"><a name="l00234"></a><span class="lineno"> 234</span>  <span class="keyword">const</span> <span class="keyword">auto</span> <a class="code" href="namespaceentt.html">entt</a> = entity & traits_type::entity_mask;</div><div class="line"><a name="l00235"></a><span class="lineno"> 235</span>  <span class="comment">// we must get rid of the in-use bit for it's not part of the position</span></div><div class="line"><a name="l00236"></a><span class="lineno"> 236</span>  <span class="keywordflow">return</span> reverse[<a class="code" href="namespaceentt.html">entt</a>] & ~in_use;</div><div class="line"><a name="l00237"></a><span class="lineno"> 237</span>  }</div><div class="line"><a name="l00238"></a><span class="lineno"> 238</span> </div><div class="line"><a name="l00250"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#adb65da9a09f41dcf6ec433066a7891c3"> 250</a></span>  <span class="keywordtype">void</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#adb65da9a09f41dcf6ec433066a7891c3">construct</a>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a> entity) {</div><div class="line"><a name="l00251"></a><span class="lineno"> 251</span>  assert(!has(entity));</div><div class="line"><a name="l00252"></a><span class="lineno"> 252</span>  <span class="keyword">using</span> promotion_type = std::conditional_t<sizeof(size_type) >= <span class="keyword">sizeof</span>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a>), <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab81c48dcee7a1104ee82794613ee7ed2">size_type</a>, <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a>>;</div><div class="line"><a name="l00253"></a><span class="lineno"> 253</span>  <span class="comment">// explicit promotion to avoid warnings with std::uint16_t</span></div><div class="line"><a name="l00254"></a><span class="lineno"> 254</span>  <span class="keyword">const</span> <span class="keyword">auto</span> <a class="code" href="namespaceentt.html">entt</a> = promotion_type{entity} & traits_type::entity_mask;</div><div class="line"><a name="l00255"></a><span class="lineno"> 255</span> </div><div class="line"><a name="l00256"></a><span class="lineno"> 256</span>  <span class="keywordflow">if</span>(!(<a class="code" href="namespaceentt.html">entt</a> < reverse.size())) {</div><div class="line"><a name="l00257"></a><span class="lineno"> 257</span>  reverse.resize(<a class="code" href="namespaceentt.html">entt</a>+1, <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">pos_type</a>{});</div><div class="line"><a name="l00258"></a><span class="lineno"> 258</span>  }</div><div class="line"><a name="l00259"></a><span class="lineno"> 259</span> </div><div class="line"><a name="l00260"></a><span class="lineno"> 260</span>  <span class="comment">// we exploit the fact that pos_type is equal to entity_type and pos has</span></div><div class="line"><a name="l00261"></a><span class="lineno"> 261</span>  <span class="comment">// traits_type::version_mask bits unused we can use to mark it as in-use</span></div><div class="line"><a name="l00262"></a><span class="lineno"> 262</span>  reverse[<a class="code" href="namespaceentt.html">entt</a>] = <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">pos_type</a>(direct.size()) | in_use;</div><div class="line"><a name="l00263"></a><span class="lineno"> 263</span>  direct.emplace_back(entity);</div><div class="line"><a name="l00264"></a><span class="lineno"> 264</span>  }</div><div class="line"><a name="l00265"></a><span class="lineno"> 265</span> </div><div class="line"><a name="l00277"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab4be1be8435da50621373c0bd737a1e8"> 277</a></span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab4be1be8435da50621373c0bd737a1e8">destroy</a>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a> entity) {</div><div class="line"><a name="l00278"></a><span class="lineno"> 278</span>  assert(has(entity));</div><div class="line"><a name="l00279"></a><span class="lineno"> 279</span>  <span class="keyword">const</span> <span class="keyword">auto</span> <a class="code" href="namespaceentt.html">entt</a> = entity & traits_type::entity_mask;</div><div class="line"><a name="l00280"></a><span class="lineno"> 280</span>  <span class="keyword">const</span> <span class="keyword">auto</span> back = direct.back() & traits_type::entity_mask;</div><div class="line"><a name="l00281"></a><span class="lineno"> 281</span>  <span class="keyword">const</span> <span class="keyword">auto</span> pos = reverse[<a class="code" href="namespaceentt.html">entt</a>] & ~in_use;</div><div class="line"><a name="l00282"></a><span class="lineno"> 282</span>  <span class="comment">// the order matters: if back and entt are the same (for the sparse set</span></div><div class="line"><a name="l00283"></a><span class="lineno"> 283</span>  <span class="comment">// has size 1), switching the two lines below doesn't work as expected</span></div><div class="line"><a name="l00284"></a><span class="lineno"> 284</span>  reverse[back] = pos | in_use;</div><div class="line"><a name="l00285"></a><span class="lineno"> 285</span>  reverse[<a class="code" href="namespaceentt.html">entt</a>] = pos;</div><div class="line"><a name="l00286"></a><span class="lineno"> 286</span>  <span class="comment">// swapping isn't required here, we are getting rid of the last element</span></div><div class="line"><a name="l00287"></a><span class="lineno"> 287</span>  direct[pos] = direct.back();</div><div class="line"><a name="l00288"></a><span class="lineno"> 288</span>  direct.pop_back();</div><div class="line"><a name="l00289"></a><span class="lineno"> 289</span>  }</div><div class="line"><a name="l00290"></a><span class="lineno"> 290</span> </div><div class="line"><a name="l00306"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#af122c1668ab1efbe0eca5792e9bae434"> 306</a></span>  <span class="keywordtype">void</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#af122c1668ab1efbe0eca5792e9bae434">swap</a>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">pos_type</a> lhs, <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">pos_type</a> rhs) noexcept {</div><div class="line"><a name="l00307"></a><span class="lineno"> 307</span>  assert(lhs < direct.size());</div><div class="line"><a name="l00308"></a><span class="lineno"> 308</span>  assert(rhs < direct.size());</div><div class="line"><a name="l00309"></a><span class="lineno"> 309</span>  <span class="keyword">const</span> <span class="keyword">auto</span> src = direct[lhs] & traits_type::entity_mask;</div><div class="line"><a name="l00310"></a><span class="lineno"> 310</span>  <span class="keyword">const</span> <span class="keyword">auto</span> dst = direct[rhs] & traits_type::entity_mask;</div><div class="line"><a name="l00311"></a><span class="lineno"> 311</span>  std::swap(reverse[src], reverse[dst]);</div><div class="line"><a name="l00312"></a><span class="lineno"> 312</span>  std::swap(direct[lhs], direct[rhs]);</div><div class="line"><a name="l00313"></a><span class="lineno"> 313</span>  }</div><div class="line"><a name="l00314"></a><span class="lineno"> 314</span> </div><div class="line"><a name="l00334"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7a6ff2340d8accf14bdaa83676cbc670"> 334</a></span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7a6ff2340d8accf14bdaa83676cbc670">respect</a>(<span class="keyword">const</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html">SparseSet<Entity></a> &other) noexcept {</div><div class="line"><a name="l00335"></a><span class="lineno"> 335</span>  <span class="keyword">auto</span> from = other.begin();</div><div class="line"><a name="l00336"></a><span class="lineno"> 336</span>  <span class="keyword">auto</span> to = other.end();</div><div class="line"><a name="l00337"></a><span class="lineno"> 337</span> </div><div class="line"><a name="l00338"></a><span class="lineno"> 338</span>  <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">pos_type</a> pos = direct.size() - 1;</div><div class="line"><a name="l00339"></a><span class="lineno"> 339</span> </div><div class="line"><a name="l00340"></a><span class="lineno"> 340</span>  <span class="keywordflow">while</span>(pos > 0 && from != to) {</div><div class="line"><a name="l00341"></a><span class="lineno"> 341</span>  <span class="keywordflow">if</span>(has(*from)) {</div><div class="line"><a name="l00342"></a><span class="lineno"> 342</span>  <span class="keywordflow">if</span>(*from != direct[pos]) {</div><div class="line"><a name="l00343"></a><span class="lineno"> 343</span>  swap(pos, <span class="keyword">get</span>(*from));</div><div class="line"><a name="l00344"></a><span class="lineno"> 344</span>  }</div><div class="line"><a name="l00345"></a><span class="lineno"> 345</span> </div><div class="line"><a name="l00346"></a><span class="lineno"> 346</span>  --pos;</div><div class="line"><a name="l00347"></a><span class="lineno"> 347</span>  }</div><div class="line"><a name="l00348"></a><span class="lineno"> 348</span> </div><div class="line"><a name="l00349"></a><span class="lineno"> 349</span>  ++from;</div><div class="line"><a name="l00350"></a><span class="lineno"> 350</span>  }</div><div class="line"><a name="l00351"></a><span class="lineno"> 351</span>  }</div><div class="line"><a name="l00352"></a><span class="lineno"> 352</span> </div><div class="line"><a name="l00356"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ad1c62c65aeb0112e688f05d8f641cdab"> 356</a></span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ad1c62c65aeb0112e688f05d8f641cdab">reset</a>() {</div><div class="line"><a name="l00357"></a><span class="lineno"> 357</span>  reverse.clear();</div><div class="line"><a name="l00358"></a><span class="lineno"> 358</span>  direct.clear();</div><div class="line"><a name="l00359"></a><span class="lineno"> 359</span>  }</div><div class="line"><a name="l00360"></a><span class="lineno"> 360</span> </div><div class="line"><a name="l00361"></a><span class="lineno"> 361</span> <span class="keyword">private</span>:</div><div class="line"><a name="l00362"></a><span class="lineno"> 362</span>  std::vector<pos_type> reverse;</div><div class="line"><a name="l00363"></a><span class="lineno"> 363</span>  std::vector<entity_type> direct;</div><div class="line"><a name="l00364"></a><span class="lineno"> 364</span> };</div><div class="line"><a name="l00365"></a><span class="lineno"> 365</span> </div><div class="line"><a name="l00366"></a><span class="lineno"> 366</span> </div><div class="line"><a name="l00389"></a><span class="lineno"> 389</span> <span class="keyword">template</span><<span class="keyword">typename</span> Entity, <span class="keyword">typename</span> Type></div><div class="line"><a name="l00390"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html"> 390</a></span> <span class="keyword">class </span><a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html">SparseSet<Entity, Type></a>: <span class="keyword">public</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html">SparseSet<Entity></a> {</div><div class="line"><a name="l00391"></a><span class="lineno"> 391</span>  <span class="keyword">using</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html">underlying_type</a> = <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html">SparseSet<Entity></a>;</div><div class="line"><a name="l00392"></a><span class="lineno"> 392</span> </div><div class="line"><a name="l00393"></a><span class="lineno"> 393</span> <span class="keyword">public</span>:</div><div class="line"><a name="l00395"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#af7db79dfb4e031a63fa526d4f7d54915"> 395</a></span>  <span class="keyword">using</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#af7db79dfb4e031a63fa526d4f7d54915">object_type</a> = Type;</div><div class="line"><a name="l00397"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#afe382e2d5c8769fb3d924e1a357cf9b0"> 397</a></span>  <span class="keyword">using</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a> = <span class="keyword">typename</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">underlying_type::entity_type</a>;</div><div class="line"><a name="l00399"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#ad161a395ca3979154a333520662c7737"> 399</a></span>  <span class="keyword">using</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">pos_type</a> = <span class="keyword">typename</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">underlying_type::pos_type</a>;</div><div class="line"><a name="l00401"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a27a88e2bb0822de41131741d9ffcded5"> 401</a></span>  <span class="keyword">using</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab81c48dcee7a1104ee82794613ee7ed2">size_type</a> = <span class="keyword">typename</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab81c48dcee7a1104ee82794613ee7ed2">underlying_type::size_type</a>;</div><div class="line"><a name="l00403"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#aab1937b624841a57dd7487e7a40ea0ac"> 403</a></span>  <span class="keyword">using</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1ad77aed1e49af60b61044c996969b9a">iterator_type</a> = <span class="keyword">typename</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1ad77aed1e49af60b61044c996969b9a">underlying_type::iterator_type</a>;</div><div class="line"><a name="l00404"></a><span class="lineno"> 404</span> </div><div class="line"><a name="l00406"></a><span class="lineno"> 406</span>  <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a>() noexcept = default;</div><div class="line"><a name="l00407"></a><span class="lineno"> 407</span> </div><div class="line"><a name="l00409"></a><span class="lineno"> 409</span>  <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a>(const <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> &) = delete;</div><div class="line"><a name="l00411"></a><span class="lineno"> 411</span>  <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a>(<a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> &&) = default;</div><div class="line"><a name="l00412"></a><span class="lineno"> 412</span> </div><div class="line"><a name="l00414"></a><span class="lineno"> 414</span>  <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> & operator=(const <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> &) = delete;</div><div class="line"><a name="l00416"></a><span class="lineno"> 416</span>  <a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> & operator=(<a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> &&) = default;</div><div class="line"><a name="l00417"></a><span class="lineno"> 417</span> </div><div class="line"><a name="l00426"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a7918956bd501e339982cc5ad21623788"> 426</a></span>  <span class="keywordtype">void</span> reserve(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab81c48dcee7a1104ee82794613ee7ed2">size_type</a> cap) {</div><div class="line"><a name="l00427"></a><span class="lineno"> 427</span>  underlying_type::reserve(cap);</div><div class="line"><a name="l00428"></a><span class="lineno"> 428</span>  instances.reserve(cap);</div><div class="line"><a name="l00429"></a><span class="lineno"> 429</span>  }</div><div class="line"><a name="l00430"></a><span class="lineno"> 430</span> </div><div class="line"><a name="l00446"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#aafa311b5b7379150782d94dffdbab959"> 446</a></span>  <span class="keyword">const</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#af7db79dfb4e031a63fa526d4f7d54915">object_type</a> * <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#aafa311b5b7379150782d94dffdbab959">raw</a>() const noexcept {</div><div class="line"><a name="l00447"></a><span class="lineno"> 447</span>  <span class="keywordflow">return</span> instances.data();</div><div class="line"><a name="l00448"></a><span class="lineno"> 448</span>  }</div><div class="line"><a name="l00449"></a><span class="lineno"> 449</span> </div><div class="line"><a name="l00465"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#ac64be22bc7dcb2498257dccbbcfa004f"> 465</a></span>  <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#af7db79dfb4e031a63fa526d4f7d54915">object_type</a> * <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#ac64be22bc7dcb2498257dccbbcfa004f">raw</a>() noexcept {</div><div class="line"><a name="l00466"></a><span class="lineno"> 466</span>  <span class="keywordflow">return</span> instances.data();</div><div class="line"><a name="l00467"></a><span class="lineno"> 467</span>  }</div><div class="line"><a name="l00468"></a><span class="lineno"> 468</span> </div><div class="line"><a name="l00481"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#ad24ca11a0ce0be4775978c3a06aed24b"> 481</a></span>  <span class="keyword">const</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#af7db79dfb4e031a63fa526d4f7d54915">object_type</a> & <span class="keyword">get</span>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a> entity) <span class="keyword">const</span> noexcept {</div><div class="line"><a name="l00482"></a><span class="lineno"> 482</span>  <span class="keywordflow">return</span> instances[underlying_type::get(entity)];</div><div class="line"><a name="l00483"></a><span class="lineno"> 483</span>  }</div><div class="line"><a name="l00484"></a><span class="lineno"> 484</span> </div><div class="line"><a name="l00497"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#acc051a79f32ee11605c5b61d76e66ef1"> 497</a></span>  <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#af7db79dfb4e031a63fa526d4f7d54915">object_type</a> & <span class="keyword">get</span>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a> entity) noexcept {</div><div class="line"><a name="l00498"></a><span class="lineno"> 498</span>  <span class="keywordflow">return</span> <span class="keyword">const_cast<</span><a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#af7db79dfb4e031a63fa526d4f7d54915">object_type</a> &<span class="keyword">></span>(<span class="keyword">const_cast<</span><span class="keyword">const </span><a class="code" href="classentt_1_1SparseSet.html">SparseSet</a> *<span class="keyword">></span>(<span class="keyword">this</span>)-><span class="keyword">get</span>(entity));</div><div class="line"><a name="l00499"></a><span class="lineno"> 499</span>  }</div><div class="line"><a name="l00500"></a><span class="lineno"> 500</span> </div><div class="line"><a name="l00515"></a><span class="lineno"> 515</span>  <span class="keyword">template</span><<span class="keyword">typename</span>... Args></div><div class="line"><a name="l00516"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#aa31e003cb882774dfb81fabb5d88e554"> 516</a></span>  <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#af7db79dfb4e031a63fa526d4f7d54915">object_type</a> & <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#aa31e003cb882774dfb81fabb5d88e554">construct</a>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a> entity, Args&&... args) {</div><div class="line"><a name="l00517"></a><span class="lineno"> 517</span>  underlying_type::construct(entity);</div><div class="line"><a name="l00518"></a><span class="lineno"> 518</span>  <span class="comment">// emplace_back doesn't work well with PODs because of its placement new</span></div><div class="line"><a name="l00519"></a><span class="lineno"> 519</span>  instances.push_back({ std::forward<Args>(args)... });</div><div class="line"><a name="l00520"></a><span class="lineno"> 520</span>  <span class="keywordflow">return</span> instances.back();</div><div class="line"><a name="l00521"></a><span class="lineno"> 521</span>  }</div><div class="line"><a name="l00522"></a><span class="lineno"> 522</span> </div><div class="line"><a name="l00534"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a06b863abd1b457c48b7080e203b47a0f"> 534</a></span>  <span class="keywordtype">void</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a06b863abd1b457c48b7080e203b47a0f">destroy</a>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entity_type</a> entity)<span class="keyword"> override </span>{</div><div class="line"><a name="l00535"></a><span class="lineno"> 535</span>  <span class="comment">// swapping isn't required here, we are getting rid of the last element</span></div><div class="line"><a name="l00536"></a><span class="lineno"> 536</span>  instances[underlying_type::get(entity)] = std::move(instances.back());</div><div class="line"><a name="l00537"></a><span class="lineno"> 537</span>  instances.pop_back();</div><div class="line"><a name="l00538"></a><span class="lineno"> 538</span>  underlying_type::destroy(entity);</div><div class="line"><a name="l00539"></a><span class="lineno"> 539</span>  }</div><div class="line"><a name="l00540"></a><span class="lineno"> 540</span> </div><div class="line"><a name="l00563"></a><span class="lineno"> 563</span>  <span class="keyword">template</span><<span class="keyword">typename</span> Compare></div><div class="line"><a name="l00564"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a91cbe1334ba5135e44dab73adedbad8d"> 564</a></span>  <span class="keywordtype">void</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a91cbe1334ba5135e44dab73adedbad8d">sort</a>(Compare compare) {</div><div class="line"><a name="l00565"></a><span class="lineno"> 565</span>  std::vector<pos_type> copy(instances.size());</div><div class="line"><a name="l00566"></a><span class="lineno"> 566</span>  std::iota(copy.begin(), copy.end(), 0);</div><div class="line"><a name="l00567"></a><span class="lineno"> 567</span> </div><div class="line"><a name="l00568"></a><span class="lineno"> 568</span>  std::sort(copy.begin(), copy.end(), [<span class="keyword">this</span>, compare = std::move(compare)](<span class="keyword">auto</span> lhs, <span class="keyword">auto</span> rhs) {</div><div class="line"><a name="l00569"></a><span class="lineno"> 569</span>  <span class="keywordflow">return</span> compare(const_cast<const object_type &>(instances[rhs]), const_cast<const object_type &>(instances[lhs]));</div><div class="line"><a name="l00570"></a><span class="lineno"> 570</span>  });</div><div class="line"><a name="l00571"></a><span class="lineno"> 571</span> </div><div class="line"><a name="l00572"></a><span class="lineno"> 572</span>  <span class="keywordflow">for</span>(<a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">pos_type</a> pos = 0, last = copy.size(); pos < last; ++pos) {</div><div class="line"><a name="l00573"></a><span class="lineno"> 573</span>  <span class="keyword">auto</span> curr = pos;</div><div class="line"><a name="l00574"></a><span class="lineno"> 574</span>  <span class="keyword">auto</span> next = copy[curr];</div><div class="line"><a name="l00575"></a><span class="lineno"> 575</span> </div><div class="line"><a name="l00576"></a><span class="lineno"> 576</span>  <span class="keywordflow">while</span>(curr != next) {</div><div class="line"><a name="l00577"></a><span class="lineno"> 577</span>  <span class="keyword">auto</span> lhs = copy[curr];</div><div class="line"><a name="l00578"></a><span class="lineno"> 578</span>  <span class="keyword">auto</span> rhs = copy[next];</div><div class="line"><a name="l00579"></a><span class="lineno"> 579</span>  std::swap(instances[lhs], instances[rhs]);</div><div class="line"><a name="l00580"></a><span class="lineno"> 580</span>  underlying_type::swap(lhs, rhs);</div><div class="line"><a name="l00581"></a><span class="lineno"> 581</span>  copy[curr] = curr;</div><div class="line"><a name="l00582"></a><span class="lineno"> 582</span>  curr = next;</div><div class="line"><a name="l00583"></a><span class="lineno"> 583</span>  next = copy[curr];</div><div class="line"><a name="l00584"></a><span class="lineno"> 584</span>  }</div><div class="line"><a name="l00585"></a><span class="lineno"> 585</span>  }</div><div class="line"><a name="l00586"></a><span class="lineno"> 586</span>  }</div><div class="line"><a name="l00587"></a><span class="lineno"> 587</span> </div><div class="line"><a name="l00610"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a73083f2d8385f8e33aebfadb2f657e7d"> 610</a></span>  <span class="keywordtype">void</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a73083f2d8385f8e33aebfadb2f657e7d">respect</a>(<span class="keyword">const</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html">SparseSet<Entity></a> &other) noexcept <span class="keyword">override</span> {</div><div class="line"><a name="l00611"></a><span class="lineno"> 611</span>  <span class="keyword">auto</span> from = other.begin();</div><div class="line"><a name="l00612"></a><span class="lineno"> 612</span>  <span class="keyword">auto</span> to = other.end();</div><div class="line"><a name="l00613"></a><span class="lineno"> 613</span> </div><div class="line"><a name="l00614"></a><span class="lineno"> 614</span>  <a class="code" href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">pos_type</a> pos = underlying_type::size() - 1;</div><div class="line"><a name="l00615"></a><span class="lineno"> 615</span>  <span class="keyword">const</span> <span class="keyword">auto</span> *direct = underlying_type::data();</div><div class="line"><a name="l00616"></a><span class="lineno"> 616</span> </div><div class="line"><a name="l00617"></a><span class="lineno"> 617</span>  <span class="keywordflow">while</span>(pos > 0 && from != to) {</div><div class="line"><a name="l00618"></a><span class="lineno"> 618</span>  <span class="keywordflow">if</span>(underlying_type::has(*from)) {</div><div class="line"><a name="l00619"></a><span class="lineno"> 619</span>  <span class="keywordflow">if</span>(*from != *(direct + pos)) {</div><div class="line"><a name="l00620"></a><span class="lineno"> 620</span>  <span class="keyword">auto</span> candidate = underlying_type::get(*from);</div><div class="line"><a name="l00621"></a><span class="lineno"> 621</span>  std::swap(instances[pos], instances[candidate]);</div><div class="line"><a name="l00622"></a><span class="lineno"> 622</span>  underlying_type::swap(pos, candidate);</div><div class="line"><a name="l00623"></a><span class="lineno"> 623</span>  }</div><div class="line"><a name="l00624"></a><span class="lineno"> 624</span> </div><div class="line"><a name="l00625"></a><span class="lineno"> 625</span>  --pos;</div><div class="line"><a name="l00626"></a><span class="lineno"> 626</span>  }</div><div class="line"><a name="l00627"></a><span class="lineno"> 627</span> </div><div class="line"><a name="l00628"></a><span class="lineno"> 628</span>  ++from;</div><div class="line"><a name="l00629"></a><span class="lineno"> 629</span>  }</div><div class="line"><a name="l00630"></a><span class="lineno"> 630</span>  }</div><div class="line"><a name="l00631"></a><span class="lineno"> 631</span> </div><div class="line"><a name="l00635"></a><span class="lineno"><a class="line" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a3b138c121f11592a3f9e9f2fc2bb67fe"> 635</a></span>  <span class="keywordtype">void</span> <a class="code" href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a3b138c121f11592a3f9e9f2fc2bb67fe">reset</a>()<span class="keyword"> override </span>{</div><div class="line"><a name="l00636"></a><span class="lineno"> 636</span>  underlying_type::reset();</div><div class="line"><a name="l00637"></a><span class="lineno"> 637</span>  instances.clear();</div><div class="line"><a name="l00638"></a><span class="lineno"> 638</span>  }</div><div class="line"><a name="l00639"></a><span class="lineno"> 639</span> </div><div class="line"><a name="l00640"></a><span class="lineno"> 640</span> <span class="keyword">private</span>:</div><div class="line"><a name="l00641"></a><span class="lineno"> 641</span>  std::vector<object_type> instances;</div><div class="line"><a name="l00642"></a><span class="lineno"> 642</span> };</div><div class="line"><a name="l00643"></a><span class="lineno"> 643</span> </div><div class="line"><a name="l00644"></a><span class="lineno"> 644</span> </div><div class="line"><a name="l00645"></a><span class="lineno"> 645</span> }</div><div class="line"><a name="l00646"></a><span class="lineno"> 646</span> </div><div class="line"><a name="l00647"></a><span class="lineno"> 647</span> </div><div class="line"><a name="l00648"></a><span class="lineno"> 648</span> <span class="preprocessor">#endif // ENTT_ENTITY_SPARSE_SET_HPP</span></div><div class="ttc" id="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4_html_a91cbe1334ba5135e44dab73adedbad8d"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a91cbe1334ba5135e44dab73adedbad8d">entt::SparseSet< Entity, Type >::sort</a></div><div class="ttdeci">void sort(Compare compare)</div><div class="ttdoc">Sort components according to the given comparison function. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00564">sparse_set.hpp:564</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_ad1c62c65aeb0112e688f05d8f641cdab"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#ad1c62c65aeb0112e688f05d8f641cdab">entt::SparseSet< Entity >::reset</a></div><div class="ttdeci">virtual void reset()</div><div class="ttdoc">Resets a sparse set. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00356">sparse_set.hpp:356</a></div></div>
|
|
<div class="ttc" id="namespaceentt_html"><div class="ttname"><a href="namespaceentt.html">entt</a></div><div class="ttdoc">EnTT default namespace. </div><div class="ttdef"><b>Definition:</b> <a href="family_8hpp_source.html#l00009">family.hpp:9</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4_html_a3b138c121f11592a3f9e9f2fc2bb67fe"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a3b138c121f11592a3f9e9f2fc2bb67fe">entt::SparseSet< Entity, Type >::reset</a></div><div class="ttdeci">void reset() override</div><div class="ttdoc">Resets a sparse set. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00635">sparse_set.hpp:635</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4_html_aafa311b5b7379150782d94dffdbab959"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#aafa311b5b7379150782d94dffdbab959">entt::SparseSet< Entity, Type >::raw</a></div><div class="ttdeci">const object_type * raw() const noexcept</div><div class="ttdoc">Direct access to the array of objects. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00446">sparse_set.hpp:446</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_a9d6b9c98d2645d821c81ff7d3586ca27"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#a9d6b9c98d2645d821c81ff7d3586ca27">entt::SparseSet< Entity >::empty</a></div><div class="ttdeci">bool empty() const noexcept</div><div class="ttdoc">Checks whether a sparse set is empty. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00151">sparse_set.hpp:151</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4_html_a73083f2d8385f8e33aebfadb2f657e7d"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a73083f2d8385f8e33aebfadb2f657e7d">entt::SparseSet< Entity, Type >::respect</a></div><div class="ttdeci">void respect(const SparseSet< Entity > &other) noexcept override</div><div class="ttdoc">Sort components according to the order of the entities in another sparse set. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00610">sparse_set.hpp:610</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_html"><div class="ttname"><a href="classentt_1_1SparseSet.html">entt::SparseSet</a></div><div class="ttdoc">Sparse set. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00025">sparse_set.hpp:25</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_ab81c48dcee7a1104ee82794613ee7ed2"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab81c48dcee7a1104ee82794613ee7ed2">entt::SparseSet< Entity >::size_type</a></div><div class="ttdeci">std::size_t size_type</div><div class="ttdoc">Unsigned integer type. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00100">sparse_set.hpp:100</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4_html"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html">entt::SparseSet< Entity, Type ></a></div><div class="ttdoc">Extended sparse set implementation. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00390">sparse_set.hpp:390</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4_html_a06b863abd1b457c48b7080e203b47a0f"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#a06b863abd1b457c48b7080e203b47a0f">entt::SparseSet< Entity, Type >::destroy</a></div><div class="ttdeci">void destroy(entity_type entity) override</div><div class="ttdoc">Removes an entity from a sparse set and destroies its object. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00534">sparse_set.hpp:534</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_a7d36e852257a965a9a0ed3fb636433e2"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7d36e852257a965a9a0ed3fb636433e2">entt::SparseSet< Entity >::entity_type</a></div><div class="ttdeci">Entity entity_type</div><div class="ttdoc">Underlying entity identifier. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00096">sparse_set.hpp:96</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_a1ad77aed1e49af60b61044c996969b9a"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1ad77aed1e49af60b61044c996969b9a">entt::SparseSet< Entity >::iterator_type</a></div><div class="ttdeci">Iterator iterator_type</div><div class="ttdoc">Input iterator type. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00102">sparse_set.hpp:102</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html">entt::SparseSet< Entity ></a></div><div class="ttdoc">Basic sparse set implementation. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00056">sparse_set.hpp:56</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_a1b6a33e6e65345bf028877efa74c5a5e"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1b6a33e6e65345bf028877efa74c5a5e">entt::SparseSet< Entity >::has</a></div><div class="ttdeci">bool has(entity_type entity) const noexcept</div><div class="ttdoc">Checks if a sparse set contains an entity. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00212">sparse_set.hpp:212</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_a20c218a69cf339371251ffa5580d7aa0"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#a20c218a69cf339371251ffa5580d7aa0">entt::SparseSet< Entity >::pos_type</a></div><div class="ttdeci">entity_type pos_type</div><div class="ttdoc">Entity dependent position type. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00098">sparse_set.hpp:98</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4_html_af7db79dfb4e031a63fa526d4f7d54915"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#af7db79dfb4e031a63fa526d4f7d54915">entt::SparseSet< Entity, Type >::object_type</a></div><div class="ttdeci">Type object_type</div><div class="ttdoc">Type of the objects associated to the entities. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00395">sparse_set.hpp:395</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_a6e4dda542e3d725dd963dea57bfb9cb1"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#a6e4dda542e3d725dd963dea57bfb9cb1">entt::SparseSet< Entity >::data</a></div><div class="ttdeci">const entity_type * data() const noexcept</div><div class="ttdoc">Direct access to the internal packed array. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00170">sparse_set.hpp:170</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_a2c54395d55054437bfe179718e102181"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#a2c54395d55054437bfe179718e102181">entt::SparseSet< Entity >::end</a></div><div class="ttdeci">iterator_type end() const noexcept</div><div class="ttdoc">Returns an iterator to the end. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00203">sparse_set.hpp:203</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_ab4be1be8435da50621373c0bd737a1e8"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#ab4be1be8435da50621373c0bd737a1e8">entt::SparseSet< Entity >::destroy</a></div><div class="ttdeci">virtual void destroy(entity_type entity)</div><div class="ttdoc">Removes an entity from a sparse set. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00277">sparse_set.hpp:277</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_a1efc9899f2ede4fd8ea1840a7ed8dbc7"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#a1efc9899f2ede4fd8ea1840a7ed8dbc7">entt::SparseSet< Entity >::begin</a></div><div class="ttdeci">iterator_type begin() const noexcept</div><div class="ttdoc">Returns an iterator to the beginning. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00186">sparse_set.hpp:186</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_adb65da9a09f41dcf6ec433066a7891c3"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#adb65da9a09f41dcf6ec433066a7891c3">entt::SparseSet< Entity >::construct</a></div><div class="ttdeci">void construct(entity_type entity)</div><div class="ttdoc">Assigns an entity to a sparse set. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00250">sparse_set.hpp:250</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4_html_aa31e003cb882774dfb81fabb5d88e554"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#aa31e003cb882774dfb81fabb5d88e554">entt::SparseSet< Entity, Type >::construct</a></div><div class="ttdeci">object_type & construct(entity_type entity, Args &&... args)</div><div class="ttdoc">Assigns an entity to a sparse set and constructs its object. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00516">sparse_set.hpp:516</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_a337360e8d0f44c373acef65328a3e9f8"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#a337360e8d0f44c373acef65328a3e9f8">entt::SparseSet< Entity >::size</a></div><div class="ttdeci">size_type size() const noexcept</div><div class="ttdoc">Returns the number of elements in a sparse set. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00143">sparse_set.hpp:143</a></div></div>
|
|
<div class="ttc" id="namespaceentt_html_a18e1a7cdfcb0c0ba075e0beeda95285f"><div class="ttname"><a href="namespaceentt.html#a18e1a7cdfcb0c0ba075e0beeda95285f">entt::operator!=</a></div><div class="ttdeci">constexpr bool operator!=(const HashedString &lhs, const HashedString &rhs) noexcept</div><div class="ttdoc">Compares two hashed strings. </div><div class="ttdef"><b>Definition:</b> <a href="hashed__string_8hpp_source.html#l00101">hashed_string.hpp:101</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_a7a6ff2340d8accf14bdaa83676cbc670"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#a7a6ff2340d8accf14bdaa83676cbc670">entt::SparseSet< Entity >::respect</a></div><div class="ttdeci">virtual void respect(const SparseSet< Entity > &other) noexcept</div><div class="ttdoc">Sort entities according to their order in another sparse set. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00334">sparse_set.hpp:334</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4_html_ac64be22bc7dcb2498257dccbbcfa004f"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_00_01Type_01_4.html#ac64be22bc7dcb2498257dccbbcfa004f">entt::SparseSet< Entity, Type >::raw</a></div><div class="ttdeci">object_type * raw() noexcept</div><div class="ttdoc">Direct access to the array of objects. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00465">sparse_set.hpp:465</a></div></div>
|
|
<div class="ttc" id="classentt_1_1SparseSet_3_01Entity_01_4_html_af122c1668ab1efbe0eca5792e9bae434"><div class="ttname"><a href="classentt_1_1SparseSet_3_01Entity_01_4.html#af122c1668ab1efbe0eca5792e9bae434">entt::SparseSet< Entity >::swap</a></div><div class="ttdeci">void swap(pos_type lhs, pos_type rhs) noexcept</div><div class="ttdoc">Swaps the position of two entities in the internal packed array. </div><div class="ttdef"><b>Definition:</b> <a href="sparse__set_8hpp_source.html#l00306">sparse_set.hpp:306</a></div></div>
|
|
<div class="ttc" id="structentt_1_1entt__traits_html"><div class="ttname"><a href="structentt_1_1entt__traits.html">entt::entt_traits</a></div><div class="ttdoc">Entity traits. </div><div class="ttdef"><b>Definition:</b> <a href="traits_8hpp_source.html#l00018">traits.hpp:18</a></div></div>
|
|
</div><!-- fragment --></div><!-- contents -->
|
|
<!-- start footer part -->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated by  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
</a> 1.8.13
|
|
</small></address>
|
|
</body>
|
|
</html>
|