-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_hash_hits.m
52 lines (40 loc) · 1.61 KB
/
get_hash_hits.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function R = get_hash_hits(H, database)
%% get_hash_hits - Gets the hashes that appear both in the db and in the query
%
% R = get_hash_hits(H, database) finds the coincidences within the hashes
% stored in H (which has been returned by landmark2hash) and the ones in
% the database database. The matrix R that is returned contains a row for
% each found collision, and whose structure is the following:
%
% Rrow = [collided_id_song, time_difference, collided_hash]
%
%
% @author and @creator: Alex Gascón
%% FUNCTION
% We declare the variables that we're going to use
R = zeros(length(H)*3,3);
count = 0;
hashes = H(:,3);
% We go hash by hash looking for coincidences
for i = 1:length(hashes)
currentHash = hashes(i);
% If the current hash exists, we get the data associated to it
if(database.isKey(currentHash))
data = database(currentHash);
% We add a row to R for every song that has that hash
for j = 1:length(data)
count = count+1;
tQuery = H(i,2); % The time at which the hash appears on the query
tTarget = data(j);
while(tTarget > 2^17) % We get the time at which the hash appears in our db
tTarget = tTarget - 2^17;
end
R(count, 1) = data(j)/2^17; % id_song of the song that coincides
R(count, 2) = abs(tTarget - tQuery); % Time difference of the coincidence
R(count, 3) = currentHash; % Hash that has collided
end
end
end
% We get rid of the unused rows and sort the rest.
R = R(1:count,:);
R = sortrows(R, [1, 2]);