mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-23 01:33:45 +00:00
auto commit
This commit is contained in:
@@ -1,108 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util;
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
*
|
||||
* <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 <em>consistent with equals</em>.) This is so because
|
||||
* the {@code Map} 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 <em>must</em> be synchronized
|
||||
* externally. (A structural modification is any operation that adds or
|
||||
* deletes one or more mappings; merely changing the value associated
|
||||
* with an existing key is not a structural modification.) This is
|
||||
* typically accomplished by synchronizing on some object that naturally
|
||||
* encapsulates the map.
|
||||
* If no such object exists, the map should be "wrapped" using the
|
||||
* {@link Collections#synchronizedSortedMap Collections.synchronizedSortedMap}
|
||||
* method. This is best done at creation time, to prevent accidental
|
||||
* unsynchronized access to the map: <pre>
|
||||
* SortedMap m = Collections.synchronizedSortedMap(new TreeMap(...));</pre>
|
||||
*
|
||||
* <p>The iterators returned by the {@code iterator} method of the collections
|
||||
* returned by all of this class's "collection view methods" are
|
||||
* <em>fail-fast</em>: if the map is structurally modified at any time after
|
||||
* the iterator is created, in any way except through the iterator's own
|
||||
* {@code remove} method, the iterator will throw a {@link
|
||||
* ConcurrentModificationException}. Thus, in the face of concurrent
|
||||
* modification, the iterator fails quickly and cleanly, rather than risking
|
||||
* arbitrary, non-deterministic behavior at an undetermined time in the future.
|
||||
*
|
||||
* <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
|
||||
* as it is, generally speaking, impossible to make any hard guarantees in the
|
||||
* presence of unsynchronized concurrent modification. Fail-fast iterators
|
||||
* throw {@code ConcurrentModificationException} on a best-effort basis.
|
||||
* Therefore, it would be wrong to write a program that depended on this
|
||||
* exception for its correctness: <em>the fail-fast behavior of iterators
|
||||
* should be used only to detect bugs.</em>
|
||||
*
|
||||
* <p>All {@code Map.Entry} pairs returned by methods in this class
|
||||
* and its views represent snapshots of mappings at the time they were
|
||||
* produced. They do <strong>not</strong> support the {@code Entry.setValue}
|
||||
* method. (Note however that it is possible to change mappings in the
|
||||
* associated map using {@code put}.)
|
||||
*
|
||||
* <p>This class is a member of the
|
||||
* <a href="{@docRoot}/../technotes/guides/collections/index.html">
|
||||
* Java Collections Framework</a>.
|
||||
*
|
||||
* @param <K> the type of keys maintained by this map
|
||||
* @param <V> the type of mapped values
|
||||
*
|
||||
* @author Josh Bloch and Doug Lea
|
||||
* @see Map
|
||||
* @see HashMap
|
||||
* @see Hashtable
|
||||
* @see Comparable
|
||||
* @see Comparator
|
||||
* @see Collection
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public class TreeMap<K,V>
|
||||
extends AbstractMap<K,V>
|
||||
implements NavigableMap<K,V>, Cloneable, java.io.Serializable
|
||||
|
||||
Reference in New Issue
Block a user