-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcuckoo_hashing_strings_example.html
182 lines (170 loc) · 7.06 KB
/
cuckoo_hashing_strings_example.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Cuckoo Hashing</title>
<style>
svg #line1 {
fill: none;
stroke: black;
stroke-width: 2;
transition: all 4s ease-in-out;
}
svg #line2 {
fill: none;
stroke: black;
stroke-width: 2;
transition: all 4s ease-in-out;
}
.lines{
-ms-flex: 70%; /* IE10 */
flex: 70%;
background-color: transparent;
padding: 20px;
}
</style>
</head>
<body>
<div id="inp" style="margin-left: 950px; position: fixed; margin-top: -30px">
<p><b>Исходные данные:</b><br>
<input type="text" id="word" size="20">
</p>
<p><b>Хэш-функция 1:</b><br>
<input type="text" size="20" value="key%8" id="func1">
</p>
<p><b>Хэш-функция 2:</b><br>
<input type="text" size="20" value="(key/8)%8" id="func2">
</p>
<input type="submit" onclick="getvalue()" size="20" value="Получить">
</div>
<div id="blocks1">
<div id="block1" style="display: block; width: 100px; height: 40px; border: 1px solid black; margin-top: 100px; margin-left: 300px"></div>
<div id="block2" style="display: block; width: 100px; height: 40px; border: 1px solid black; margin-left: 300px"></div>
<div id="block3" style="display: block; width: 100px; height: 40px; border: 1px solid black; margin-left: 300px"></div>
<div id="block4" style="display: block; width: 100px; height: 40px; border: 1px solid black; margin-left: 300px"></div>
</div>
<div id="blocks2">
<div id="block_1" style="display: block; width: 100px; height: 40px; border: 1px solid black; margin-top: -170px; margin-left: 600px"></div>
<div id="block_2" style="display: block; width: 100px; height: 40px; border: 1px solid black; margin-left: 600px"></div>
<div id="block_3" style="display: block; width: 100px; height: 40px; border: 1px solid black; margin-left: 600px"></div>
<div id="block_4" style="display: block; width: 100px; height: 40px; border: 1px solid black; margin-left: 600px"></div>
</div>
<div id="info" style="margin-left: 950px; margin-top: 30px">
<p>Хэш: </p>
<div id="text1"></div>
<p>Первый ключ: </p>
<div id="text2"></div>
<p>Второй ключ: </p>
<div id="text3"></div>
<div>
<div id="words">
<div id="word1" style="height: 20px; width: 60px; display: none; transition: all 2s ease-in-out;">
<p id="try" style="color: black; margin-left: -740px; margin-top: -390px; font-size: 25px">hash</p>
</div>
<div id="word11" style="height: 20px; width: 60px; display: none; transition: all 2s ease-in-out;">
<p id="try" style="color: black; margin-left: -740px; margin-top: -290px; font-size: 25px">hash</p>
</div>
<div id="word2" style="height: 20px; width: 60px; display: none; transition: all 2s ease-in-out;">
<p style="color: black; margin-left: -740px; margin-top: -110px; font-size: 25px; color: black">polynom</p>
</div>
<div id="word3" style="height: 20px; width: 60px; display: none; color: transparent; transition: all 2s ease-in-out;">
<p id="try" style="color: black; margin-left: -780px; margin-top: -30px; font-size: 25px">algorithm</p>
</div>
<div id="word33" style="height: 20px; width: 60px; display: none; color: transparent; transition: all 2s ease-in-out;">
<p id="try" style="color: black; margin-left: -780px; margin-top: 105px; font-size: 25px">algorithm</p>
</div>
<div id="word4" style="height: 20px; width: 60px; display: none; transition: all 2s ease-in-out;">
<p style="color: black; margin-left: -780px; margin-top: -170px; font-size: 25px; color: black">efficiency</p>
</div>
<div id="word44" style="height: 20px; width: 60px; display: none; transition: all 2s ease-in-out;">
<p style="color: black; margin-left: -780px; margin-top: 110px; font-size: 25px; color: black">efficiency</p>
</div>
<div id="word333" style="height: 20px; width: 60px; display: none; transition: all 2s ease-in-out;">
<p style="color: black; margin-left: -650px; margin-top: -20px; font-size: 25px; color: black">algorithm</p>
</div>
</div>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
<script>
var count = 0;
function getvalue(){
count++;
var val = document.getElementById('word').value;
var p = 31;
var power = 1;
var hash = 0;
var val2 = val.split("");
for(var i = 0; i < val2.length; i++){
hash+=(val.charCodeAt(i) - 97 + 1)*power;
power = p*power;
}
var hash1 = document.getElementById('func1').value;
var hash2 = document.getElementById('func2').value;
var number = hash1.split("");
var res1 = hash%number[4];
var res2 = hash/number[4];
var res3 = Math.round(res2%number[4]);
if (res3 == number[4]){
res3 = res3-1;
}
alert("Хэш: "+ hash + "\n" + "Первый ключ: " + res1 + "\n" + "Второй ключ: " + res3);
document.getElementById('text1').innerHTML = hash;
document.getElementById('text2').innerHTML = res1;
document.getElementById('text3').innerHTML = res3;
if(count == 1){
$("#word1").fadeIn('slow');
document.getElementById("word1").style.display = "block";
setTimeout(function () {
$('#word1').css({ transform: 'translate(40px,95px)' });
}, 1500);
setTimeout(function () {
$("#word1").fadeOut('slow');
$("#word11").fadeIn('slow');
$('#word11').css({ transform: 'translate(120px,0px)' });
}, 2500);
}
else if(count == 2){
setTimeout(function () {
$("#word2").fadeIn('slow');
document.getElementById("word2").style.display = "block";
}, 1500);
setTimeout(function () {
$('#word2').css({ transform: 'translate(100px,0px)' });
}, 2500);
}
else if(count == 3){
setTimeout(function () {
$("#word3").fadeIn('slow');
document.getElementById("word3").style.display = "block";
}, 1500);
setTimeout(function () {
$('#word3').css({ transform: 'translate(30px,140px)' });
}, 2500);
setTimeout(function () {
$("#word3").fadeOut('slow');
$("#word33").fadeIn('slow');
$('#word33').css({ transform: 'translate(135px,0px)' });
}, 3500);
}
else if(count == 4){
setTimeout(function () {
$("#word4").fadeIn('slow');
document.getElementById("word4").style.display = "block";
}, 1500);
setTimeout(function () {
$('#word4').css({ transform: 'translate(30px,160px)' });
}, 2500);
setTimeout(function () {
$("#word4").fadeOut('slow');
$("#word33").fadeOut('slow');
$("#word44").fadeIn('slow');
$("#word333").fadeIn('slow');
$('#word44').css({ transform: 'translate(130px,0px)' });
$('#word333').css({ transform: 'translate(300px,-50px)' });
}, 3500);
}
}
</script>
</body>
</html>