dict.c — 哈希表数据结构

源文件:src/dict.c · 共 2341 行 C 代码

模块职责

Redis 自实现的渐进式 rehashing 字典,是数据库底层核心。

文件头注释

/* Hash Tables Implementation.
 *
 * This file implements in memory hash tables with insert/del/replace/find/
 * get-random-element operations. Hash tables will auto resize if needed
 * tables of power of two in size are used, collisions are handled by
 * chaining. See the source code for more information... :)
 *
 * Copyright (c) 2006-Present, Redis Ltd.
 * All rights reserved.
 *
 * Licensed under your choice of (a) the Redis Source Available License 2.0
 * (RSALv2); or (b) the Server Side Public License v1 (SSPLv1); or (c) the
 * GNU Affero General Public License v3 (AGPLv3).
 */

主要数据结构与函数

  • 数据结构:见 src/dict.h 同名头文件
  • 关键函数:通过 grep -nE '^(void|int|robj\*|sds|list|dict|client|server)' src/dict.c 检索

阅读路径建议

  1. 先看 dict.h 头文件了解对外接口
  2. 再读本文件顶部 #include 列表确认依赖
  3. ^[a-z_]+Init\( 类入口函数作为切入点