TreeMap是基于红黑树实现的,无容量限制;
TreeMap是非线程安全的;
public V put(K key, V value) {
Entry<K,V> t = root;
if (t == null) {
// TBD:
// 5045147: (coll) Adding null to an empty TreeSet should
// throw NullPointerException
//
// compare(key, key); // type check
root = new Entry<K,V>(key, value, null);
size = 1;
modCount++;
return null;
}
int cmp;
Entry<K,V> parent;
// split comparator and comparable paths
Comparator<? super K> cpr = comparator;
if (cpr != null) {
do {
parent = t;
cmp = cpr.compare(key, t.key);
if (cmp < 0)
t = t.left;
else if (cmp > 0)
t = t.right;
else
return t.setValue(value);
} while (t != null);
}
else {
if (key == null)
throw new NullPointerException();
Comparable<? super K> k = (Comparable<? super K>) key;
do {
parent = t;
cmp = k.compareTo(t.key);
if (cmp < 0)
t = t.left;
else if (cmp > 0)
t = t.right;
else
return t.setValue(value);
} while (t != null);
}
Entry<K,V> e = new Entry<K,V>(key, value, parent);
if (cmp < 0)
parent.left = e;
else
parent.right = e;
fixAfterInsertion(e);
size++;
modCount++;
return null;
}
分享到:
相关推荐
vue 2.x echarts treemap带示例数据及效果图,及在对话框里显示的处理方法
JAVA中用TREEMAP做的,可以求学生的总分,总分的平均值,最大值最小值
java中HashMap,LinkedHashMap,TreeMap,HashTable的区别
van Wijk 发布的 Squarified Treemap 算法。 用途 假设我们有一个宽度为 6、高度为 4 的矩形,并且进一步假设这个矩形必须细分为 7 个矩形,面积分别为 6、6、4、3、2、2 和 1。标准树形图算法使用一个简单的方法...
编写一个应用程序,使用TreeMap,V>类,分别按照价格和容量排序并输出10个硬盘的详细信息 9_5.编写一个应用程序,要求将LinkedList创建的对象写入到文件,然后读出一个LinkedList对象,并遍历LinkedList节点中的数据
TreeMap按VALUE排序
本资源提供了List对对象中的属性和TreeMap, String>对键值排序,并针对100w条数据排序,对比List和TreeMap, String>排序的效率。个人认为排序效率对比可以相信,但也可能存在不科学之处,还请高手给与指点,多多包涵...
1. TreeMap 2. HashMap 3. ConcurrentSkipListMap 本测试查找方法使用Map的get方法,循环、离散获取。对于ConcurrentSkipListMap,获得顺序片段,可用subMap()方法,提取50w的子序列只需要1ms,具有巨大优势。 ...
treeMap实现分组数据树形结构,在通过Redis和MySQL数据库ID生成序列ID
在eclipse上用java实现统计一句话或一段话中单词出现的个数,并按照字母表顺序输出,并利用treemap实现
Map,HashMap,TreeMap的使用 很详细额,值得看看
Java TreeMap源码解析 Java TreeMap源码解析 Java TreeMap源码解析
Python TreeMap可视化方案数据源(因为不能粘贴链接额,具体实现实现代码,请看我博客专栏《机器学习》:))
treemap treeset hashset hashmap 简要介绍
Python_TreeMap_可视化方案数据源(因为不能直接粘贴链接,所以实现代码,请移步看我博客专栏《机器学习》)
JDK源码剖析之红黑树TreeMap,偶然看见,传上来分享一下
TreeMap自己的理解
Treemap-4.1.2.zip tree map开发代码,可用于创建tree map
TreeMap源码是基于数据结构中的红黑树进行设计并开发的。
TreeMap例子GDP