当元素已知时如何避免散列冲突

How to avoid hash-collision when elements are known

如果我们在构建哈希之前知道输入的大小,是否可以避免哈希函数中的哈希冲突 table? 换句话说,我们如何才能在 O(1) 时间内完成最坏情况的插入?

您要的是 perfect hash function. There are many known algorithms for this (see this article in Dr. Dobbs' on one such algorithm). Most of them rely on some randomized parameterized scheme that has a nontrivial chance of finding no collisions. Once such a parameter is found, you have a perfect hash. See this lecture 可读简介。