当前位置: 首页 > news >正文

Redis 源码分析-内部数据结构 dict

Redis 源码分析-内部数据结构 dict

在上一篇 Redis 数据库源码分析 提到了 Redis 其实用了全局的 hash 表来存储所有的键值对,即下方图示的 dict,dict 中有两个数组,其中 ht[1] 只在 rehash 时候才真正用到,平时都是指向 null,hash 的底层又是使用数组来实现的,那就引出了接下来的几个问题:

  • redis 启动初始化这个 dict 时数组容量是多少
  • 如果发生了 hash 冲突怎么办
  • 扩容机制(扩容的时机,扩容的实现)

image-20250106162507568

dict 的创建

/* Create a new hash table */
dict *dictCreate(dictType *type, void *privDataPtr)
{dict *d = zmalloc(sizeof(*d));_dictInit(d,type,privDataPtr);return d;
}/* Initialize the hash table */
int _dictInit(dict *d, dictType *type, void *privDataPtr)
{_dictReset(&d->ht[0]);_dictReset(&d->ht[1]);d->type = type;			d->privdata = privDataPtr;d->rehashidx = -1;d->iterators = 0;return DICT_OK;
}/* Reset a hash table already initialized with ht_init().* NOTE: This function should only be called by ht_destroy(). */
static void _dictReset(dictht *ht)
{ht->table = NULL;ht->size = 0;		// table 的长度, 一定是2的倍数ht->sizemask = 0;	// size - 1,具体原因参见上篇ht->used = 0;		// 已经存的元素总数
}

代码分析:

  • 2行,创建变量时的 dictType *type,包含很多函数指针,无论是添加或查找 key 时 hash 函数还是删除 dictEntry 时的析构函数
  • 25行,ht->table = NULL,也就是说 dict 在被创建时 table 并没有分配内存空间,意味着第一个数据插入时才会真正分配空间。

dict 的扩容

/* Expand the hash table if needed */
static int _dictExpandIfNeeded(dict *d)
{/* Incremental rehashing already in progress. Return. */if (dictIsRehashing(d)) return DICT_OK;/* If the hash table is empty expand it to the initial size. */if (d->ht[0].size == 0) return dictExpand(d, DICT_HT_INITIAL_SIZE);/* If we reached the 1:1 ratio, and we are allowed to resize the hash* table (global setting) or we should avoid it but the ratio between* elements/buckets is over the "safe" threshold, we resize doubling* the number of buckets. */if (d->ht[0].used >= d->ht[0].size &&(dict_can_resize ||d->ht[0].used/d->ht[0].size > dict_force_resize_ratio)){return dictExpand(d, d->ht[0].used*2);}return DICT_OK;
}/* Expand or create the hash table */
int dictExpand(dict *d, unsigned long size)
{/* the size is invalid if it is smaller than the number of* elements already inside the hash table */if (dictIsRehashing(d) || d->ht[0].used > size)return DICT_ERR;dictht n; /* the new hash table */unsigned long realsize = _dictNextPower(size);	// _dictNextPower 根据传入的 size 获得最终分配的 size/* Rehashing to the same table size is not useful. */if (realsize == d->ht[0].size) return DICT_ERR;/* Allocate the new hash table and initialize all pointers to NULL */n.size = realsize;n.sizemask = realsize-1;n.table = zcalloc(realsize*sizeof(dictEntry*));n.used = 0;/* Is this the first initialization? If so it's not really a rehashing* we just set the first hash table so that it can accept keys. */if (d->ht[0].table == NULL) {d->ht[0] = n;return DICT_OK;}/* Prepare a second hash table for incremental rehashing */d->ht[1] = n;d->rehashidx = 0;return DICT_OK;
}/* Our hash table capability is a power of two */
static unsigned long _dictNextPower(unsigned long size)
{unsigned long i = DICT_HT_INITIAL_SIZE;if (size >= LONG_MAX) return LONG_MAX + 1LU;while(1) {if (i >= size)return i;i *= 2;}
}

代码分析:

  • 8行,如果是第一次插入(ht[0].size == 0),用初始化大小(DICT_HT_INITIAL_SIZE)分配,这个值默认是 4
  • 14行,扩容的判断条件,负载因子(d->ht[0].used / d->ht[0].size),即 ht 中元素总数与 bucket 个数的比值
    • 负载因子 >= 1,且 dict_can_resize,dict_can_resize 的值受此时 redis 状态的影响,例如 redis 在进行 aof 重写或 rdb生成时,不想造成太多的内存拷贝,就会关闭
    • 负载因子 >= 5,即 dict_force_resize_ratio 的默认值,此时 hash 冲突已经很严重了,不管此时处于什么状态,都会进行扩容

