dasinigetudou

dasinigetudou

V2EX member #190932, joined on 2016-09-08 16:25:40 +08:00
Per dasinigetudou's settings, the topics list is hidden
Deals info, including closed deals, is not hidden
dasinigetudou's recent replies
最近在看《情商》和《看人的艺术》
Dec 28, 2020
Replied to a topic by jwautumn 职场话题 圣诞节,我裸辞了
加油
```
final TreeNode<K,V> putTreeVal(HashMap<K,V> map, Node<K,V>[] tab,
int h, K k, V v) {
Class<?> kc = null;
boolean searched = false;
TreeNode<K,V> root = (parent != null) ? root() : this;
for (TreeNode<K,V> p = root;;) {
//树的根节点开始遍历
int dir, ph; K pk;
//比较根节点的 hash 值,dir 猜测是决定节点插入时应该插到左子节点还是右子节点
if ((ph = p.hash) > h)
dir = -1;
else if (ph < h)
dir = 1;
else if ((pk = p.key) == k || (k != null && k.equals(pk)))
//如果根节点的 key 和要插入节点的 key 相同,直接返回根节点
return p;
else if ((kc == null &&
(kc = comparableClassFor(k)) == null) ||
(dir = compareComparables(kc, k, pk)) == 0) {
//根节点的 key 和要插入的 key 不同,开始比较根节点的左右子节点
if (!searched) {
TreeNode<K,V> q, ch;
searched = true;
if (((ch = p.left) != null &&
(q = ch.find(h, k, kc)) != null) ||
((ch = p.right) != null &&
(q = ch.find(h, k, kc)) != null))
//找到相同的 key,将节点返回
return q;
}
//这里记录下 dir,可能是决定为了如果从子节点也找不到接下来创建新的节点插入到左边还是右边
dir = tieBreakOrder(k, pk);
}

//到这里就是从红黑树找不到符合要求的节点了,创建新的节点,插入到红黑树
TreeNode<K,V> xp = p;
if ((p = (dir <= 0) ? p.left : p.right) == null) {
Node<K,V> xpn = xp.next;
TreeNode<K,V> x = map.newTreeNode(h, k, v, xpn);
if (dir <= 0)
xp.left = x;
else
xp.right = x;
xp.next = x;
x.parent = x.prev = xp;
if (xpn != null)
((TreeNode<K,V>)xpn).prev = x;
moveRootToFront(tab, balanceInsertion(root, x));
return null;
}
}
}
```
```
final TreeNode<K,V> putTreeVal(HashMap<K,V> map, Node<K,V>[] tab,

​ int h, K k, V v) {

​ Class<?> kc = null;

​ boolean searched = false;

​ TreeNode<K,V> root = (parent != null) ? root() : this;

​ for (TreeNode<K,V> p = root;;) {

​ //树的根节点开始遍历

​ int dir, ph; K pk;

​ //比较根节点的 hash 值,dir 猜测是决定节点插入时应该插到左子节点还是右子节点

​ if ((ph = p.hash) > h)

​ dir = -1;

​ else if (ph < h)

​ dir = 1;

​ else if ((pk = p.key) == k || (k != null && k.equals(pk)))

​ //如果根节点的 key 和要插入节点的 key 相同,直接返回根节点

​ return p;

​ else if ((kc == null &&

​ (kc = comparableClassFor(k)) == null) ||

​ (dir = compareComparables(kc, k, pk)) == 0) {

​ //根节点的 key 和要插入的 key 不同,开始比较根节点的左右子节点

​ if (!searched) {

​ TreeNode<K,V> q, ch;

​ searched = true;

​ if (((ch = p.left) != null &&

​ (q = ch.find(h, k, kc)) != null) ||

​ ((ch = p.right) != null &&

​ (q = ch.find(h, k, kc)) != null))

​ //找到相同的 key,将节点返回

​ return q;

​ }

​ //这里记录下 dir,可能是决定为了如果从子节点也找不到接下来创建新的节点插入到左边还是右边

​ dir = tieBreakOrder(k, pk);

​ }



​ //到这里就是从红黑树找不到符合要求的节点了,创建新的节点,插入到红黑树

​ TreeNode<K,V> xp = p;

​ if ((p = (dir <= 0) ? p.left : p.right) == null) {

​ Node<K,V> xpn = xp.next;

​ TreeNode<K,V> x = map.newTreeNode(h, k, v, xpn);

​ if (dir <= 0)

​ xp.left = x;

​ else

​ xp.right = x;

​ xp.next = x;

​ x.parent = x.prev = xp;

​ if (xpn != null)

​ ((TreeNode<K,V>)xpn).prev = x;

​ moveRootToFront(tab, balanceInsertion(root, x));

​ return null;

​ }

​ }

​ }
```
不知道分析的对不对~希望大佬一起交流
@exmorning 算法要求高吗
上海办公地点在哪里
Sep 24, 2020
Replied to a topic by corningsun 上海 迫于穷,代拍沪牌,个人非营业额度
借楼摆摊代拍,有需要的加微信 NzA0NDEwNDg2 。
Jul 2, 2019
Replied to a topic by dasinigetudou Android AndroidAnnotation 使用方面的疑惑
@saucew 但是跳转还是要跳带后缀的 fragment 啊
Jul 2, 2019
Replied to a topic by dasinigetudou Android AndroidAnnotation 使用方面的疑惑
@Cabana AndroidAnnotations 框架
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5560 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 16ms · UTC 07:40 · PVG 15:40 · LAX 00:40 · JFK 03:40
♥ Do have faith in what you're doing.