-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashMapExample.html
35 lines (35 loc) · 954 Bytes
/
HashMapExample.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HashMap Example</title>
</head>
<body>
Open the browser console to see the results.
<script src="../dist/HashMap.js"></script>
<script>
class Point{
constructor(x, y){
this.x = x;
this.y = y;
}
hashCode(){
const prime = 31;
let result = 1;
result = prime * result + this.x;
result = prime * result + this.y;
return result;
}
equals(obj){
return obj instanceof Point && obj.x === this.x && obj.y === this.y;
}
}
const hm = new HashMap();
console.log('hm.put(new Point(1,2), "abc") ->', hm.put(new Point(1,2), "abc"));
console.log('hm.containsKey(new Point(1,2)) ->', hm.containsKey(new Point(1,2)));
console.log('hm.get(new Point(1,2)) ->', hm.get(new Point(1,2)));
console.log('hm.put(new Point(1,2), "abcd") ->', hm.put(new Point(1,2), "abcd"));
console.log('hm.get(new Point(1,2)) ->', hm.get(new Point(1,2)));
</script>
</body>
</html>