⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 requesttable.cc

📁 CBRP协议(移动adhoc中基于分簇的路由协议)ns2下的源码
💻 CC
字号:
/* requesttable.h   implement a table to keep track of the most current request   number we've heard from a node in terms of that node's id   $Id: requesttable.cc,v 1.3 1998/05/13 22:21:19 dmaltz Exp $*/#include "path.h"#include "constants.h"#include "requesttable.h"RequestTable::RequestTable(int s): size(s){  table = new Entry[size];  size = size;  ptr = 0;}RequestTable::~RequestTable(){  delete[] table;}intRequestTable::find(const ID& net_id, const ID& MAC_id) const{  for (int c = 0 ; c < size ; c++)    if (table[c].net_id == net_id || table[c].MAC_id == MAC_id)      return c;  return size;}intRequestTable::get(const ID& id) const{  int existing_entry = find(id, id);  if (existing_entry >= size)        {      return 0;    }  return table[existing_entry].req_num;}Entry*RequestTable::getEntry(const ID& id){  int existing_entry = find(id, id);  if (existing_entry >= size)        {      table[ptr].MAC_id = ::invalid_addr;      table[ptr].net_id = id;      table[ptr].req_num = 0;      table[ptr].last_arp = 0.0;      table[ptr].rt_reqs_outstanding = 0;      table[ptr].last_rt_req = -(rt_rq_period + 1.0);      existing_entry = ptr;      ptr = (ptr+1)%size;    }  return &(table[existing_entry]);}voidRequestTable::insert(const ID& net_id, int req_num){  insert(net_id,::invalid_addr,req_num);}voidRequestTable::insert(const ID& net_id, const ID& MAC_id, int req_num){  int existing_entry = find(net_id, MAC_id);  if (existing_entry < size)    {      if (table[existing_entry].MAC_id == ::invalid_addr)	table[existing_entry].MAC_id = MAC_id; // handle creations by getEntry      table[existing_entry].req_num = req_num;      return;    }  // otherwise add it in  table[ptr].MAC_id = MAC_id;  table[ptr].net_id = net_id;  table[ptr].req_num = req_num;  table[ptr].last_arp = 0.0;  table[ptr].rt_reqs_outstanding = 0;  table[ptr].last_rt_req = -(rt_rq_period + 1.0);  ptr = (ptr+1)%size;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -