<div dir="ltr">Dear All,<div><br></div><div>I managed to solve the problem by employing an unordered_map variable. This unordered_map is used to maintain pairs of item names and iterators to items in a policy_container. Because search, erase, and insert operations in an unordered_map normally take constant time, this solution is faster than directly search policy_container for a given name. </div><div><br></div><div>Best regards,</div><div>Saran </div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-11-18 16:37 GMT+09:00 Saran Tarnoi <span dir="ltr"><<a href="mailto:sarantarnoi@gmail.com" target="_blank">sarantarnoi@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Dear All,<div><br></div><div>I am working inside lru-policy.hpp and really need some ideas for code optimization.</div><div><br></div><div>My goal is to get an iterator of a policy_container that points to a content which matches a given content name (ndn::Name).</div><div>I have achieved this goal through the following inline function.</div><div><br></div><div><div>      inline typename policy_container::iterator</div><div>      search_with_name(ndn::Name name_item)</div><div>      {</div><div><span style="white-space:pre-wrap">     </span>typename policy_container::iterator it;</div><div><span style="white-space:pre-wrap">  </span>for (it = policy_container::begin (); it != policy_container::end (); ++it)</div><div><span style="white-space:pre-wrap">      </span>{</div><div><span style="white-space:pre-wrap">        </span>  if (name_item == it->payload()->GetName()) break;</div><div><span style="white-space:pre-wrap">       </span>}</div><div><span style="white-space:pre-wrap">        </span>return it;</div><div>      }</div><div><br></div><div>However, the above code is so slow when policy_container is large (, which makes sense as we will be iterating the check for all items in policy_container in the worst case).</div><div><br></div><div>Is there any faster way to do this?</div><div>Your suggestion will be highly appreciated and I would like to thank you in advance for your time.</div><div><br></div><br><div><div dir="ltr">Best regards,<div>Saran Tarnoi</div></div></div>
</div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Regards,<div>Saran Tarnoi</div><div>Graduate Student</div><div>Department of Informatics</div><div>The Graduate University for Advanced Studies (Sokendai)</div><div>Tokyo, Japan</div></div></div>
</div>