Created
June 5, 2019 08:02
-
-
Save circlee/84d029044bea2a52b5204902bfb0f337 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
putVal(int XORHash, K key, V value, boolean onlyIfAbsent, boolean evict) { | |
1. Node<K,V> 테이블이 없다면 초기화 | |
2. 테이블의 [ 테이블 길이 -1 & XORHash ] 인덱스 Value가 null 이라면 | |
- 테이블의 [ 테이블 길이 -1 & XORHash ] 인덱스에 newNode(새로운 노드 생성) 넣음 | |
3. 2번이 아니라면 | |
테이블의 [ 테이블 길이 -1 & XORHash ] 인덱스의 Node 값 참조 | |
3-1. (Node의 hash 가 파라미터 XORHash 같고 Node의 key 가 파라미터 키와 같음) or (노드의 key 가 파라미터 key 와 equals true) | |
==> XORhash 값과 == 체크를 먼저하는 이유는 equals 보다 체크 비용이 적기때문 , equals true 라면 완전 같은 객체 | |
- 찾은 Node가 대상Node가 된다. | |
3-2. Node 가 TreeNode라면 | |
- TreeNode에 putTreeVal()로 값을 담음, TreeNode가 대상 Node가 됨. | |
3-3. Node 가 TreeNode가 아니라면 | |
- Next Node를 순차적으로 찾아가며 찾을수 없다면 | |
- NextNode에 newNode(새로운 노드 생성) 넣음 | |
- 순차적으로 찾아간 카운트가 (TREEIFY_THRESHOLD[8] -1) 보다 크다면 TreeNode로 변환 | |
- 대상 Node는 null | |
- Next Node를 순차적으로 찾아가며 찾았다면 | |
- 대상 Node가 된다. | |
3-4. 대상 Node가 null이 아니라면 | |
- 해당 Ndoe에 파라미터 Value를 넣는다. | |
- afterNodeAccess(e); | |
- return oldValue; | |
4. ++modCount; | |
5. if (++size > threshold) resize(); | |
6. afterNodeInsertion(evict); | |
7. return null; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment