zoukankan      html  css  js  c++  java
  • java学习_5_24

    TreeMap底层是用红黑树实现的,源码如下:

    /**
     * A Red-Black tree based {@link NavigableMap} implementation.
     * The map is sorted according to the {@linkplain Comparable natural
     * ordering} of its keys, or by a {@link Comparator} provided at map
     * creation time, depending on which constructor is used.
     *
     * <p>This implementation provides guaranteed log(n) time cost for the
     * {@code containsKey}, {@code get}, {@code put} and {@code remove}
     * operations.  Algorithms are adaptations of those in Cormen, Leiserson, and
     * Rivest's <em>Introduction to Algorithms</em>.
    */
    
    static final class Entry<K,V> implements Map.Entry<K,V> {
            K key;
            V value;
            Entry<K,V> left;
            Entry<K,V> right;
            Entry<K,V> parent;
            boolean color = BLACK;

    Set为一接口(没有顺序 不可重复),其实现类HashSet底层实现实为HashTable  JDK源码如下:

    public class HashSet<E>
        extends AbstractSet<E>
        implements Set<E>, Cloneable, java.io.Serializable
    {
        static final long serialVersionUID = -5024744406713321676L;
    
        private transient HashMap<E,Object> map;
    
        // Dummy value to associate with an Object in the backing Map
        private static final Object PRESENT = new Object();
    
        /**
         * Constructs a new, empty set; the backing {@code HashMap} instance has
         * default initial capacity (16) and load factor (0.75).
         */
        public HashSet() {
            map = new HashMap<>();
        }
    
    .............
      public boolean add(E e) {
            return map.put(e, PRESENT)==null;
        }
    
    ........
    }
  • 相关阅读:
    映射和分析
    文档操作
    向 Nginx 主进程发送 USR1 信号
    ES集群7.3.0设置快照,存储库进行索引备份和恢复等
    ES7.3.0配置邮件告警
    Elasticsearch 史上最全最常用工具清单
    Grok在线调试网址
    Linux 小知识翻译
    Linux 小知识翻译
    Linux 小知识翻译
  • 原文地址:https://www.cnblogs.com/ustc-anmin/p/10920686.html
Copyright © 2011-2022 走看看