dict 的销毁

/* Clear & Release the hash table */
void dictRelease(dict *d)
{_dictClear(d,&d->ht[0],NULL);_dictClear(d,&d->ht[1],NULL);zfree(d);
}/* Destroy an entire dictionary */
int _dictClear(dict *d, dictht *ht, void(callback)(void *)) {unsigned long i;/* Free all the elements */for (i = 0; i < ht->size && ht->used > 0; i++) {dictEntry *he, *nextHe;if (callback && (i & 65535) == 0) callback(d->privdata);if ((he = ht->table[i]) == NULL) continue;while(he) {nextHe = he->next;dictFreeKey(d, he);dictFreeVal(d, he);zfree(he);ht->used--;he = nextHe;}}/* Free the table and the allocated cache structure */zfree(ht->table);/* Re-initialize the table */_dictReset(ht);return DICT_OK; /* never fails */
}#define dictFreeKey(d, entry) \if ((d)->type->keyDestructor) \(d)->type->keyDestructor((d)->privdata, (entry)->key)
#define dictFreeVal(d, entry) \if ((d)->type->valDestructor) \(d)->type->valDestructor((d)->privdata, (entry)->v.val)

代码分析:

  • 20-27行:删除每个 dictEntry 时会调用 key 和 value 的析构函数(keyDestructor 和 valDestructor),用于释放键和值所占的内存。

dict 添加元素

主要涉及两个函数,dictAdd 和 dictReplace

dictAdd

该函数向 hash table 中添加数据,如果 key 已经存在会返回失败

/* Add an element to the target hash table */
int dictAdd(dict *d, void *key, void *val)
{dictEntry *entry = dictAddRaw(d,key,NULL);if (!entry) return DICT_ERR;dictSetVal(d, entry, val);return DICT_OK;
}/* Low level add or find:* This function adds the entry but instead of setting a value returns the* dictEntry structure to the user, that will make sure to fill the value* field as he wishes.** This function is also directly exposed to the user API to be called* mainly in order to store non-pointers inside the hash value, example:** entry = dictAddRaw(dict,mykey,NULL);* if (entry != NULL) dictSetSignedIntegerVal(entry,1000);** Return values:** If key already exists NULL is returned, and "*existing" is populated* with the existing entry if existing is not NULL.** If key was added, the hash entry is returned to be manipulated by the caller.*/
dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing)
{long index;dictEntry *entry;dictht *ht;if (dictIsRehashing(d)) _dictRehashStep(d);/* Get the index of the new element, or -1 if* the element already exists. */if ((index = _dictKeyIndex(d, key, dictHashKey(d,key), existing)) == -1)return NULL;/* Allocate the memory and store the new entry.* Insert the element in top, with the assumption that in a database* system it is more likely that recently added entries are accessed* more frequently. */ht = dictIsRehashing(d) ? &d->ht[1] : &d->ht[0];entry = zmalloc(sizeof(*entry));entry->next = ht->table[index];ht->table[index] = entry;ht->used++;/* Set the hash entry fields. */dictSetKey(d, entry, key);return entry;
}

代码分析:

  • 34行判断此时是否正在 rehash,如果在,则将 rehash 向前推进一步
  • 38行,_dictKeyIndex函数根据传入的 key 寻找插入的位置,如果该 key 已经存在,会返回-1
  • 45行,如果此时正在 rehash,就把数据插入到 ht[1],否则插入到 ht[0]
  • 47行-49行,使用头插法插入数据

上面有两个关键函数,一个是_dictKeyIndex,另一个是_dictRehashStep

_dictKeyIndex
/* Returns the index of a free slot that can be populated with* a hash entry for the given 'key'.* If the key already exists, -1 is returned* and the optional output parameter may be filled.** Note that if we are in the process of rehashing the hash table, the* index is always returned in the context of the second (new) hash table. */
static long _dictKeyIndex(dict *d, const void *key, uint64_t hash, dictEntry **existing)
{unsigned long idx, table;dictEntry *he;if (existing) *existing = NULL;/* Expand the hash table if needed */if (_dictExpandIfNeeded(d) == DICT_ERR)return -1;for (table = 0; table <= 1; table++) {idx = hash & d->ht[table].sizemask;/* Search if this slot does not already contain the given key */he = d->ht[table].table[idx];while(he) {if (key==he->key || dictCompareKeys(d, key, he->key)) {if (existing) *existing = he;return -1;}he = he->next;}if (!dictIsRehashing(d)) break;}return idx;
}

