TreeMap源码分析

参考链接:
https://www.cnblogs.com/jing99/p/11736005.html

复杂度

TreeMap的基本操作 containsKey、get、put 和 remove 的时间复杂度是 log(n)。

public class TreeMap<K,V>
    extends AbstractMap<K,V>
    implements NavigableMap<K,V>, Cloneable, java.io.Serializable

继承的类和接口都是老熟人了,就是这个NavigableMap有点陌生,我们就来康康

public interface NavigableMap<K,V> extends SortedMap<K,V>{
    /**
     * Returns a key-value mapping associated with the greatest key
     * strictly less than the given key, or {@code null} if there is
     * no such key.
     * 返回严格小于给定的键的最大键关联的键值映射,或者{@code null}(如果没
     * 有这样的key
     * @param key the key 
     * @参数 key 传入的键
     * @return an entry with the greatest key less than {@code key},
     *         or {@code null} if there is no such key
     * 返回一个小于{@code key}的有最大键的entry,或{@code null},如果没有这样的key
     * @throws ClassCastException if the specified key cannot be compared
     *         with the keys currently in the map
     * 指定的key无法被比较将抛出异常
     * @throws NullPointerException if the specified key is null
     *         and this map does not permit null keys
     * 指定的key为null,同时该map不允许null key将抛出异常
     */

底层数据结构:红黑树(是一种平衡二叉树,也是一种二叉搜索树)

平衡二叉树:它是一棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二叉树

特点:
查找、插入、删除复杂度均为log(n)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值