crossoverJie / crossoverJie/JCSprout
对LRUAbstractMap 中put方法的一点小疑问?
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7k
- PR merge metrics
- No merged PRs in 30d
Description
```
public Object put(Object key, Object value) {
int hash = hash(key);
int index = hash % arraySize ;
Node currentNode = (Node) arrays[index] ;
if (currentNode == null){
arrays[index] = new Node(null,null, key, value);
//写入队列
QUEUE.offer((Node) arrays[index]) ;
sizeUp();
}else {
Node cNode = currentNode ;
Node nNode = cNode ;
//存在就覆盖
if (nNode.key == key){
cNode.val = value ;
}
while (nNode.next != null){
//key 存在 就覆盖 简单判断
if (nNode.key == key){
nNode.val = value ;
break ;
}else {
//不存在就新增链表
sizeUp();
Node node = new Node(nNode,null,key,value) ;
//写入队列
QUEUE.offer(currentNode) ;
cNode.next = node ;
}
nNode = nNode.next ;
}
}
return null ;
}
```
>其中while (nNode.next != null)这个条件在key第一次冲突的条件时是不是不满足哇?求解惑,^_^
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the LRUAbstractMap.put method shown in the issue and trace the first insertion into an occupied bucket. Follow the while condition and key comparisons for both a single-node bucket and a chained collision, then compare the observed behavior with the intended map semantics. Done means documenting whether the condition or surrounding logic mishandles the collision case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 18/100