Map 学习

interface Map :implements 有 HashMap,TreeMap;
Map的主要方法:
[align=left][size=x-small][color=red]put();
putAll();
get(key);
remove(key);
containsKey(key);
containsValue(value);
ketSet();
values()(Collection);
entrySet()(key=value…);
isEmpty();[/color][/size][/align]

[color=red][size=medium][align=center]HashMap:[/align][/size][/color
变量:

// table 里存放 该 Map中全部数据;
[color=darkred]transient Entry[] table;[/color]
/
[color=darkred]Entry<K,V>定义:[/color]static class Entry<K,V> implements Map.Entry<K,V> {
final K key;
V value;
Entry<K,V> next;
final int hash;

/**
* Creates new entry.
*/
Entry(int h, K k, V v, Entry<K,V> n) {
value = v;
next = n;
key = k;
hash = h;
}
/
* The number of times this HashMap has been structurally modified
* Structural modifications are those that change the number of mappings in
* the HashMap or otherwise modify its internal structure (e.g.,
* rehash). This field is used to make iterators on Collection-views of
* the HashMap fail-fast. (See ConcurrentModificationException).
*/
[color=darkred]transient int modCount;[/color]
[color=darkred]put 方法源代码:[/color]

public V put(K key, V value) {
if (key == null)
return putForNullKey(value);
int hash = hash(key.hashCode());
int i = indexFor(hash, table.length);
for (Entry<K,V> e = table[i]; e != null; e = e.next) {
Object k;
if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
V oldValue = e.value;
e.value = value;
e.recordAccess(this);
return oldValue;
}
}

modCount++;
addEntry(hash, key, value, i);
return null;
}

[color=darkred]void addEntry(int hash, K key, V value, int bucketIndex) {[/color] Entry<K,V> e = table[bucketIndex];
table[bucketIndex] = new Entry<K,V>(hash, key, value, e);
if (size++ >= threshold)
resize(2 * table.length);
}

---------------------------------------------------------------------
---------------------------------------------------------------------
由此可见:
[color=blue]HashMap特点:
1.数据存放在Entry 数组中(table)
2.按照自定义key的hash值来存储。
3.初始化一个 数组,数组的 类型是 Entry的。
4.同一hash 的不同key,存放在 table数组同一 下表处。。。组成一个小链表。
5.put时 如果存在同一key值,则只修改对应的value值。
6.只能存在一个null key。[/color]

[color=red][size=medium][align=center]LinkedHashMap[/align][/size][/color]

类定义:
---------------------------------------------------------------------
public class LinkedHashMap<K,V>
extends HashMap<K,V>
implements Map<K,V>
{ private transient Entry<K,V> header;.....
}
---------------------------------------------------------------------
private static class Entry<K,V> extends HashMap.Entry<K,V> {
// These fields comprise the doubly linked list used for iteration.
Entry<K,V> before, after;
---------------------------------------------------------------------
[color=blue]由此可见LinkedHashMap所有的成员变量如下:

transient Entry[] table;
private transient Entry<K,V> header;

Entry<K,V> 变量如下:
final K key;
V value;
Entry<K,V> next;
final int hash;
Entry<K,V> before, after;
所以:LinkedHashMap用 双向链表即实现了Map又实现了链表。。解决了HashMap无序的问题。 但是,其 空间利用率 及效率大大降低。。。[/color]
---------------------------------------------------------------------

[color=red][size=medium][align=center]TreeMap[/align][/size][/color]
主要变量:
private final Comparator<? super K> comparator;
private transient Entry<K,V> root = null;

static final class Entry<K,V> implements Map.Entry<K,V> {
K key;
V value;
Entry<K,V> left = null;
Entry<K,V> right = null;
Entry<K,V> parent;
boolean color = BLACK;
排序是按照 Comparator来判断,如果该变量为null,自然排序。否则,按照Comparator来排序...
This implementation provides guaranteed [size=x-small][color=red]log(n) [/color][/size]time cost for the containsKey, get, put and remove operations.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
mAP画图是深度学习中的一个指标,用于评估目标检测算法的性能。mAP代表平均精度均值(mean Average Precision),它是通过计算不同类别的精度-召回曲线下的面积来得到的。精度-召回曲线是在不同的召回率下计算的,召回率是指检测到的正样本与所有正样本的比例,而精度是指检测到的正样本中真正正确的比例。 在深度学习中,mAP画图通常用于比较不同模型或算法在目标检测任务上的性能。通过绘制精度-召回曲线,并计算曲线下的面积,可以得到一个综合评估指标,用于衡量模型的准确性和鲁棒性。 如果你想了解更多关于mAP画图和深度学习的内容,可以参考\[1\]中提供的链接,里面有详细的介绍和实践案例。 #### 引用[.reference_title] - *1* *3* [深度学习系列资料总结](https://blog.csdn.net/qq_36816848/article/details/125829496)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [深度学习画图工具](https://blog.csdn.net/qq_40677266/article/details/92793474)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值