Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有固定数量的存储桶和 N 个输入。我希望 N 的前 n 个值进入同一个桶,例如
如果我有 6 个存储桶和 16 个条目,我希望前 3 个值 (0,1,2) 进入存储桶 1,
(3,4,5) 桶 2 等。条目按升序排序。
我可以使用哪个散列函数?
那为什么不直接使用整数除法呢?
for i, entry in enumerate(entries): bucket = i // 3 # insert into choosen bucket number
对于 0、1 和 2,这将导致 bucket 0,对于 3、4 和 5,它将是1等等。
0
1