代码分析:

  • 15行,会判断此时是否需要扩容
  • 28行,查找时会先从 ht[0] 查找,如果 ht[0] 中没有数据且此时不在进行 rehash,就直接返回

_dictKeyIndex 如果 key 已经存在会返回 -1,否则返回该 key 需要插入的桶的索引。

_dictRehashStep
/* This function performs just a step of rehashing, and only if there are* no safe iterators bound to our hash table. When we have iterators in the* middle of a rehashing we can't mess with the two hash tables otherwise* some element can be missed or duplicated.** This function is called by common lookup or update operations in the* dictionary so that the hash table automatically migrates from H1 to H2* while it is actively used. */
static void _dictRehashStep(dict *d) {if (d->iterators == 0) dictRehash(d,1);
}/* Performs N steps of incremental rehashing. Returns 1 if there are still* keys to move from the old to the new hash table, otherwise 0 is returned.** Note that a rehashing step consists in moving a bucket (that may have more* than one key as we use chaining) from the old to the new hash table, however* since part of the hash table may be composed of empty spaces, it is not* guaranteed that this function will rehash even a single bucket, since it* will visit at max N*10 empty buckets in total, otherwise the amount of* work it does would be unbound and the function may block for a long time. */
int dictRehash(dict *d, int n) {int empty_visits = n*10; /* Max number of empty buckets to visit. */if (!dictIsRehashing(d)) return 0;while(n-- && d->ht[0].used != 0) {dictEntry *de, *nextde;/* Note that rehashidx can't overflow as we are sure there are more* elements because ht[0].used != 0 */assert(d->ht[0].size > (unsigned long)d->rehashidx);while(d->ht[0].table[d->rehashidx] == NULL) {d->rehashidx++;if (--empty_visits == 0) return 1;}de = d->ht[0].table[d->rehashidx];/* Move all the keys in this bucket from the old to the new hash HT */while(de) {uint64_t h;nextde = de->next;/* Get the index in the new hash table */h = dictHashKey(d, de->key) & d->ht[1].sizemask;de->next = d->ht[1].table[h];d->ht[1].table[h] = de;d->ht[0].used--;d->ht[1].used++;de = nextde;}d->ht[0].table[d->rehashidx] = NULL;d->rehashidx++;}/* Check if we already rehashed the whole table... */if (d->ht[0].used == 0) {zfree(d->ht[0].table);d->ht[0] = d->ht[1];_dictReset(&d->ht[1]);d->rehashidx = -1;return 0;}/* More to rehash... */return 1;
}

代码分析:

  • 32-35行,如果 rehashidx 指向的 bucket 里一个 dictEntry 也没有,那么它就没有可迁移的数据。这时它尝试在 ht[0].table 数组中不断向后遍历,直到找到下一个存有数据的 bucket 位置。如果一直找不到,则最多走 n*10 步(empty_visits)。避免在该操作上一直向后遍历,影响响应时间。

  • 43行,原 bucket 里的元素重新 hash 计算后对新的 sizemask 进行余操作,确定在新 table 上的位置。

  • 55-61行,如果 ht[0] 上的数据都迁移到 ht[1] 上了(即d->ht[0].used == 0),那么整个重哈希结束,ht[0] 变成 ht[1] 的内容,而 ht[1] 重置为空。

参考下面这张图:哈希桶即 bucket,entry 即 dictEntry

image-20250109153512305

dictReplace

该函数向 hash table 中添加数据,如果 key 已经存在会替换

/* Add or Overwrite:* Add an element, discarding the old value if the key already exists.* Return 1 if the key was added from scratch, 0 if there was already an* element with such key and dictReplace() just performed a value update* operation. */
int dictReplace(dict *d, void *key, void *val)
{dictEntry *entry, *existing, auxentry;/* Try to add the element. If the key* does not exists dictAdd will succeed. */entry = dictAddRaw(d,key,&existing);if (entry) {dictSetVal(d, entry, val);return 1;}/* Set the new value and free the old one. Note that it is important* to do that in this order, as the value may just be exactly the same* as the previous one. In this context, think to reference counting,* you want to increment (set), and then decrement (free), and not the* reverse. */auxentry = *existing;dictSetVal(d, existing, val);dictFreeVal(d, &auxentry);return 0;
}

代码分析:

  • 12行,如果插入成功(key不存在)entry 就是插入的对象,如果 key 已经存在,则 existing 变量就是对应的 dictEntry
  • 23-26行,注意顺序是先创建并设置新值,再释放旧值。

dict 删除元素

