6 ms·
Yea if I cast the large calculated integers to strings, performance is O(1) `values = [str(i * M) for i in range(1, n + 1)]` or `values = [i * M % 1_000_000_
by brody_hamer 6d ago
Yea if I cast the large calculated integers to strings, performance is O(1)
`values = [str(i * M) for i in range(1, n + 1)]`
or
`values = [i * M % 1_000_000_000_000_000 for i in range(1, n + 1)]`
- jldugger 6d agoPart of the secret explained elsewhere on this HN post is that the OP is selecting values that all collide. Most hash tables handle collisions with linked lists that would be linear insert. It's O(1) average case but O(n) if you pull an "oops all collisions on the same bucket" stunt.