链表(应用篇)

1.概述

链表是在程序设计过程中经常使用的数据结构,bcos系统内部的调度和tasklet的实现都是基于链表。所以,对链表的支持是bcos与生俱来的特性。bcos的链表设计参考了Linux内核链表的设计思想,如果用户想使用链表只需要在自己的数据结构中包含链表头,然后便可以开始使用链表来实现自己的数据结构了。

2.双向循环链表

下面展示了双向循环链表的所有接口并附有简单的解释。每个接口的参数都易于理解,读者很容易理解并使用接口实现利用双向循环链表进行数据的管理。

链表头:

struct list_head{
	struct list_head *next, *prev;
};

初始化链表:

//静态初始化链表
#define LIST_HEAD_INIT(name)    \
{                               \
    &(name),                    \
    &(name),                    \
}

//定义并静态初始化链表
#define LIST_HEAD(name)         \
    struct list_head name = LIST_HEAD_INIT(name)

//动态初始化链表
static inline void INIT_LIST_HEAD(struct list_head *list)

链表节点的添加

//将新节点添加到head后面,如果head为链表头则将新节点添加到链表的最前面
static inline void list_add(struct list_head *new_, struct list_head *head)

//将新节点添加到head前面,如果head为链表头则将新节点添加到链表的最后面
static inline void list_add_tail(struct list_head *new_, struct list_head *head)

链表节点的删除

//将节点从链表中删除并将该节点的prev和next指针赋值为NULL
static inline void list_del(struct list_head *entry)

//将节点从链表中删除并将该节点的prev和next指针指向它自己
static inline void list_del_init(struct list_head *entry)

链表遍历

//从链表头遍历到链表尾
/**
 * list_for_each_entry_safe - iterate over list of given type safe against 
 * removal of list enty.
 * @pos:      the type * to use as a loop sursor.
 * @n:        another type * to use as temporary storage.
 * @head:     the head for your list.
 * @member:   the name of the list_struct within the strut.
 */
#define list_for_each_entry_safe(pos, n, head, member)

//从链表尾逆向遍历到链表头
/**
 * list_for_each_entry_safe_reverse
 * @pos:      the type *  to use as a loop cursor.
 * @n         another type * to use as temporary storage.
 * @head:     the head for your list.
 * @member:   the name of the list_struct within the struct.
 * 
 * Iterate backwards over list of given type, safe against removal
 * of list entry.
 */
#define list_for_each_entry_safe_reverse(pos, n, head,member)

获取链表的第一个节点

/**
 * list_first_entry - get the first element from a list.
 * @ptr:     the list head to take the element from.
 * @type:    the type of the struct this is embedded in.
 * @member:  the name of the list_struct within the struct.
 * 
 * Note, that list is expected to be not empty.
 */
#define list_first_entry(ptr, type, member)

判断是否是链表最后一个节点

/**
 * list_is_last - tests whether @list is the last entry in list @head
 * @list: the entry to test.
 * @head: the head of the list.
 */
static inline int list_is_last(const struct list_head *list,
        const struct list_head *head)

判断链表是否为空

/**
 * list_empty - tests whether a list is empty.
 * @head: the list to test.
 */
static inline int list_empty(const struct list_head *head)

以链表中某个元素为依据,升序的插入节点

/**
 * 在列表中升序插入,值更小的靠近链表头
 */
#define list_ascending_order_add(new_, pos, n, head, member, condition_member)

3.单向循环链表

单向循环链表的实现与双向循环链表类似,它的接口实现与双向循环链表也基本类似。接口如下:

链表头及初始化:

typedef struct slist_s {
	struct slist_s *next;
}slist_t;

//链表的静态初始化
#define SLIST_HEAD_INIT(name)	{&name}

//链表的动态初始化
static inline void slist_init_head(slist_t *head)

链表添加一个节点

//将新节点添加到head的后面
static inline void slist_add(slist_t *new_, slist_t *head)

链表删除节点:

//仅将节点从链表中移除,需要提供将被删除节点的上一个节点
static inline void slist_del(slist_t *prev, slist_t *node)

//将节点从链表中移除并初始化(将节点的next指针指向节点自己)
static inline void slist_del_init(slist_t *prev, slist_t *node)

