src/share/classes/java/util/TreeMap.java

Print this page

        

*** 34,54 **** * <p>This implementation provides guaranteed log(n) time cost for the * <tt>containsKey</tt>, <tt>get</tt>, <tt>put</tt> and <tt>remove</tt> * operations. Algorithms are adaptations of those in Cormen, Leiserson, and * Rivest's <I>Introduction to Algorithms</I>. * ! * <p>Note that the ordering maintained by a sorted map (whether or not an ! * explicit comparator is provided) must be <i>consistent with equals</i> if ! * this sorted map is to correctly implement the <tt>Map</tt> interface. (See ! * <tt>Comparable</tt> or <tt>Comparator</tt> for a precise definition of ! * <i>consistent with equals</i>.) This is so because the <tt>Map</tt> ! * interface is defined in terms of the equals operation, but a map performs ! * all key comparisons using its <tt>compareTo</tt> (or <tt>compare</tt>) ! * method, so two keys that are deemed equal by this method are, from the ! * standpoint of the sorted map, equal. The behavior of a sorted map ! * <i>is</i> well-defined even if its ordering is inconsistent with equals; it ! * just fails to obey the general contract of the <tt>Map</tt> interface. * * <p><strong>Note that this implementation is not synchronized.</strong> * If multiple threads access a map concurrently, and at least one of the * threads modifies the map structurally, it <i>must</i> be synchronized * externally. (A structural modification is any operation that adds or --- 34,55 ---- * <p>This implementation provides guaranteed log(n) time cost for the * <tt>containsKey</tt>, <tt>get</tt>, <tt>put</tt> and <tt>remove</tt> * operations. Algorithms are adaptations of those in Cormen, Leiserson, and * Rivest's <I>Introduction to Algorithms</I>. * ! * <p>Note that the ordering maintained by a tree map, like any sorted map, and ! * whether or not an explicit comparator is provided, must be <em>consistent ! * with {@code equals}</em> if this sorted map is to correctly implement the ! * {@code Map} interface. (See {@code Comparable} or {@code Comparator} for a ! * precise definition of <i>consistent with equals</i>.) This is so because ! * the <tt>Map</tt> interface is defined in terms of the {@code equals} ! * operation, but a sorted map performs all key comparisons using its {@code ! * compareTo} (or {@code compare}) method, so two keys that are deemed equal by ! * this method are, from the standpoint of the sorted map, equal. The behavior ! * of a sorted map <em>is</em> well-defined even if its ordering is ! * inconsistent with {@code equals}; it just fails to obey the general contract ! * of the {@code Map} interface. * * <p><strong>Note that this implementation is not synchronized.</strong> * If multiple threads access a map concurrently, and at least one of the * threads modifies the map structurally, it <i>must</i> be synchronized * externally. (A structural modification is any operation that adds or