AODV链表
来源:互联网 发布:科技感 设计 知乎 编辑:程序博客网 时间:2024/06/13 21:37
原文地址:http://blog.csdn.net/ise_gaoyue1990/article/details/7625709
ns2中的链表定义在ns\lib\bsd-list.h下面,下面看一下里面的代码:
- #define LIST_HEAD(name, type) \
- struct name { \
- type *lh_first; /* first element */ \
- }
#define LIST_HEAD(name, type)\struct name {\type *lh_first;/* first element */\}
定义了一个结构体name和一个type类型的*lh_first指针,指向结构体的头。name是链表的名字,元素类型必须是type类型。
- #define LIST_ENTRY(type) \
- struct { \
- type *le_next; /* next element */ \
- type **le_prev; /* address of previous next element */ \
- }
#define LIST_ENTRY(type)\struct {\type *le_next;/* next element */\type **le_prev;/* address of previous next element */\}
定义了两个type类型的指针,*le_next表示链表的下一个元素,**le_prev表示之前下一个元素的地址。这个结构体入口处只给了元素是type类型,并未给出结构体的名字,这在之后会介绍到。
下面是关于链表的一些具体操作
- #define LIST_INIT(head) { \// 这个操作是将链表初始为空。
- #define LIST_INSERT_AFTER(listelm, elm, field) {\
- //这个操作实际是将elm插入到listelm后。
- #define LIST_INSERT_BEFORE(listelm, elm, field) \
- //功能时将elm插入到listelm前面
- #define LIST_INSERT_HEAD(head, elm, field)
- //功能时将elm插入到表头
- #define LIST_REMOVE(elm, field)
- //功能时将elm除去
#defineLIST_INIT(head) {\//这个操作是将链表初始为空。#define LIST_INSERT_AFTER(listelm, elm, field) {\//这个操作实际是将elm插入到listelm后。#define LIST_INSERT_BEFORE(listelm, elm, field) \//功能时将elm插入到listelm前面#define LIST_INSERT_HEAD(head, elm, field)//功能时将elm插入到表头#define LIST_REMOVE(elm, field)//功能时将elm除去
下面来看看AODV前缀列表这个链表:
- class AODV_Precursor {
- friend class AODV;
- friend class aodv_rt_entry;
- public:
- AODV_Precursor(u_int32_t a) { pc_addr = a; }
- protected:
- LIST_ENTRY(AODV_Precursor) pc_link;
- nsaddr_t pc_addr; // precursor address
- };
class AODV_Precursor { friend class AODV; friend class aodv_rt_entry; public: AODV_Precursor(u_int32_t a) { pc_addr = a; } protected: LIST_ENTRY(AODV_Precursor) pc_link; nsaddr_t pc_addr;// precursor address};
- LIST_HEAD(aodv_precursors, AODV_Precursor);
LIST_HEAD(aodv_precursors, AODV_Precursor);
在LIST_HEAD中,aodv_precursors表示结构体的名字,AODV_Precursor表示结构体中的指针变量。在LIST_ENTRY中,AODV_Precursor表示指针变量,pc_link表示指针结构体的名字,因为在LIST_ENTRY中没有定义结构体变量的名字,上面的field域就是指的pc_link。接下来看一下前缀链表的操作。
- AODV_Precursor*
- aodv_rt_entry::pc_lookup(nsaddr_t id)
- {
- AODV_Precursor *pc = rt_pclist.lh_first;
- for(; pc; pc = pc->pc_link.le_next) {
- if(pc->pc_addr == id)
- return pc;
- }
- return NULL;
- }
AODV_Precursor*aodv_rt_entry::pc_lookup(nsaddr_t id){AODV_Precursor *pc = rt_pclist.lh_first; for(; pc; pc = pc->pc_link.le_next) { if(pc->pc_addr == id) return pc; } return NULL;}
这个函数就是遍历链表,若找到满足条件则返回真;否则返回假。
- void
- aodv_rt_entry::pc_delete(nsaddr_t id) {
- AODV_Precursor *pc = rt_pclist.lh_first;
- for(; pc; pc = pc->pc_link.le_next) {
- if(pc->pc_addr == id) {
- LIST_REMOVE(pc,pc_link);
- delete pc;
- break;
- }
- }
- }
voidaodv_rt_entry::pc_delete(nsaddr_t id) {AODV_Precursor *pc = rt_pclist.lh_first; for(; pc; pc = pc->pc_link.le_next) { if(pc->pc_addr == id) { LIST_REMOVE(pc,pc_link); delete pc; break; } }}
这个表示删除链表中的一个元素,遍历后,调用LIST_REMOVE(elm, field)。
- AODV链表
- AODV链表
- AODV.tcl
- aodv之一
- AODV协议
- aodv.cc
- NS2下AODV协议aodv.cc注释
- NS2下AODV协议aodv.cc注释
- NS2下AODV协议aodv.cc注释
- AODV协议概述
- aodv协议源代码分析
- aodv协议功能
- AODV=DSR+DSDV
- aodv协议源代码分析
- AODV协议分析
- AODV的消息格式
- 图解AODV协议(demo)
- AODV协议分析
- 【HTML5】最好的HTML 5编码教程和参考手册分享
- iframe 自适应高度
- BO/MSTR/Cognos共同面对的表连接问题
- TCP和UDP区别
- 用Dos命令复制远程计算机中的文件
- AODV链表
- Oracle入门(一) 不可不知的专业术语
- 11-05作业
- Android ListView怎么取消点击效果
- Win8 应用开发介绍(一) Win8新特性
- jquery js 页面元素定位
- objective-C: NSString应该用initWithFormat? 还是 stringWithFormat?
- c#获取当前日期时间(转)
- 11-06作业