-
Notifications
You must be signed in to change notification settings - Fork 65
/
CustomHashTable.java
61 lines (53 loc) · 1.09 KB
/
CustomHashTable.java
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
package com.deepak.data.structures.Hashing;
import java.util.Map;
import java.util.Objects;
public class CustomHashTable<K, V> {
/**
* This is a node representation of Linked List
* @author Deepak
*
* @param <K>
* @param <V>
*/
static class Entry<K, V> {
final int hash;
final K key;
V value;
Entry<K, V> next;
/**
* Constructor for creating a entry
* @param hash
* @param key
* @param value
* @param next
*/
public Entry(int hash, K key, V value, Entry<K, V> next) {
this.hash = hash;
this.key = key;
this.value = value;
this.next = next;
}
/**
* HashCode implementation for entry
*/
public final int hashCode() {
return Objects.hashCode(key) ^ Objects.hashCode(value);
}
/**
* Method to check if two objects are equal
*/
public final boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof Map.Entry) {
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
if (Objects.equals(key, e.getKey()) &&
Objects.equals(value, e.getValue())) {
return true;
}
}
return false;
}
}
}