/* Remove an element, returning DICT_OK on success or DICT_ERR if the* element was not found. */
int dictDelete(dict *ht, const void *key) {return dictGenericDelete(ht,key,0) ? DICT_OK : DICT_ERR;
}/* Search and remove an element. This is an helper function for* dictDelete() and dictUnlink(), please check the top comment* of those functions. */
static dictEntry *dictGenericDelete(dict *d, const void *key, int nofree) {uint64_t h, idx;dictEntry *he, *prevHe;int table;if (d->ht[0].used == 0 && d->ht[1].used == 0) return NULL;if (dictIsRehashing(d)) _dictRehashStep(d);h = dictHashKey(d, key);for (table = 0; table <= 1; table++) {idx = h & d->ht[table].sizemask;he = d->ht[table].table[idx];prevHe = NULL;while(he) {if (key==he->key || dictCompareKeys(d, key, he->key)) {/* Unlink the element from the list */if (prevHe)prevHe->next = he->next;elsed->ht[table].table[idx] = he->next;if (!nofree) {dictFreeKey(d, he);dictFreeVal(d, he);zfree(he);}d->ht[table].used--;return he;}prevHe = he;he = he->next;}if (!dictIsRehashing(d)) break;}return NULL; /* not found */
}

代码分析:

  • 17行,如果在 rehash,也推进一步
  • 25-38行,其实就是首先根据 hash 找到对应的 bucket,在链表中删除该元素,找不到则返回 null,根据是否在 rehash 决定只查找 ht[0] 还是 ht[1]
  • 32-33行,删除后会调用 key 和 value 的析构函数(keyDestructor 和 valDestructor)

dict 查找元素

dictEntry *dictFind(dict *d, const void *key)
{dictEntry *he;uint64_t h, idx, table;if (d->ht[0].used + d->ht[1].used == 0) return NULL; /* dict is empty */if (dictIsRehashing(d)) _dictRehashStep(d);h = dictHashKey(d, key);for (table = 0; table <= 1; table++) {idx = h & d->ht[table].sizemask;he = d->ht[table].table[idx];while(he) {if (key==he->key || dictCompareKeys(d, key, he->key))return he;he = he->next;}if (!dictIsRehashing(d)) return NULL;}return NULL;
}

代码分析:

  • 7行,如果此时在 rehash,它也会推进一步
  • 10行,hash 值与 sizemask 取余 = hash % size,这样写的原因是 & 一步到位,而 % 是一直除下去
  • 17行,如果 ht[0] 中没有,且当前不在 rehash,直接返回 null,否则去 ht[1] 中查找

参考资料

【1】Redis(5.0.8)源码

【2】哔哩哔哩-Redis底层设计与源码分析

【3】极客时间-Redis核心技术剖析与实战

相关文章:

Redis 源码分析-内部数据结构 dict

Redis 源码分析-内部数据结构 dict 在上一篇 Redis 数据库源码分析 提到了 Redis 其实用了全局的 hash 表来存储所有的键值对&#xff0c;即下方图示的 dict&#xff0c;dict 中有两个数组&#xff0c;其中 ht[1] 只在 rehash 时候才真正用到&#xff0c;平时都是指向 null&am…...

git相关操作笔记

git相关操作笔记 1. git init git init 是一个 Git 命令&#xff0c;用于初始化一个新的 Git 仓库。执行该命令后&#xff0c;Git 会在当前目录创建一个 .git 子目录&#xff0c;这是 Git 用来存储所有版本控制信息的地方。 使用方法如下&#xff1a; &#xff08;1&#xff…...

STM32小实验2

定时器实验 TIM介绍 TIM&#xff08;Timer&#xff09;定时器 定时器可以对输入的时钟进行计数&#xff0c;并在计数值达到设定值时触发中断 16位计数器、预分频器、自动重装寄存器的时基单元&#xff0c;在72MHz计数时钟下可以实现最大59.65s的定时 不仅具备基本的定时中断…...

Oracle Dataguard(主库为双节点集群)配置详解(2):备库安装 Oracle 软件

Oracle Dataguard&#xff08;主库为双节点集群&#xff09;配置详解&#xff08;2&#xff09;&#xff1a;备库安装 Oracle 软件 目录 Oracle Dataguard&#xff08;主库为双节点集群&#xff09;配置详解&#xff08;2&#xff09;&#xff1a;备库安装 Oracle 软件一、Orac…...

基于 Pod 和 Service 注解的服务发现

基于 Pod 和 Service 注解的服务发现 背景 很多应用会为 Pod 或 Service 打上一些注解用于 Prometheus 的服务发现&#xff0c;如 prometheus.io/scrape: "true"&#xff0c;这种注解并不是 Prometheus 官方支持的&#xff0c;而是社区的习惯性用法&#xff0c;要使…...

