in reply to RFC: Is there a solution to the flaw in my hash mechanism? (And are there any others?)
my %hash; # hash of stored values my $PRIME = some_large_prime(); # random or fixed, your choice my $PRIME_HALF = int($PRIME/2); # or some other known value or functio +n ... my $i = $initial_index; # wherever you get this from my $failed_tries = $PRIME; while (defined($hash{$i}) and $failed_tries--) { my $offset = $hash{$i} % $PRIME; $offset = $PRIME_HALF if ($offset == 0); $i = ($i + ($hash{$i}) % $PRIME; } if ($failed_tries) { $hash{$i} = $value; } else { warn "Hash full\n"; }
Update: I'm assuming that the hash values, once written, are read only, and never change.
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RFC: Is there a solution to the flaw in my hash mechanism? (And are there any others?)
by BrowserUk (Patriarch) on Jun 03, 2015 at 01:15 UTC |