# 查找表

查找表（lookup table，LUT）是一种预计算数组，程序按索引取回其中的值，而不是在运行时计算相应结果。这项技术以内存换计算：如果查表比从头求值函数更快，或者同一输入被反复查询，那么在常见输入的定义域上预计算该函数会带来显著的性能提升；在存储样本之间插值可以近似落在其间的值<sup>[1](https://developer.nvidia.com/gpugems/gpugems2/part-iii-high-quality-rendering/chapter-24-using-lookup-tables-accelerate-color)</sup>。

| 关键事实 | 详情 |
|---|---|
| 核心思想 | 将函数输出存储在带索引的结构中并取回，而不是重新计算；这是经典的存储与计算之间的权衡<sup>[1](https://developer.nvidia.com/gpugems/gpugems2/part-iii-high-quality-rendering/chapter-24-using-lookup-tables-accelerate-color)</sup> |
| 直接寻址表 | 每个可能键对应一个槽位的数组可实现无冲突的 O(1) 查找，但对于键全集 U 需要 Θ(U) 的空间，因此只适用于小而稠密的键空间<sup>[2](https://www.inf.usi.ch/faculty/carzaniga/edu/algo17s/elementary.pdf)</sup> |
| 哈希表 | 哈希函数将键映射到较小数组中的桶，平均情况下查找、插入和删除均为 O(1)；冲突不可避免，可通过链式法或开放寻址解决<sup>[3](https://comp.anu.edu.au/courses/comp1110/notes/comp1110-4I/)</sup> |
| 装载因子 | 在含 n 个元素、m 个桶的链式表中，期望查找成本为 O(1 + α)，其中 α = n/m；当 α 大致保持在 1/2 到 2 之间时性能最佳<sup>[4](https://www.cs.cornell.edu/courses/cs2112/2015fa/lectures/lec_hashtables/)</sup> |
| 印刷表时代 | 格奥尔格·波伊尔巴赫（Georg Peurbach）的表格论著于1468年首次印行，可能是现存最古老的印刷数学表；印刷表在实际计算中占据主导地位，直至20世纪<sup>[5](https://www.computerhistory.org/revolution/calculators/1/51/212)</sup> |
| 硬件 LUT | 查找表是 FPGA 中的原生计算元件，并在 GPU 上作为基于纹理的预计算函数使用；将其放在 GPU 共享内存而非全局内存中，可使搜索快 2 至 5 倍<sup>[6](https://developer.nvidia.com/blog/accelerating-vector-search-nvidia-cuvs-ivf-pq-performance-tuning-part-2/)</sup> |

## 查表如何工作

最简单的形式是直接寻址表，即键本身就是索引的数组。例如，统计 0 到 99 的每个整数在列表中出现的次数，只需一个以该整数本身为索引的 100 元素计数数组；关键洞见在于，整数就是它自己的索引<sup>[3](https://comp.anu.edu.au/courses/comp1110/notes/comp1110-4I/)</sup>。所有直接寻址操作都在 O(1) 时间内运行，但空间成本为 Θ(U)，即整个键全集的大小，通常远大于实际存储的集合<sup>[2](https://www.inf.usi.ch/faculty/carzaniga/edu/algo17s/elementary.pdf)</sup>。

**哈希缩小表。** 哈希表对每个键应用哈希函数 H，并将条目存储在容量小得多的桶后备数组中位置 H(key) mod capacity 处。对 H 的唯一正确性要求是它尊重相等性：相等的键必须得到相同的哈希值，而不相等的键可以冲突。由于可能的键多于桶，根据鸽巢原理，冲突不可避免；冲突解决策略决定两个键映射到同一个桶时如何处理<sup>[3](https://comp.anu.edu.au/courses/comp1110/notes/comp1110-4I/)</sup>。两种常见策略是链式法（每个桶保存一个条目链表）和线性探测（表向前扫描下一个空槽）；线性探测具有更好的缓存性能，但对已占用槽位的聚集很敏感<sup>[3](https://comp.anu.edu.au/courses/comp1110/notes/comp1110-4I/)</sup>。当表变得过满时，通常将数组加倍并重新哈希所有元素；采用几何增长时，每次操作的摊还成本仍为 O(1)<sup>[4](https://www.cs.cornell.edu/courses/cs2112/2015fa/lectures/lec_hashtables/)</sup>。

替代方案权衡不同的性质。有序数组和搜索树提供 O(log n) 查找，但要求键上具有全序<sup>[3](https://comp.anu.edu.au/courses/comp1110/notes/comp1110-4I/)</sup>。布隆过滤器（Bloom filter）等近似结构以可调假阳性率和零假阴性回答成员查询，使用的内存远少于完整哈希表，但无法取回关联值<sup>[7](https://technav.ieee.org/topic/table-lookup/)</sup>。

## 内存与计算之间的权衡

查找表只有在若干可检验的条件下才划算：出现足够多重复或相似的查询，足以摊薄建表成本；访问表显著快于求值原函数；并且表能在不过度占用内存的情况下满足所需精度<sup>[8](https://pmc.ncbi.nlm.nih.gov/articles/PMC3922221/)</sup>。表大小、采样方法和插值决定速度与精度之间的平衡；手工选择这些参数很容易出错，因此人们构建了源到源工具来自动化分析<sup>[8](https://pmc.ncbi.nlm.nih.gov/articles/PMC3922221/)</sup>。

**在 GPU 上，这种权衡更加尖锐。** 定义域和值域恒定的函数可以预计算为一维、二维或三维纹理图，纹理硬件提供滤波，以在条目之间进行分段线性插值<sup>[9](https://developer.nvidia.com/gpugems/gpugems2/part-iv-general-purpose-computation-gpus-primer/chapter-35-gpu-program-optimization)</sup>。但许多 GPU 应用受内存带宽限制，因此为节省少量计算而增加一次纹理读取可能得不偿失；以不连贯方式访问表会反复冲刷纹理缓存并损害性能<sup>[9](https://developer.nvidia.com/gpugems/gpugems2/part-iv-general-purpose-computation-gpus-primer/chapter-35-gpu-program-optimization)</sup>。放置位置有可测量的影响：在英伟达（NVIDIA）的 cuVS 向量检索库中，将乘积量化查找表放在 GPU 共享内存中，比放在全局内存中使搜索快 2 至 5 倍；将表条目存储为 16 位或 8 位值而非 32 位浮点数，可在不重建索引的情况下将表缩小为原来的 1/2 或 1/4<sup>[6](https://developer.nvidia.com/blog/accelerating-vector-search-nvidia-cuvs-ivf-pq-performance-tuning-part-2/)</sup>。

同样的压力也出现在电子设计自动化中。用于 gm/ID 设计方法的预计算 MOSFET 查找表，视精度而定，每器件可达数 GB；只存储所需点的非完整网格表示可将占用空间减少最多 67%<sup>[10](https://doi.org/10.3390/electronics13183776)</sup>。

## 历史

**印刷表。** 在电子计算出现之前，任何需要超出简单算术的计算的人——从天文学家、航海家到精算师和保险经纪人——都依赖印刷数值表；这些表由手工计算、抄录、核对和排版，因此未被发现的错误始终令人担忧<sup>[11](https://www.computerhistory.org/babbage/history/)</sup>。更早的辅助工具以物理形式封装表格：17世纪初发明的[纳皮尔算筹](https://www.edgepedia.org/zh/napiers-bones)（Napier's bones）是乘法表的一种记忆形式；对数表和函数表书籍一直印刷销售到20世纪60年代<sup>[12](https://tcm.computerhistory.org/reports/TCMReportSpring1987.pdf)</sup>。格奥尔格·波伊尔巴赫（Georg Peurbach）关于正弦与弦的论著于1468年首次印行，可能是现存最古老的印刷数学表<sup>[5](https://www.computerhistory.org/revolution/calculators/1/51/212)</sup>。

**造表的机器。** [查尔斯·巴贝奇](https://www.edgepedia.org/zh/charles-babbage)（Charles Babbage）的差分机一号（Difference Engine No. 1）旨在自动计算多项式并制表，其直接动机正是手工制表中的错误；在与工具制造者约瑟夫·克莱门特（Joseph Clement）发生争执、导致建造于1833年停止后，英国财政部已在这个失败项目上花费了17,500英镑<sup>[11](https://www.computerhistory.org/babbage/history/)</sup>。在美国，[新政](https://www.edgepedia.org/zh/new-deal)工程振兴署（Works Projects Administration）于1938年至1946年资助纽约市的数学表计划（Math Tables Project），雇用人工计算员制作了37卷三角函数、指数、对数表，并在战时制作了用于罗兰导航系统（LORAN）的导航表和弹道表<sup>[13](https://www.nist.gov/mathematics-statistics/prehistory-math-tables-project)</sup>。

**早期计算机内部的表。** IBM 的选择性序列电子计算器（Selective Sequence Electronic Calculator）包含一个专用查表单元，最多可容纳36个固定长度、首尾粘接的带环；为进行月球计算，安装了24个环，以尽可能缩短查表时间<sup>[14](https://www.columbia.edu/cu/computinghistory/ssec-table.html)</sup>。随着硬件改进，通用机器越来越多地计算数值而非查表；20世纪80年代初的手持科学计算器在日常使用中取代了印刷函数表<sup>[12](https://tcm.computerhistory.org/reports/TCMReportSpring1987.pdf)</sup>。

## 现代应用

《ACM 计算综述》（ACM Computing Surveys）中一篇2026年的综述追溯了基于 LUT 的计算，从软件函数求值到硬件，涵盖基于 LUT 的神经网络、FPGA（其中 LUT 是原生可编程元件）以及基于 LUT 的存内计算系统；其出发点是本文开头陈述的同一原理：从内存结构中取回预计算结果，而不是实时计算<sup>[15](https://paperity.org/p/376507313/lookup-table-based-computing-a-survey-from-software-implementations-to-hardware)</sup>。

网络是长期存在的应用领域。IP 路由器必须为每个数据包找到最佳匹配前缀，长期以来人们认为普通哈希不适用于此；瓦尔德福格尔（Waldvogel）、瓦尔盖塞（Varghese）、特纳（Turner）和普拉特纳（Plattner）的方案在按前缀长度组织的哈希表上执行二分搜索，最坏情况下需要 log₂(地址位数) 次哈希查找，即 IPv4 为5次、IPv6 为7次；对于拥有超过33,000条目的骨干路由器，平均少于2次<sup>[16](https://marcel.wanda.ch/Publications/waldvogel97scalable)</sup>。

机器学习重新引发了对超大表的兴趣。硬件工作压缩用于非线性函数求值以及基于表的神经网络和柯尔莫哥洛夫-阿诺德网络（Kolmogorov-Arnold networks）的大型常值表<sup>[17](https://arxiv.org/abs/2609.36634)</sup>；查找表方法加速 SIMD CPU 上的超低精度卷积网络推理<sup>[18](https://arxiv.org/abs/2304.09049)</sup>。

## References

1. [Chapter 24. Using Lookup Tables to Accelerate Color Transformations, GPU Gems 2, NVIDIA](https://developer.nvidia.com/gpugems/gpugems2/part-iii-high-quality-rendering/chapter-24-using-lookup-tables-accelerate-color)
2. [Elementary Data Structures (Carzaniga, Università della Svizzera italiana)](https://www.inf.usi.ch/faculty/carzaniga/edu/algo17s/elementary.pdf)
3. [Hashing and Hash Tables, COMP1110, Australian National University](https://comp.anu.edu.au/courses/comp1110/notes/comp1110-4I/)
4. [Hash Tables lecture notes, CS 2112, Cornell University](https://www.cs.cornell.edu/courses/cs2112/2015fa/lectures/lec_hashtables/)
5. [Tractatus Georgii Peurbachii, Computer History Museum Revolution exhibit](https://www.computerhistory.org/revolution/calculators/1/51/212)
6. [Accelerating Vector Search: NVIDIA cuVS IVF-PQ Part 2, NVIDIA Technical Blog](https://developer.nvidia.com/blog/accelerating-vector-search-nvidia-cuvs-ivf-pq-performance-tuning-part-2/)
7. [Table lookup, IEEE Technology Navigator](https://technav.ieee.org/topic/table-lookup/)
8. [Tool support for software lookup table optimization, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC3922221/)
9. [Chapter 35. GPU Program Optimization, GPU Gems 2, NVIDIA](https://developer.nvidia.com/gpugems/gpugems2/part-iv-general-purpose-computation-gpus-primer/chapter-35-gpu-program-optimization)
10. [Toward Memory-Efficient Analog Design Using Precomputed Lookup Tables, Electronics (MDPI)](https://doi.org/10.3390/electronics13183776)
11. [A Brief History, Babbage Engine, Computer History Museum](https://www.computerhistory.org/babbage/history/)
12. [Pre-computer Memories: Read or Write, The Computer Museum Report, Spring 1987](https://tcm.computerhistory.org/reports/TCMReportSpring1987.pdf)
13. [Prehistory: The Math Tables Project, NIST](https://www.nist.gov/mathematics-statistics/prehistory-math-tables-project)
14. [SSEC Table Lookup Unit, Columbia University Computing History](https://www.columbia.edu/cu/computinghistory/ssec-table.html)
15. [Lookup Table-based Computing: A Survey from Software Implementations to Hardware Architectures, ACM Computing Surveys](https://paperity.org/p/376507313/lookup-table-based-computing-a-survey-from-software-implementations-to-hardware)
16. [Scalable High Speed IP Routing Table Lookups (Waldvogel, Varghese, Turner, Plattner), ACM SIGCOMM 1997](https://marcel.wanda.ch/Publications/waldvogel97scalable)
17. [Lossless Compression of Lookup Tables for Hardware Applications, arXiv](https://arxiv.org/abs/2609.36634)
18. [DeepGEMM: Accelerated Ultra Low-Precision Inference on CPU Architectures using Lookup Tables, arXiv](https://arxiv.org/abs/2304.09049)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Data structures › Lists and linked structures

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/lookup-table

English original: https://www.edgepedia.org/lookup-table
