```java
```java
public class HashBuck {
static class Node {
public int key;
public int val;
public Node next;
public Node(int key, int val) {
this.key = key;
this.val = val;
}
}
public Node[] array;
public int usedSize;
public HashBuck() {
this.array = new Node[8];
}
public void push(int key,int val) {
Node node = new Node(key,val);
int index = key % array.length;
Node cur = array[index];
while (cur != null) {
if(cur.key == key) {
cur.val = val;
return;
}
cur = cur.next;
}
node.next = array[index];
array[index] = node;
this.usedSize++;
if(loadFactor() >= 0.75) {
resize();
}
}
public double loadFactor() {
return this.usedSize*1.0 / this.array.length;
}
public void resize() {
Node[] newArray = new Node[2*array.length];
for (int i = 0; i < array.length; i++) {
Node cur = array[i];
while (cur != null) {
int index = cur.key % newArray.length;
Node curNext = cur.next;
cur.next = newArray[index];
newArray[index] = cur;
cur = curNext;
}
}
array = newArray;
}
public int get(int key) {
int index = key % array.length;
Node cur = array[index];
while (cur != null) {
if(cur.key == key) {
return cur.val;
}
cur = cur.next;
}
return -1;
}
public static void main(String[] args) {
HashBuck hashBuck = new HashBuck();
hashBuck.push(1,1);
hashBuck.push(2,2);
hashBuck.push(10,10);
hashBuck.push(4,4);
hashBuck.push(5,5);
hashBuck.push(6,6);
hashBuck.push(7,7);
System.out.println(hashBuck.get(6));
HashMap<String,Integer> map = new HashMap<>();
}
}
class Person {
public Integer id;
public Person(Integer id) {
this.id = id;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Person person = (Person) o;
return Objects.equals(id, person.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Person{" +
"id=" + id +
'}';
}
}
public class HashBuck2<K,V> {
static class Node<K,V> {
public K key;
public V val;
public Node<K,V> next;
public Node(K key, V val) {
this.key = key;
this.val = val;
}
}
public Node<K,V>[] array;
public int usedSize;
public HashBuck2() {
this.array = new Node[8];
}
public void push(K key,V val) {
Node<K,V> node = new Node<K,V>(key,val);
int hash = key.hashCode();
int index = hash % array.length;
Node<K,V> cur = array[index];
while (cur != null) {
if(cur.key.equals(key)) {
cur.val = val;
return;
}
cur = cur.next;
}
node.next = array[index];
array[index] = node;
this.usedSize++;
}
public V get(K key) {
int hash = key.hashCode();
int index = hash % array.length;
Node<K,V> cur = array[index];
while (cur != null) {
if(cur.key == key) {
return cur.val;
}
cur = cur.next;
}
return null;
}
public static void main(String[] args) {
Person person1 = new Person(1);
Person person2 = new Person(2);
HashBuck2<Person,String> hashBuck2 = new HashBuck2<>();
hashBuck2.push(person1,"gaobo");
hashBuck2.push(person2,"wangfei");
System.out.println(hashBuck2.get(person1));
}
}