<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi,<br><br>I noticed that several of the engine's nwscript 'functions_object.cpp' files use a similar '<span class="gmail-pl-en">Functions::getNearestObject' call to find the 'nth' nearest object. This relies on (the o(n log(n)) efficient) "</span><span class="gmail-pl-en">objects.<span class="gmail-pl-c1">sort</span>(<span class="gmail-pl-c1">ObjectDistanceSort</span>(*target))" call for ordered comparisons.<br><br>However, in the common case where 'nth' is one, I think it should always be faster to use a "find minimum" call.</span><span class="gmail-pl-en"><span class="gmail-pl-en"></span> (Particularly when the object count is very large.)</span> Perhaps there could be an if-then-else branch just before the sort, and the nth == 1 branch could use s<span class="gmail-pl-en">omething like (the o(n) efficient) 'std::min', for example? Would that make sense?</span><br><br>A similar argument holds for <span class="gmail-pl-en">getNearestObjectByTag and </span><br><span class="gmail-pl-en"><span class="gmail-pl-en">getNearestCreature functions.</span></span></div><div dir="ltr"><span class="gmail-pl-en"></span><div><br>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>  Bob</div></div></div></div></div></div></div></div></div>
</div></div></div></div></div></div></div></div>