操作系统之文件的逻辑结构

目录 无结构文件&#xff08;流式文件&#xff09; 有结构文件&#xff08;记录式文件&#xff09; 分类&#xff1a; 顺序文件 特点&#xff1a; 存储方式&#xff1a; 逻辑结构&#xff1a; 优缺点&#xff1a; 索引文件 目的&#xff1a; 结构&#xff1a; 特点…...

网络分析与监控:阿里云拨测方案解密

作者&#xff1a;俞嵩(榆松) 随着互联网的蓬勃发展&#xff0c;网络和服务的稳定性已成为社会秩序中不可或缺的一部分。一旦网络和服务发生故障&#xff0c;其带来的后果将波及整个社会、企业和民众的生活质量&#xff0c;造成难以估量的损失。 2020 年 12 月&#xff1a; Ak…...

vue实现虚拟列表滚动

<template> <div class"cont"> //box 视图区域Y轴滚动 滚动的是box盒子 滚动条显示的也是因为box<div class"box">//itemBox。 一个空白的盒子 计算高度为所有数据的高度 固定每一条数据高度为50px<div class"itemBox" :st…...

服务器/电脑与代码仓gitlab/github免密连接

git config --global user.name "xxxx" git config --global user.email "xxxxxx163.com" #使用注册GitHub的邮箱 生成对应邮箱的密码对 ssh-keygen -t rsa -b 4096 -C "xxxxxx163.com" 把公钥id_rsa.pub拷贝到github中 Setting----->…...

用户界面软件03

一种标准的满足不同的非功能性需求的技术是对子系统进行不同的考虑……但是一个用户 界面要求有大量的域层面的信息&#xff0c;以符合比较高的人机工程标准&#xff0c;所以&#xff0c;这些分开的子系统还是 紧密地耦合在一起的。 一个软件架构师的标准反应是将不同的非功能…...

年会抽奖Html

在这里插入图片描述 <!-- <video id"backgroundMusic" src"file:///D:/background.mp3" loop autoplay></video> --> <divstyle"width: 290px; height: 580px; margin-left: 20px; margin-top: 20px; background: url(D:/nianhu…...

(一)Ubuntu20.04版本的ROS环境配置与基本概述

前言 ROS不需要在特定的环境下进行安装&#xff0c;不管你是Ubuntu的什么版本或者还是虚拟机都可以按照教程进行安装。 1.安装ROS 一键安装ros及ros2 wget http://fishros.com/install -O fishros && . fishros 按照指示安装你想要的ros。 ros和ros2是可以兼容的…...

深入分析线程安全问题的本质

深入分析线程安全问题的本质 1. 并发编程背后的性能博弈2. 什么是线程安全问题&#xff1f;3. 源头之一&#xff1a;原子性问题3.1. 原子性问题示例3.2. 原子性问题分析3.3. 如何解决原子性问题&#xff1f; 4. 源头之二&#xff1a;可见性问题4.1. 为什么会有可见性问题&#…...

58. Three.js案例-创建一个带有红蓝配置的半球光源的场景

58. Three.js案例-创建一个带有红蓝配置的半球光源的场景 实现效果 本案例展示了如何使用Three.js创建一个带有红蓝配置的半球光源的场景&#xff0c;并在其中添加一个旋转的球体。通过设置不同的光照参数&#xff0c;可以观察到球体表面材质的变化。 知识点 WebGLRenderer …...

插入实体自增主键太长,mybatis-plaus自增主键

1、问题 spring-boot整合mybtais执行insert语句时&#xff0c;主键id为长文本数据。 2、分析问题 1)数据库主键是否自增 2&#xff09;数据库主键的种子值设置的多少 3、解决问题 1&#xff09;数据库主键设置的时自增 3&#xff09;种子值是1 所以排查是数据库的问题 4、继…...

【利用 Unity + Mirror 网络框架、Node.js 后端和 MySQL 数据库】

要实现一个简单的1v1战斗小游戏&#xff0c;利用 Unity Mirror 网络框架、Node.js 后端和 MySQL 数据库&#xff0c;我们可以将其分为几个主要部分&#xff1a;客户端&#xff08;Unity&#xff09;、服务器&#xff08;Node.js&#xff09;和数据库&#xff08;MySQL&#xf…...

https原理

一、基本概念 1、https概念 https&#xff08;全称&#xff1a; Hypertext Transfer Protocol Secure&#xff0c;超文本传输安全协议&#xff09;&#xff0c;是以安全为目标的http通道&#xff0c;简单讲是http的安全版。 2、为啥说http协议不安全呢&#xff1f; 我们用h…...

