Need help generating a hash table
Show older comments
So hopefully someone here knows something about making hash tables. I have to generate a hash table of load alpha from seq1 which is an array of randomly generated numbers between 0 and 10,000. What I'm having trouble with is actually inserting the numbers into the table. So far my code seems to be getting stuck in a loop or its efficiency is so far gone that my computer cannot produce an answer in a reasonable amount of time. Below is my code for making the hash table where a is the load factor alpha specified by the user (a < 1) and m is the table size, in this case m=9973. Seq1 was created using the randi function.
function [ T ] = MakeAHashTable(seq1,a,m)
n = floor(a.*m);
T = zeros(size(seq1));
index = 1;
i = 0;
while i <= m || n ~= 0
k = seq1(index);
j = mod(k+i,m)+1;
if T(j) == 0
T(j) = k;
index = index+1;
i = 0;
n = n-1;
else i = i+1
end
end
end
1 Comment
Nicholas Colburn
on 12 Mar 2013
Edited: Nicholas Colburn
on 12 Mar 2013
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!