[ndnSIM] query about interfaces of a node

Alex Afanasyev alexander.afanasyev at ucla.edu
Wed Nov 26 20:59:04 PST 2014


I haven’t tried, but it should be something like

const_cast<typename Container::iterator>(&(*itm))

—
Alex

> On Nov 26, 2014, at 4:32 PM, Shahneela Naz <shahneela.cs at gmail.com> wrote:
> 
> Dear Sir
> 
> Thanks a lot. I am not using for indexing purpose. ...Kindly can you further explain how I can use const_cast.
> 
> 
> Regards
> shahneela
> 
> On Wed, Nov 26, 2014 at 6:34 PM, Alex Afanasyev <alexander.afanasyev at ucla.edu <mailto:alexander.afanasyev at ucla.edu>> wrote:
> 
>> On Nov 26, 2014, at 2:16 PM, Shahneela Naz <shahneela.cs at gmail.com <mailto:shahneela.cs at gmail.com>> wrote:
>> 
>> Dear sir,
>> 
>> I am doing changes in lifetime_stats_policy.h
>> 
>> I have defined following to associate lifetime value of a content entry
>> 
>> static double& get_time (typename Container::iterator item)
>>     {
>>       return static_cast<typename policy_container::value_traits::hook_type*>
>>         (policy_container::value_traits::to_node_ptr(*item))->LiveTime;
>>     }
>>       
>>     static const double& get_time (typename Container::const_iterator item)
>>        {
>>       return static_cast<const typename policy_container::value_traits::hook_type*>
>>         (policy_container::value_traits::to_node_ptr(*item))->LiveTime;
>>     }
>> 
>> I associate an initial lifetime value to every item I insert...
>> 
>> next I want to update lifetime of all entries already present in cache.. I am doing this way..
>> 
>> for (typename policy_container::const_iterator itm = policy_container::begin ();
>>                 itm != policy_container::end (); itm++){ 
>>                double oldLifeTime = get_time(&(*itm));
>>                double newLifeTime = oldLifetime * 0.6 ; // let us say so 
>>              //  next I want to associate this new value with the item but I am unable to do so;
>> 
>>   }  
> 
> Is this lifetime value is used in indexing purposes in the policy_container?  If so, you cannot replace the value and the only way is to remove the item from the cache, and then re-insert it with the new value.
> 
> If lifetime is not used for indexing purposes, then you can use const_cast.
> 
>> Alex
> 
>> 
>> 
>> On Thu, Oct 16, 2014 at 12:45 PM, Alex Afanasyev <alexander.afanasyev at ucla.edu <mailto:alexander.afanasyev at ucla.edu>> wrote:
>> Can you show the code?...  It's close to impossible to diagnose the problem without seeing the code :(
>> 
>> ---
>> Alex
>> 
>> 
>> On Oct 15, 2014, at 11:53 PM, Shahneela Naz <shahneela.cs at gmail.com <mailto:shahneela.cs at gmail.com>> wrote:
>> 
>>> Dear Sir
>>> 
>>> thanks a lot for your kind response.. I have certain confusions which I feel to explain for your kind consideration.. 
>>> I am not using the values for indexing purpose. lifetime/popularity just an attribute which is attached to an item.it <http://item.it/> could be anything other than time. I just want to update that attribute. it is basically not reordering in my case as I am not using it for indexing. the problem which I have understood is that to iterate over all items in cache I have a reference to address which I increment in each iteration. but to modify/update an attribute of a content (which I have attached previously) I need the actual value (content/item) not reference to its address. 
>>> I am finding it hard to typecast between these two types..
>>> 
>>> I hope I was better able to explain my problem now...
>>> 
>>> regards,
>>> 
>>> shahneela 
>>> 
>>> On Thu, Oct 16, 2014 at 12:09 AM, Alex Afanasyev <alexander.afanasyev at ucla.edu <mailto:alexander.afanasyev at ucla.edu>> wrote:
>>> Hi Shahneela,
>>> 
>>> You're trying to modify value, which is used for indexing purposes inside the policy (i.e., policy sorts all items based on the lifetime, which results in trivial eviction when time comes).
>>> 
>>> Unfortunately, you cannot directly modify time for the items in the policy container.  What you need to do instead is to remove item from the container, update the value, and then reinsert the value into the container.  There is basic example of this in lfu-policy.h, though it doesn't deal with const iterators.
>>> 
>>> With boost::intrusive::multiset you should be able to use `typename policy_container::iterator`.  You still should not directly modify the value (as it would invalidate order), but you should be able to do the conversions.
>>> 
>>> --
>>> Alex
>>> 
>>> On Oct 15, 2014, at 11:55 AM, Shahneela Naz <shahneela.cs at gmail.com <mailto:shahneela.cs at gmail.com>> wrote:
>>> 
>>>> Dear Sir,
>>>> 
>>>> I want to loop over cache contents to change their lifetime with respect to passing time.. for this I am using policy_container::iterator e.g.
>>>> 
>>>> for (typename policy_container::const_iterator item = policy_container::begin ();
>>>>                 item != policy_container::end (); item++)
>>>> 
>>>> the problem is that I can read time value against an item using get_time(&(*item))..
>>>> but when I want to set new value to the same item it requires Container::const_iterator type...
>>>> I am finding it hard to typecast between iterator and const_iterator types which is required to set a value against an item..
>>>> 
>>>> can you kindly help me in this regard..
>>>> 
>>>> regards,
>>>> 
>>>> shahneela  
>>>> 
>>>> 
>>>> 
>>>> On Fri, Sep 12, 2014 at 7:07 PM, Alex Afanasyev <alexander.afanasyev at ucla.edu <mailto:alexander.afanasyev at ucla.edu>> wrote:
>>>> 
>>>> On Sep 12, 2014, at 7:16 AM, Shahneela Naz <shahneela.cs at gmail.com <mailto:shahneela.cs at gmail.com>> wrote:
>>>> 
>>>> > Dear Users,
>>>> >
>>>> > I want to make a little change in cache-with-probability class that if a node has certain number of interfaces it should add a content. For this I want to know number of interfaces to which the node is attached.
>>>> >
>>>> > but when I try to get a node as follows
>>>> >
>>>> > Ptr<Node> n = This->GetObject<Node>();
>>>> >
>>>> > it gives error that the function is defined out of scope. it is the problem due to virtual or inline function calls...
>>>> >
>>>> > can any one kindly help me on this.. If I want to get information related to a node while using policy traits. how can I do this..
>>>> 
>>>> Hi Shaneela,
>>>> 
>>>> Where exactly you're adding this? If you're inside any of the policy methods, you can do something like:
>>>> 
>>>> Ptr<Node> n = item->payload ()->GetContentStore()->template GetObject<Node>();
>>>> 
>>>> Note that there is "template" keyword before GetObject.  Is is necessary, since policy and all policy methods are part of the template implementation.
>>>> 
>>>> ---
>>>> Alex
>>>> 
>>>> 
>>>> > regards,
>>>> >
>>>> > Shahneela
>>>> > _______________________________________________
>>>> > ndnSIM mailing list
>>>> > ndnSIM at lists.cs.ucla.edu <mailto:ndnSIM at lists.cs.ucla.edu>
>>>> > http://www.lists.cs.ucla.edu/mailman/listinfo/ndnsim <http://www.lists.cs.ucla.edu/mailman/listinfo/ndnsim>
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20141126/598037cd/attachment.html>


More information about the ndnSIM mailing list