判断节点是否是链表的最后一个节点

/*
 * list:被判断的链表节点
 * head:链表头
 */
static inline int slist_is_last(const slist_t *list, const slist_t *head)

判断链表是否为空

static inline int slist_empty(const slist_t *head)

对链表进行遍历

#define slist_for_each_entry_safe(pos, n, head, member)

单向循环链表的使用示例具体可以参考内存管理模块的实现。

内容概要:本文档详细介绍了在三台CentOS 7服务器(IP地址分别为192.168.0.157、192.168.0.158和192.168.0.159)上安装和配置Hadoop、Flink及其他大数据组件(如Hive、MySQL、Sqoop、Kafka、Zookeeper、HBase、Spark、Scala)的具体步骤。首先,文档说明了环境准备,包括配置主机名映射、SSH免密登录、JDK安装等。接着,详细描述了Hadoop集群的安装配置,包括SSH免密登录、JDK配置、Hadoop环境变量设置、HDFS和YARN配置文件修改、集群启动与测试。随后,依次介绍了MySQL、Hive、Sqoop、Kafka、Zookeeper、HBase、Spark、Scala和Flink的安装配置过程,包括解压、环境变量配置、配置文件修改、服务启动等关键步骤。最后,文档提供了每个组件的基本测试方法,确保安装成功。 适合人群:具备一定Linux基础和大数据组件基础知识的运维人员、大数据开发工程师以及系统管理员。 使用场景及目标:①为大数据平台建提供详细的安装指南,确保各组件能够顺利安装和配置;②帮助技术人员快速掌握Hadoop、Flink等大数据组件的安装与配置,提升工作效率;③适用于企业级大数据平台的建与维护,确保集群稳定运行。 其他说明:本文档不仅提供了详细的安装步骤,还涵盖了常见的配置项解释和故障排查建议。建议读者在安装过程中仔细阅读每一步骤,并根据实际情况调整配置参数。此外,文档中的命令和配置文件路径均为示例,实际操作时需根据具体环境进行适当修改。
在无线通信领域,天线阵列设计对于信号传播方向和覆盖范围的优化至关重要。本题要求设计一个广播电台的天线布局,形成特定的水平面波瓣图,即在东北方向实现最大辐射强度,在正东到正北的90°范围内辐射衰减最小且无零点;而在其余270°范围内允许出现零点,且正西和西南方向必须为零。为此,设计了一个由4个铅垂铁塔组成的阵列,各铁塔上的电流幅度相等,相位关系可自由调整,几何布置和间距不受限制。设计过程如下: 第一步:构建初级波瓣图 选取南北方向上的两个点源,间距为0.2λ(λ为电磁波波长),形成一个端射阵。通过调整相位差,使正南方向的辐射为零,计算得到初始相位差δ=252°。为了满足西南方向零辐射的要求,整体相位再偏移45°,得到初级波瓣图的表达式为E1=cos(36°cos(φ+45°)+126°)。 第二步:构建次级波瓣图 再选取一个点源位于正北方向,另一个点源位于西南方向,间距为0.4λ。调整相位差使西南方向的辐射为零,计算得到相位差δ=280°。同样整体偏移45°,得到次级波瓣图的表达式为E2=cos(72°cos(φ+45°)+140°)。 最终组合: 将初级波瓣图E1和次级波瓣图E2相乘,得到总阵的波瓣图E=E1×E2=cos(36°cos(φ+45°)+126°)×cos(72°cos(φ+45°)+140°)。通过编程实现计算并绘制波瓣图,可以看到三个阶段的波瓣图分别对应初级波瓣、次级波瓣和总波瓣,最终得到满足广播电台需求的总波瓣图。实验代码使用MATLAB编写,利用polar函数在极坐标下绘制波瓣图,并通过subplot分块显示不同阶段的波瓣图。这种设计方法体现了天线阵列设计的基本原理,即通过调整天线间的相对位置和相位关系,控制电磁波的辐射方向和强度,以满足特定的覆盖需求。这种设计在雷达、卫星通信和移动通信基站等无线通信系统中得到了广泛应用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南波儿万

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值