如何处理京东商品详情接口返回的JSON数据中的缺失值?

1.在 Python 中处理缺失值 使用if - else语句进行检查和处理 假设通过requests库获取了接口返回的 JSON 数据&#xff0c;并使用json模块进行解析&#xff0c;存储在data变量中。 import json import requestsurl "YOUR_API_URL" response requests.get(url) dat…...

window对象

bom dom部分学完了&#xff0c;来看看bom吧~ bom是整个浏览器&#xff0c;本质上bom与dom是包含的关系&#xff0c;window是里面最大的对象 调用的方法默认对象是window&#xff0c;一般都会省略前面的window 创建的全局变量也是属于window的&#xff0c;当然window也可以省…...

(五)ROS通信编程——参数服务器

前言 参数服务器在ROS中主要用于实现不同节点之间的数据共享&#xff08;P2P&#xff09;。参数服务器相当于是独立于所有节点的一个公共容器&#xff0c;可以将数据存储在该容器中&#xff0c;被不同的节点调用&#xff0c;当然不同的节点也可以往其中存储数据&#xff0c;关…...

MySQL常用命令之汇总(Summary of Commonly Used Commands in MySQL)

MySQL常用命令汇总 简介 ‌MySQL是一个广泛使用的开源关系型数据库管理系统&#xff0c;由瑞典的MySQL AB公司开发&#xff0c;现属于Oracle公司。‌ MySQL支持SQL&#xff08;结构化查询语言&#xff09;&#xff0c;这是数据库操作的标准语言&#xff0c;用户可以使用SQL进…...

更新至2023年,各省数字经济变量/各省数字经济相关指标数据集(20个指标)

更新至2023年&#xff0c;各省数字经济相关指标数据集&#xff08;20个指标&#xff09; 1、时间&#xff1a;更新至2023年&#xff0c;具体时间如下 2、指标&#xff1a;互联网宽带接入端口(万个)&#xff08;2006-2023&#xff09;、互联网宽带接入用户(万户)&#xff08;2…...

聚类系列 (二)——HDBSCAN算法详解

在进行组会汇报的时候&#xff0c;为了引出本研究动机&#xff08;论文尚未发表&#xff0c;暂不介绍&#xff09;&#xff0c;需要对DBSCAN、OPTICS、和HDBSCAN算法等进行详细介绍。在查询相关资料的时候&#xff0c;发现网络上对于DBSCAN算法的介绍非常多与细致&#xff0c;但…...

【JavaEE】—— SpringBoot项目集成百度千帆AI大模型(对话Chat V2)

本篇文章在SpringBoot项目中集成百度千帆提供的大模型接口实现Chat问答效果&#xff1a; 一、百度智能云 百度千帆大模型平台是百度智能云推出的一个企业级一站式大模型与AI原生应用开发及服务平台。 注册地址&#xff1a;https://qianfan.cloud.baidu.com/ 注册成功后&…...

一种更激进的Hook实现方案猜想

XXX原创不原创不清楚&#xff0c;暂定为原创。毕竟windows 大神很多XXX 昨天才发现不是原创&#xff0c;这种方案是VEH HOOK的一种实现方案。VEH HOOK很久很久以前都被广泛使用了。只是自己没听说过。好悲哀呀。。。。 激进的猜想&#xff1a; 如果VEH HOOK在内核态处理异常…...

HTML5实现好看的端午节网页源码

HTML5实现好看的端午节网页源码 前言一、设计来源1.1 网站首页界面1.2 登录注册界面1.3 端午节由来界面1.4 端午节习俗界面1.5 端午节文化界面1.6 端午节美食界面1.7 端午节故事界面1.8 端午节民谣界面1.9 联系我们界面 二、效果和源码2.1 动态效果2.2 源代码 源码下载结束语 H…...

微信小程序获取图片使用session(上篇)

概述&#xff1a; 我们开发微信小程序&#xff0c;从后台获取图片现实的时候&#xff0c;通常采用http get的方式&#xff0c;例如以下代码 <image class"user_logo" src"{{logoUrl}}"></image>变量logoUrl为ur图片l的请求地址 但是对于很多…...

RT-DETR融合YOLOv9的下采样模块ADown

RT-DETR使用教程&#xff1a; RT-DETR使用教程 RT-DETR改进汇总贴&#xff1a;RT-DETR更新汇总贴 《YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information》 一、 模块介绍 论文链接&#xff1a;https://arxiv.org/abs/2402.13616 代码链接&…...

