afpro's recent timeline updates
afpro

afpro

V2EX member #172475, joined on 2016-05-10 18:35:20 +08:00
afpro's recent replies
Apr 1, 2020
Replied to a topic by Achilless Python tqdm 多行显示问题
我用 cmder 也遇到过这个 尤其是远程桌面进来一次之后 由于远程机器和 windows 本身分辨率不一致 就很容易这样
解决办法有点蠢 出现问题后把 cmder 的窗口拉宽 就好了
只靠大盘数据是不可能赚钱的 你算法再 NB 也没用 洗洗睡吧
如果楼主是做机器学习的 可以了解一下 Julia
Mar 18, 2020
Replied to a topic by waibunleung 程序员 PHP 转 go 好还是继续深造?
来头条吧 只要能面过 入职之后给时间熟悉 go 内部也有各种技术讲座 完善的新人技术培训
Mar 13, 2020
Replied to a topic by pOH8 程序员 你们公司都发口罩了吗?
头条还在远程办公 囧
@MatthewHan 你疑惑的是 capacity 这个方法??

final int capacity() {
return (table != null) ? table.length :
(threshold > 0) ? threshold :
DEFAULT_INITIAL_CAPACITY;
}

这不是显然 table 为 null 的时候返回了 threshold 或者 DEFAULT_INITIAL_CAPACITY

有发帖和跟帖的时间瞄一眼 code 可好。。
@MatthewHan 你是没 put 啊 所以只初始化了两个参数 没有 new table 你的疑惑在哪呢??
emmm 我尝试用 ``` 放代码 但是没成功 这个怎么样才能正确的贴代码?
```
public HashMap(int initialCapacity, float loadFactor) {
if (initialCapacity < 0)
throw new IllegalArgumentException("Illegal initial capacity: " +
initialCapacity);
if (initialCapacity > MAXIMUM_CAPACITY)
initialCapacity = MAXIMUM_CAPACITY;
if (loadFactor <= 0 || Float.isNaN(loadFactor))
throw new IllegalArgumentException("Illegal load factor: " +
loadFactor);
this.loadFactor = loadFactor;
this.threshold = tableSizeFor(initialCapacity);
}
```

显然只初始化了一个 float 和一个 int

```
public V put(K key, V value) {
return putVal(hash(key), key, value, false, true);
}

final V putVal(int hash, K key, V value, boolean onlyIfAbsent,
boolean evict) {
Node<K,V>[] tab; Node<K,V> p; int n, i;
if ((tab = table) == null || (n = tab.length) == 0)
n = (tab = resize()).length;
...
}
```

put 的时候如果 (tab = table) == null 会去 resize

```
final Node<K,V>[] resize() {
...
Node<K,V>[] newTab = (Node<K,V>[])new Node[newCap];
...

```

在 resize 里面 new 了新的 table
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5810 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 06:25 · PVG 14:25 · LAX 23:25 · JFK 02:25
♥ Do have faith in what you're doing.