wow-slist文件说明

server/2024/12/23 1:30:27/

wow-slist文件说明

  • 项目地址:https://gitee.com/wow-iot/wow-iot7
  • 本文件的的功能主要用于链表相关操作,主要涉及创建、销毁、插入、查找、移除、替换、获取、清空、遍历;

创建与销毁:

Slist_T* wow_slist_create(void)
{Slist_T *slist = CALLOC(1,Slist_T);CHECK_RET_VAL_ERRNO_P(slist,-SYSTEM_MALLOC_FAILED,"malloc Slist_T failed!\n");memset(slist,0,sizeof(Slist_T));slist->head = NULL;slist->tail = NULL;slist->entries = 0;return (Slist_T*)slist;
}void wow_slist_destroy(Slist_T** pptSlist, slist_destroy_func_t destroy)
{CHECK_RET_VOID(pptSlist && *pptSlist);Slist_T* slist = (Slist_T*)*pptSlist;wow_slist_clear(slist, destroy);FREE(slist);*pptSlist = NULL;
}

在索引出插入

int wow_slist_insert_by_index(Slist_T* ptSlist, int nIdx, void *pData)
{SlistEntry_T *new_entry = NULL;CHECK_RET_VAL_P(ptSlist,-PARAM_INPUT_STRUCT_IS_NULL,"param input struct invalid!\n");CHECK_RET_VAL_P(pData,-PARAM_INPUT_DATA_IS_NULL,"param input data invalid!\n");new_entry = CALLOC(1, SlistEntry_T);CHECK_RET_VAL_P(new_entry,-SYSTEM_MALLOC_FAILED,"malloc SlistEntry_T faild!\n");memset(new_entry,0,sizeof(SlistEntry_T));new_entry->data = pData;if(nIdx <= 0){new_entry->next = ptSlist->head;ptSlist->head = new_entry;if (ptSlist->tail == NULL){ptSlist->tail = new_entry;}		}else if(nIdx > ptSlist->entries){	if (ptSlist->tail){ptSlist->tail->next = new_entry;}ptSlist->tail = new_entry;if (ptSlist->head == NULL){ptSlist->head = new_entry;}}else{//查找索引位置SlistEntry_T *entry = NULL;for (entry = ptSlist->head; entry && nIdx > 1; entry = entry->next,nIdx--);if(entry == NULL){FREE(new_entry);return -WOW_FAILED;}new_entry->next = entry->next;if (!entry->next)ptSlist->tail = new_entry;entry->next = new_entry;}ptSlist->entries++;
return WOW_SUCCESS;

}

获取内容

void* wow_slist_peek_by_match(Slist_T* ptSlist,slist_match_func_t fMatch,const void *pArg)
{SlistEntry_T *entry;CHECK_RET_VAL_ERRNO_P(ptSlist,-PARAM_INPUT_STRUCT_IS_NULL,"param input struct invalid!\n");CHECK_RET_VAL_ERRNO_P(fMatch,-PARAM_INPUT_DATA_IS_NULL,"param input func invalid!\n");	CHECK_RET_VAL_ERRNO_P(pArg,-PARAM_INPUT_DATA_IS_NULL,"param input data invalid!\n");	for (entry = ptSlist->head; entry; entry = entry->next)if (fMatch(entry->data, pArg))return entry->data;return NULL;
}

移除内容

int wow_slist_remove_by_index(Slist_T* ptSlist, int nIdx)
{
SlistEntry_T *entry = NULL;
SlistEntry_T *prev	= NULL;CHECK_RET_VAL_P(ptSlist,PARAM_INPUT_STRUCT_IS_NULL,"param input struct invalid!\n");
CHECK_RET_VAL_P(nIdx >= 0 && nIdx < ptSlist->entries,PARAM_INPUT_ARG_INVALID,"param input arg invalid!\n");	for (entry = ptSlist->head; entry && nIdx--;prev = entry, entry = entry->next);
CHECK_RET_VAL_P(entry,-1,"remove nIdx entry failed!\n");if (prev)prev->next = entry->next;
elseptSlist->head = entry->next;if (!entry->next) ptSlist->tail = prev;FREE(entry);
ptSlist->entries--;return WOW_SUCCESS;
}

替换链表数据内容

int wow_slist_replace_by_index(Slist_T* ptSlist,int nIdx,void *pData)
{SlistEntry_T *entry = NULL;CHECK_RET_VAL_P(ptSlist,PARAM_INPUT_STRUCT_IS_NULL,"param input struct invalid!\n");CHECK_RET_VAL_P(nIdx >= 0 && nIdx < ptSlist->entries,PARAM_INPUT_ARG_INVALID,"param input arg invalid!\n");	for (entry = ptSlist->head; entry && nIdx--; entry = entry->next);CHECK_RET_VAL_P(entry,-1,"peek nIdx entry failed!\n");entry->data = pData;return WOW_SUCCESS;
}

清空链表

 int wow_slist_clear(Slist_T* ptSlist,  slist_destroy_func_t fDestroy)
{SlistEntry_T *entry = NULL;SlistEntry_T *tmp   = NULL;CHECK_RET_VAL_P(ptSlist,-PARAM_INPUT_STRUCT_IS_NULL,"param input struct invalid!\n");CHECK_RET_VAL(ptSlist->head,0);for (entry = ptSlist->head; entry; entry = tmp){if(fDestroy) {fDestroy(entry->data);}tmp = entry->next;FREE(entry);}memset(ptSlist, 0, sizeof(Slist_T));ptSlist->head = NULL;ptSlist->tail = NULL;ptSlist->entries = 0; return WOW_SUCCESS;
}

http://www.ppmy.cn/server/18969.html

相关文章

用 Python 创建 Voronoi 图

概述 最常见的空间问题之一是找到距离我们当前位置最近的兴趣点 (POI)。假设有人很快就会耗尽汽油&#xff0c;他/她需要在为时已晚之前找到最近的加油站&#xff0c;解决这个问题的最佳解决方案是什么&#xff1f;当然&#xff0c;驾驶员可以检查地图来找到最近的加油站&…

GEM TSU Interface Details and IEEE 1588 Support

摘要&#xff1a;Xilinx ZNYQ ULTRASCALE MPSOC的GEM和1588的使用 对于FPGA来说&#xff0c;只需要勾选一些znyq的配置就行了&#xff0c;其余的都是软件的工作&#xff1b; 所有配置都勾选之后&#xff0c;最终会露出来的接口如下&#xff1a; GEM需要勾选的配置如下&#xf…

【C++】哈希思想

目录 哈希介绍&#xff1a; 一&#xff0c;位图 1-1&#xff0c;位图的认识 1-2&#xff0c;位图的简单实现 1-3&#xff0c;位图的应用 二&#xff0c;布隆过滤器 2-1&#xff0c;布隆过滤器的认识 2-2&#xff0c;布隆过滤器的简单实现 2-3&#xff0c;布隆过滤器的…

Android Glide 获取动图的第一帧

一、说明 Glide 可以加载 2 种动图&#xff0c;一种是 Gif 图&#xff0c;另一种是 Webp 动图。 有时候我们需要获取动图的第一帧&#xff0c;并以封面的形式显示&#xff0c;那该怎样获取呢&#xff1f; 二、获取 Webp 第一帧 我这儿的 Webp 显示用到了一个三方库&#xf…

从零入门区块链和比特币(第二期)

欢迎来到我的区块链与比特币入门指南&#xff01;如果你对区块链和比特币感兴趣&#xff0c;但不知道从何开始&#xff0c;那么你来对地方了。本博客将为你提供一个简明扼要的介绍&#xff0c;帮助你了解这个领域的基础知识&#xff0c;并引导你进一步探索这个激动人心的领域。…

QT中基于TCP的网络通信

QT中基于TCP的网络通信 QTcpServer公共成员函数信号 QTcpSocket公共成员函数信号 通信流程服务器端通信流程代码 客户端通信流程代码 使用Qt提供的类进行基于TCP的套接字通信需要用到两个类&#xff1a; QTcpServer&#xff1a;服务器类&#xff0c;用于监听客户端连接以及和客…

基于streamlit快速部署机器学习项目(Public URL)

基于streamlit的AIGC项目前端展示 1.Streamlit 简介与入门1.1 安装 Streamlit1.2 开发Streamlit应用程序1.3 启动并运行1.3.1 本地运行1.3.2 部署 现在LLM技术发展迅速&#xff0c;很多人在学习的时候&#xff0c;都想展示效果&#xff0c;并且想部署在服务器上&#xff0c;但是…

WPF 资源基础

动态资源/静态资源 UI代码 <Window x:Class"WpfApp1.MainWindow"xmlns"http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x"http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d"http://schemas.microsoft.com/ex…