【机器学习案列】学生抑郁可视化及预测分析

&#x1f9d1; 博主简介&#xff1a;曾任某智慧城市类企业算法总监&#xff0c;目前在美国市场的物流公司从事高级算法工程师一职&#xff0c;深耕人工智能领域&#xff0c;精通python数据挖掘、可视化、机器学习等&#xff0c;发表过AI相关的专利并多次在AI类比赛中获奖。CSDN…...

CES 2025|美格智能高算力AI模组助力“通天晓”人形机器人震撼发布

当地时间1月7日&#xff0c;2025年国际消费电子展&#xff08;CES 2025&#xff09;在美国拉斯维加斯正式开幕。美格智能合作伙伴阿加犀联合高通在展会上面向全球重磅发布人形机器人原型机——通天晓&#xff08;Ultra Magnus&#xff09;。该人形机器人内置美格智能基于高通QC…...

Linux第一个系统程序---进度条

进度条---命令行版本 回车换行 其实本质上回车和换行是不同概念&#xff0c;我们用一张图来简单的理解一下&#xff1a; 在计算机语言当中&#xff1a; 换行符&#xff1a;\n 回车符&#xff1a;\r \r\n&#xff1a;回车换行 这时候有人可能会有疑问&#xff1a;我在学习C…...

黑马跟学.苍穹外卖.Day04

黑马跟学.苍穹外卖.Day04 苍穹外卖-day04课程内容1. Redis入门1.1 Redis简介1.2 Redis下载与安装1.2.1 Redis下载1.2.2 Redis安装 1.3 Redis服务启动与停止1.3.1 服务启动命令1.3.2 客户端连接命令1.3.3 修改Redis配置文件1.3.4 Redis客户端图形工具 2. Redis数据类型2.1 五种常…...

人生第一次面试之依托答辩

今天收到人生的第一场面试&#xff0c;是东华软件集团。答的那是依托答辩&#xff0c;就面了20分钟&#xff0c;还没考算法。其实依托答辩的效果是意料之中的&#xff0c;这次面试也只是想练练手。 目录 静态变量什么时候加载的&#xff1f; 重写和重载有什么区别&#xff1…...

STM32 : PWM 基本结构

这张图展示了PWM&#xff08;脉冲宽度调制&#xff09;的基本结构和工作流程。PWM是一种用于控制功率转换器输出电压的技术&#xff0c;通过调整信号的占空比来实现对负载的精确控制。以下是详细讲解&#xff1a; PWM 基本结构 1. 时基单元 ARR (Auto-reload register): 自动…...

【大模型(LLM)面试全解】深度解析 Layer Normalization 的原理、变体及实际应用

系列文章目录 大模型&#xff08;LLMs&#xff09;基础面 01-大模型&#xff08;LLM&#xff09;面试全解&#xff1a;主流架构、训练目标、涌现能力全面解析 02-【大模型&#xff08;LLM&#xff09;面试全解】深度解析 Layer Normalization 的原理、变体及实际应用 大模型&…...

《浮岛风云》V1.0中文学习版

《浮岛风云》中文版https://pan.xunlei.com/s/VODadt0vSGdbrVOBEsW9Xx8iA1?pwdy7c3# 一款有着类似暗黑破坏神的战斗系统、类似最终幻想的奇幻世界和100%可破坏体素环境的动作冒险RPG。...

学习threejs,导入babylon格式的模型

&#x1f468;‍⚕️ 主页&#xff1a; gis分享者 &#x1f468;‍⚕️ 感谢各位大佬 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍⚕️ 收录于专栏&#xff1a;threejs gis工程师 文章目录 一、&#x1f340;前言1.1 ☘️THREE.BabylonLoader babyl…...

Django 社团管理系统的设计与实现

标题:Django 社团管理系统的设计与实现 内容:1.摘要 本文介绍了 Django 社团管理系统的设计与实现。通过分析社团管理的需求&#xff0c;设计了系统的架构和功能模块&#xff0c;并使用 Django 框架进行了实现。系统包括社团信息管理、成员管理、活动管理、财务管理等功能&…...

2025 GitCode 开发者冬日嘉年华:AI 与开源的深度交融之旅

在科技的浪潮中&#xff0c;AI 技术与开源探索的火花不断碰撞&#xff0c;催生出无限可能。2025 年 1 月 4 日&#xff0c;由 GitCode 联合 CSDN COC 城市开发者社区精心打造的开年首场开发者活动&#xff1a;冬日嘉年华在北京中关村 • 鼎好 DH3-A 座 22 层盛大举行&#xff0…...

