Need help generating a hash table
古いコメントを表示
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 件のコメント
Nicholas Colburn
2013 年 3 月 12 日
編集済み: Nicholas Colburn
2013 年 3 月 12 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!