[Click] How to remove a row from a HashMap table

sendoa vaz sendoav at gmail.com
Sat Sep 20 10:33:59 EDT 2008


Hello everybody,

I am trying to delete a row in my HashMap table declared as :

 typedef HashMap<EtherAddress, AddrInfo> Table;

where AddrInfo is

struct AddrInfo {
    uint16_t vlan;
    int port;
    uint16_t priority;
    Timestamp stamp;
    inline AddrInfo(uint16_t dir_vlan,int p,uint16_t prioridad,const
Timestamp &t);
    };

What I would like to do is to find a row giving the values of EtherAddress,
_vlan,port, priority and Timestamp and remove that row. I am trying to
rewrite a new remove function from the one which is in the bighashmap.cc but
the problem is that I don't know how to compare the values from the AddrInfo
field.

The code I have rewritten is

template <class K, class V>
bool
HashMap<K, V>::remove_eth(const K &key,const V &value)
{
  size_t b = bucket(key);

  Elt *prev = 0;
  Elt *e = _buckets[b];

  while (e && !(e->key == key)) {
    prev = e;
    e = e->next;
  }
  if (e)
  {
    while(e->value!=value){
     prev = e;
    e = e->next;
     }
    if (prev)
      prev->next = e->next;
    else
      _buckets[b] = e->next;
    e->key.~K();
    e->value.~V();
    _arena->free(e);
    _n--;
    return true;
  } else
    return false;
}

But the problem is that I can't use the operator != to compare the V value.

Anyone has any idea?

Thanks in advance

Sendoa


More information about the click mailing list