news 2026/6/10 21:53:09

[Linux]学习笔记系列 -- hashtable

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
[Linux]学习笔记系列 -- hashtable

title: hashtable
categories:

  • linux
  • include
    tags:
  • linux
  • include
    abbrlink: 14dfa8ed
    date: 2025-10-03 09:01:49

https://github.com/wdfk-prog/linux-study

文章目录

  • include/linux/hashtable.h
    • DEFINE_HASHTABLE 定义哈希表
    • hlist_for_each_entry 遍历哈希表
    • hash_add 将一个对象添加到哈希表

include/linux/hashtable.h

DEFINE_HASHTABLE 定义哈希表

#defineDEFINE_HASHTABLE(name,bits)\structhlist_headname[1<<(bits)]=\{[0...((1<<(bits))-1)]=HLIST_HEAD_INIT}

hlist_for_each_entry 遍历哈希表

#definehlist_entry(ptr,type,member)container_of(ptr,type,member)#definehlist_for_each(pos,head)\for(pos=(head)->first;pos;pos=pos->next)#definehlist_for_each_safe(pos,n,head)\for(pos=(head)->first;pos&&({n=pos->next;1;});\pos=n)#definehlist_entry_safe(ptr,type,member)\({typeof(ptr)____ptr=(ptr);\____ptr?hlist_entry(____ptr,type,member):NULL;\})/** * hlist_for_each_entry - 遍历给定类型的列表 * @pos: 用作循环游标的类型 *。 * @head: 您列表的开头。 * @member: 结构体内 hlist_node 的名称。 */#definehlist_for_each_entry(pos,head,member)\for(pos=hlist_entry_safe((head)->first,typeof(*(pos)),member);\pos;\pos=hlist_entry_safe((pos)->member.next,typeof(*(pos)),member))/** * hash_for_each_possible - 遍历所有可能哈希到同一桶的对象 * @name: 要遍历的哈希表 * @obj: 用作每个条目的循环游标的类型* * @member: 结构体内 hlist_node 的名称 * @key: 要遍历的对象的键 */#definehash_for_each_possible(name,obj,member,key)\hlist_for_each_entry(obj,&name[hash_min(key,HASH_BITS(name))],member)

hash_add 将一个对象添加到哈希表

/** * hlist_add_head - add a new entry at the beginning of the hlist * @n: new entry to be added * @h: hlist head to add it after * * Insert a new entry after the specified head. * This is good for implementing stacks. */staticinlinevoidhlist_add_head(structhlist_node*n,structhlist_head*h){structhlist_node*first=h->first;WRITE_ONCE(n->next,first);if(first)WRITE_ONCE(first->pprev,&n->next);WRITE_ONCE(h->first,n);WRITE_ONCE(n->pprev,&h->first);}/** * hash_add - 将一个对象添加到哈希表 * @hashtable: 要添加到的哈希表 * @node: 要添加的对象的 &struct hlist_node * @key: 要添加的对象的键 */#definehash_add(hashtable,node,key)\hlist_add_head(node,&hashtable[hash_min(key,HASH_BITS(hashtable))])
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/10 13:53:27

Vue Super Flow:快速上手Vue流程图组件库

Vue Super Flow&#xff1a;快速上手Vue流程图组件库 【免费下载链接】vue-super-flow Flow chart component based on Vue。vue flowchart 项目地址: https://gitcode.com/gh_mirrors/vu/vue-super-flow 在前端开发领域&#xff0c;高效、灵活且易用的UI组件是项目成功…

作者头像 李华
网站建设 2026/6/10 13:59:09

Video2X终极指南:免费AI视频无损放大工具快速上手

Video2X终极指南&#xff1a;免费AI视频无损放大工具快速上手 【免费下载链接】video2x A lossless video/GIF/image upscaler achieved with waifu2x, Anime4K, SRMD and RealSR. Started in Hack the Valley II, 2018. 项目地址: https://gitcode.com/gh_mirrors/vi/video2…

作者头像 李华
网站建设 2026/6/10 13:53:56

如何快速上手UKB_RAP数据分析:从入门到精通的完整指南

如何快速上手UKB_RAP数据分析&#xff1a;从入门到精通的完整指南 【免费下载链接】UKB_RAP Access share reviewed code & Jupyter Notebooks for use on the UK Biobank (UKBB) Research Application Platform. Includes resources from DNAnexus webinars, online train…

作者头像 李华
网站建设 2026/6/10 2:04:55

番茄小说下载器终极指南:轻松保存全网热门小说内容

番茄小说下载器终极指南&#xff1a;轻松保存全网热门小说内容 【免费下载链接】fanqienovel-downloader 下载番茄小说 项目地址: https://gitcode.com/gh_mirrors/fa/fanqienovel-downloader 想要永久珍藏番茄小说平台上的精彩作品吗&#xff1f;这款功能强大的免费开源…

作者头像 李华
网站建设 2026/6/10 13:55:10

OFDRW实战指南:5步快速掌握OFD文档处理全技能

OFDRW实战指南&#xff1a;5步快速掌握OFD文档处理全技能 【免费下载链接】ofdrw OFD Reader & Writer 开源的OFD处理库&#xff0c;支持文档生成、数字签名、文档保护、文档合并、转换、导出等功能&#xff0c;文档格式遵循《GB/T 33190-2016 电子文件存储与交换格式版式文…

作者头像 李华