// 생성
HashMap<Integer, String> hm = new HashMap<>();
// 삽입
hm.put(3, "three");
hm.put(1, "one");
hm.put(4, "four");
hm.put(2, "two");
// 접근
System.out.println(hm.get(3));
// 삭제
hm.remove(4);
static class Node{
		int r;
		int c;
		Node(int r, int c){
				this.r = r;
				this.c = c;
		}
}

public static void main(String[] args) throws Exception{

		HashMap<Node, Integer> nhm = new HashMap<>();
		nhm.put(new Node(0, 0), 0);
		nhm.put(new Node(1, 1), 1);
		nhm.put(new Node(1, 10), 11);
		nhm.put(new Node(10, 11), 21);
		
		System.out.println(nhm.get(new Node(0, 0))); // null 출력됨
		// why?
		// 해시코드가 다름. => 오버라이딩 필요
}
static class Node{
		int r;
		int c;
		Node(int r, int c){
				this.r = r;
				this.c = c;
		}
		
		@Override
		// 모든 노드에 대한 해시코드는 1로 나오도록 변경
		public int hashCode(){
				return 1;
		}
}

public static void main(String[] args) throws Exception{

		HashMap<Node, Integer> nhm = new HashMap<>();
		nhm.put(new Node(0, 0), 0);
		nhm.put(new Node(1, 1), 1);
		nhm.put(new Node(1, 10), 11);
		nhm.put(new Node(10, 11), 21);
		nhm.put(new Node(0, 0), 2); // 갱신 안되고 새로 추가됨
		// why?
		// 해시코드가 동일한 배열 내에 있는 모든 값을 비교를 해줘야 하는데
		// 비교할 능력이 안됨.
		// 비교는 equals로 하기 때문.
		
		System.out.println(new Node(0, 0).equals(new Node(0, 0)); // 출력 false
		// => 지금의 equals는 아래 코드로 들어가기 때문
		// public boolean equals(Object obj){
		// 		return (this == obj);
		// }
}
static class Node{
		int r;
		int c;
		Node(int r, int c){
				this.r = r;
				this.c = c;
		}
		
		@Override
		// 모든 노드에 대한 해시코드는 1로 나오도록 변경
		public int hashCode(){
				return 1;
		}
		
		@Override
		// 
		public boolean equals(Object o){
				if (this == o)
						return true;
				if (this.getClass() !- o.getClass())
						return false;
				Node ob = (Node) o;
				return ob.y == y && ob.x == x;
		}
}

public static void main(String[] args) throws Exception{

		HashMap<Node, Integer> nhm = new HashMap<>();
		nhm.put(new Node(0, 0), 0);
		nhm.put(new Node(1, 1), 1);
		nhm.put(new Node(1, 10), 11);
		nhm.put(new Node(10, 11), 21);
		nhm.put(new Node(0, 0), 2); // 정상적으로 갱신되는 것을 볼 수 있음.
		
		System.out.println(new Node(0, 0).equals(new Node(0, 0)); // 출력 true
}