-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHashTable.html
43 lines (40 loc) · 952 Bytes
/
HashTable.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
<!DOCTYPE html>
<html lang="en">
<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>Document</title>
</head>
<body>
</body>
<script>
function HashTable(){
this.table = new Array(137);
this.simpleHash = simpleHash;
this.showDistro = showDistro;
this.put = put
}
function put(data){
var pos = this.simpleHash(data);
this.table[pos] = data;
}
function simpleHash(data){
var total = 0;
for(var i =0; i < data.length; i++){
console.log(data.charCodeAt(i));
// 必需。表示字符串中某个位置的数字,即字符在字符串中的下标。
total += data.charCodeAt(i);
}
return total % this.table.length;
}
function showDistro(){
var n = 0;
for(var i = 0; i < this.table.length; i++){
if(this.table[i] != undefined){
console.log(this.table[i], '/n')
}
}
}
</script>
</html>