3 ms·
> An indexed array is a degenerate example in which the "hash" (pointer) is presumably a lot smaller than the key (index). No, it isn't. The "0" in arr[0] is
by da_chicken 8y ago
> An indexed array is a degenerate example in which the "hash" (pointer) is presumably a lot smaller than the key (index).
No, it isn't.
The "0" in arr[0] is (in most cases) a 32-bit signed integer. If you're using a signed 32-bit int to index your array, you're using a hash length of 32-bits. You won't be able to index more than 2.1 billion unique items without changing your data type. Even if you're not using all those bits, you're still using 32-bits to index them. The fact that you're storing something that may have more than 32 bits of information is irrelevant, because your array (a naive hash) doesn't consider them real values.
If you want to store a set of N elements in an array or perfectly hash a set of N elements, then the set of all possible indexes or hashes must have at least N elements.
- gumby 8y agoIt's the lemma I challenge, not the common case on certain of today's architectures. The use of the word "must" implies ∀, which is plainly not the case.
- da_chicken 8y agoYou're not explaining yourself at all. How do you propose to put 10 pounds of shit in a 5 pound bag?
- bjourne 8y agoIf it is not the case, can you present a counter-example? Can you code it up in say Python?