嵌入式系统 tensorflow

&#x1f3ac; 秋野酱&#xff1a;《个人主页》 &#x1f525; 个人专栏:《Java专栏》《Python专栏》 ⛺️心若有所向往,何惧道阻且长 文章目录 探索嵌入式系统中的 TensorFlow&#xff1a;机遇与挑战一、TensorFlow 适配嵌入式的优势二、面临的硬件瓶颈三、软件优化策略四、实…...

Web无障碍

文章目录 &#x1f7e2;Web Accessibility-Web无障碍&#x1f7e2;一、Web Accessibility-Web1. web无障碍设计2. demo3.使用相关相关开源无障碍工具条(调用可能会根据网络有点慢) 如有其他更好方案&#xff0c;可以私信我哦✒️总结 &#x1f7e2;Web Accessibility-Web无障碍…...

Qt使用MySQL数据库(Win)----2.配置MySQL驱动

使用Everything软件&#xff0c;找到mysql.pro文件。并使用qt creator打开mysql.pro。 导入外部库 选择外部库 点击下一步&#xff0c;勾选。 为debug版本添加‘d’作为后缀取消勾选&#xff0c;然后点击下一步 添加后的Pro文件。 这样文件应该是改好了&#xff0c;选择releas…...

记录一下vue2项目优化,虚拟列表vue-virtual-scroll-list处理10万条数据

文章目录 封装BrandPickerVirtual.vue组件页面使用组件属性 select下拉接口一次性返回10万条数据&#xff0c;页面卡死&#xff0c;如何优化&#xff1f;&#xff1f;这里使用 分页 虚拟列表&#xff08;vue-virtual-scroll-list&#xff09;&#xff0c;去模拟一个下拉的内容…...

java 中 main 方法使用 KafkaConsumer 拉取 kafka 消息如何禁止输出 debug 日志

pom 依赖&#xff1a; <dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka</artifactId><version>2.5.14.RELEASE</version> </dependency> 或者 <dependency><groupId>org.ap…...

前端性能优化全攻略:加速网页加载,提升用户体验

前端性能优化全攻略&#xff1a;加速网页加载&#xff0c;提升用户体验 在当今互联网时代&#xff0c;用户对于网页的加载速度和性能要求越来越高。一个快速响应、流畅加载的网页能够极大地提升用户体验&#xff0c;增加用户留存率和满意度。前端性能优化是实现这一目标的关键…...

关于内网外网,ABC类地址,子网掩码划分

本文的三个关键字是&#xff1a;内网外网&#xff0c;ABC类地址&#xff0c;子网掩码划分。围绕以下问题展开&#xff1a; 如何从ip区分外网、内网&#xff1f;win和linux系统中&#xff0c;如何查询自己的内网ip和外网ip。开发视角看内外网更多是处于安全考虑&#xff0c;接口…...

【C++多线程编程:六种锁】

目录 普通互斥锁&#xff1a; 轻量级锁 独占锁&#xff1a; std::lock_guard&#xff1a; std::unique_lock: 共享锁&#xff1a; 超时的互斥锁 递归锁 普通互斥锁&#xff1a; std::mutex确保任意时刻只有一个线程可以访问共享资源&#xff0c;在多线程中常用于保…...

【LeetCode】力扣刷题热题100道(16-20题)附源码 容器 子数组 数组 连续序列 三数之和(C++)

目录 1.盛最多水的容器 2.和为K的子数组 3.最大子数组和 4.最长连续序列 5.三数之和 1.盛最多水的容器 给定一个长度为 n 的整数数组 height 。有 n 条垂线&#xff0c;第 i 条线的两个端点是 (i, 0) 和 (i, height[i]) 。 找出其中的两条线&#xff0c;使得它们与 x 轴…...

WHAT - devicePixelRatio 与像素分辨率

目录 语法理解 devicePixelRatio常见值应用场景注意事项在高分辨率屏幕下的视觉效果 devicePixelRatio 是一个浏览器属性&#xff0c;用来表示设备的物理像素与 CSS 像素之间的比例。它是屏幕显示清晰度的重要指标&#xff0c;特别是在高分辨率屏幕&#xff08;如 Retina 显示屏…...

【cs.CV】25.1.8 arxiv更新速递

—第1篇---- ===== ConceptMaster: 面向扩散Transformer模型的多概念视频定制,无需测试时调优 🔍 关键词: 文本到视频生成, 扩散模型, 多概念定制, 身份解耦 链接1 摘要: 文本到视频生成通过扩散模型取得了显著进展。然而,多概念视频定制(MCVC)仍然是一个重大挑战。…...