[ndnSIM] How to get an iterator to a content in policy_containter given a name

Saran Tarnoi sarantarnoi at gmail.com
Mon Nov 30 21:55:59 PST 2015


Dear All,

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.

Best regards,
Saran

2015-11-18 16:37 GMT+09:00 Saran Tarnoi <sarantarnoi at gmail.com>:

> Dear All,
>
> I am working inside lru-policy.hpp and really need some ideas for code
> optimization.
>
> My goal is to get an iterator of a policy_container that points to a
> content which matches a given content name (ndn::Name).
> I have achieved this goal through the following inline function.
>
>       inline typename policy_container::iterator
>       search_with_name(ndn::Name name_item)
>       {
> typename policy_container::iterator it;
> for (it = policy_container::begin (); it != policy_container::end (); ++it)
> {
>  if (name_item == it->payload()->GetName()) break;
> }
> return it;
>       }
>
> 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).
>
> Is there any faster way to do this?
> Your suggestion will be highly appreciated and I would like to thank you
> in advance for your time.
>
>
> Best regards,
> Saran Tarnoi
>



-- 
Regards,
Saran Tarnoi
Graduate Student
Department of Informatics
The Graduate University for Advanced Studies (Sokendai)
Tokyo, Japan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20151201/5d121d1e/attachment.html>


More information about the ndnSIM mailing list