<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Go - 标签 - Victor's Code Journey</title><link>http://www.victorchu.info/tags/go/</link><description>Go - 标签 - Victor's Code Journey</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><managingEditor>victorchu0610@outlook.com (victorchutian)</managingEditor><webMaster>victorchu0610@outlook.com (victorchutian)</webMaster><lastBuildDate>Sat, 10 Oct 2026 16:25:28 +0800</lastBuildDate><atom:link href="http://www.victorchu.info/tags/go/" rel="self" type="application/rss+xml"/><item><title>Swiss Table：Go map 背后的高效 Hash 表</title><link>http://www.victorchu.info/posts/2026/10/c0f61dae/</link><pubDate>Sat, 10 Oct 2026 16:25:28 +0800</pubDate><author><name>victorchutian</name></author><guid>http://www.victorchu.info/posts/2026/10/c0f61dae/</guid><description><![CDATA[<div class="featured-image">
                <img src="/feature-images/algorithm.webp" referrerpolicy="no-referrer">
            </div><h2 id="为什么值得单独讲" class="headerLink">
    <a href="#%e4%b8%ba%e4%bb%80%e4%b9%88%e5%80%bc%e5%be%97%e5%8d%95%e7%8b%ac%e8%ae%b2" class="header-mark"></a>为什么值得单独讲</h2><p>Hash 表的性能通常取决于两件事：冲突发生后如何找下一个候选位置，以及这些候选位置离缓存有多远。传统链式哈希把冲突元素串成链表，逻辑简单，但一次查询可能要跳过多个指针；普通开放寻址没有指针跳跃，却常常只能逐个 slot 检查。</p>
<p>Swiss Table 的核心贡献是在开放寻址表前面加了一层非常小的元数据，让 CPU 能按 group 批量排除大量不可能匹配的 slot。它不改变 hash 表的基本语义，而是改变查找、插入、删除时的观察方式：先用极小的哈希指纹过滤，再对少数候选 key 做精确比较。</p>
<p>这个设计来自 Google 的工程实践，后来成为 Abseil <code>flat_hash_map</code> 的底层实现，也被 Rust 标准库 <code>HashMap</code> 采用。Go 1.24 之后，内置 <code>map</code> 的默认运行时实现也切换到了 Swiss Table 风格。</p>]]></description></item></channel></rss>