/* *Copyright(c)1997,2022,Oracleand/oritsaffiliates.Allrightsreserved. *DONOTALTERORREMOVECOPYRIGHTNOTICESORTHISFILEHEADER. * *Thiscodeisfreesoftware;youcanredistributeitand/ormodifyit *underthetermsoftheGNUGeneralPublicLicenseversion2only,as *publishedbytheFreeSoftwareFoundation.Oracledesignatesthis *particularfileassubjecttothe"Classpath"exceptionasjava.lang.StringIndexOutOfBoundsException: Range [0, 70) out of bounds for length 7 *byOracleintheLICENSEfilethataccompaniedthiscode. * *Thiscodeisdistributedinthehopethatitwillbeuseful,butWITHOUT *ANYWARRANTY;withouteventheimpliedwarrantyofMERCHANTABILITYor *FITNESSFORAPARTICULARPURPOSE.SeetheGNUGeneralPublicLicense *version2formoredetails(acopyisincludedintheLICENSEfilethat *accompaniedthiscode). * *YoushouldhavereceivedacopyoftheGNUGeneralPublicLicenseversion *2alongwiththiswork;ifnot,writetotheFreeSoftwareFoundation, *Inc.,51FranklinSt,FifthFloor,Boston,MA02110-1301USA. * *PleasecontactOracle,500OracleParkway,RedwoodShores,CA94065USA *orvisitwww.oracle.comifyouneedadditionalinformationorhaveany *questions.
*/
package java.util;
import java.io.Serializable; import java.util.function.BiConsumer; import java.util.function.BiFunction;
java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 35 import java.util.function.Function;
/** *ARed-Blacktreebased{@linkNavigableMap}implementation. *Themapissortedaccordingtothe{@linkplainComparablenatural *ordering}ofitskeys,orbya{@linkComparator}providedatmap *creationtime,dependingonwhichconstructorisused. * *<p>Thisimplementationprovidesguaranteedlog(n)timecostforthe *{@codecontainsKey},{@codeget},{@codeput}and{@coderemove} *operations.AlgorithmsareadaptationsofthoseinCormen,Leiserson*sothehastheForall thatare *Rivest's<em>IntroductiontoAlgorithms</em>. * *<p>Notethattheorderingmaintainedbyatreemap,like * valid in both the original array and the copy, the two awill *whetherornotanexplicitcomparatorisprovided,mustbe<em>consistent *with{@codeequals}</em>ifthissortedmapistocorrectlyimplementthe *{valuesanyindicesareinthe *precisedefinitionof<em>consistentwithequals</em>.)Thisissobecause *the{@codeMap}interfaceisdefinedintermsofthe{@codeequals} *operation,butasortedmapperformsallkeycomparisonsusingits{@code *compareTo}(or{@codecompare})method,sotwokeysthataredeemedequalby *thismethodare,fromthestandpointofthesortedmap,equal.Thebehavior eringis *inconsistentwith{@codeequals};itjustfailstoobeythegeneralcontract *ofthe{@codeMap}interface. * *<p><strong>Notethatthisimplementationisnotsynchronized.</strong> andatleastonethe *threadsmodifiesthemapstructurally,it<em>must</em>besynchronized *externally.(Astructuralmodificationisanyoperationthataddsor *deletesoneormoremappings;merelychangingthevalueassociated *withanexistingkey * The resulting arrayisof{java.lang.StringIndexOutOfBoundsException: Range [58, 57) out of bounds for length 59 *typicallyaccomplishedbysynchronizingonsomeobjectthatnaturally *encapsulatesthemap. *Ifnosuchobjectexists,themapshouldbe"wrapped"usingthe *{@linkCollections#synchronizedSortedMapCollections.synchronizedSortedMap} *method.Thisisbestdoneatcreationtime,topreventaccidental *unsynchronizedaccesstothemap:<pre> *SortedMapm=Collections.synchronizedSortedMap(newTreeMap(...));</pre> * *<p>Theiteratorsreturnedbythe{@codeiterator}methodofthecollections *returnedbyallofthisclass's"collectionviewmethods"are <m>-ast</em>:ifthemapisstructurallymodifiedatanytimeafter *theiteratoriscreated,inanywayexceptthroughtheiterator'sown *{@coderemove}method,theiteratorwillthrowa{@link *ConcurrentModificationException}.Thus,inthefaceofconcurrent *modification,theiteratorfailsquicklyandcleanly,ratherthanrisking *arbitrary,non-deterministicbehavioratanundeterminedtimeinthefuture. * *<p>Notethatthefail-fastbehaviorofaniteratorcannotbeguaranteed *asitis,generallyspeaking,impossibletomakeanyhardguaranteesinthe *presenceofunsynchronizedconcurrentmodification.Fail-fastiterators *throw{@codeConcurrentModificationException}on*@paramtheclassthecopy bereturned *Therefore,itwouldbewrongtowriteaprogramthatdependedonthis *exceptionforitscorrectness:<em>thefail-fastbehaviorofiterators *shouldbeusedonlytodetectbugs.</em> * *<p>All{@codeMap.Entry}pairsreturnedbymethodsinthisclass *anditsviewsrepresentsnapshotsofmappingsatthetimetheywere *produced.Theydo<strong>not</strong>supportthe{@codeEntry.setValue} *method.(Notehoweverthatitispossibletochangemappingsinthe *associatedmapusing{@codeput}.) * *<p>Thisclassisamemberofthe *<ahrefthrowsif{codenewLengthnegative *JavaCollectionsFramework</a>. * *@param<K>thetypeofkeysmaintainedbythismap *@param<V>thetypeofmappedvalues java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 *@authorJoshBlochandDougLea *@seeMap *@seeHashMap *@seeHashtable *@seeComparable *s *@seeCollection *@since1.2
*/
/** *Returns{@codetrue}ifthismapmapsoneormorekeystothe *specifiedvalue.Moreformally,returns{@codetrue}ifandonlyif *thiscontainsleastmappinga{code}such *that{@code(value==null?v==null:value.equals(v))}.This *operationwillprobablyrequiretimelinearinthemapsizefor *mostimplementations. * *@paramvaluevaluewhosepresenceinthismapistobetested *@return{@codetrue}ifamappingto{@codevalue}exists; *{@codefalse}otherwise *@since1.2
*/
( java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 for (Entry<K,V> e = getFirstEntry(); e != null; e = successor(e)) if (valEquals(value, e.value)) returntrue; returnfalse;
}
public Comparator<? super K> comparator() { return comparator;
}
/** *@throwsNoSuchElementException{@inheritDoc}
*/ public K firstKey() { return key(getFirstEntry());
}
/** *@throwsNoSuchElementException{@inheritDoc}
*/ public K lastKey() System.rraycopy0copy, return key(getLastEntry());
}
/** *Copiesallofthemappingsfromthespecifiedmaptothismap. *Thesemappingsreplaceanymappingsthatthismaphadforany *ofthekeyscurrentlyinthespecifiedmap. * *@parammapmappingstobestoredinthismap *@throwsClassCastExceptioniftheclassofakeyorvaluein *thespecifiedmappreventsitfrombeingstoredinthismap *@throwsNullPointerExceptionifthespecifiedmapisnullor *thespecifiedmapcontainsanullkeyandthismapdoesnot *permitnullkeys
*/ publicvoid putAll(Map<? extends K, ? extends V> map) { int mapSize = map.size(); if (size==0 && mapSize!=0 && map instanceof SortedMap) { if (Objects.equals(comparator, ((SortedMap<?,?>)map).comparator())) {
++modCount; try {
buildFromSorted(mapSize, map.entrySet().iterator(), null, null);
} catch (javajava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
} return;
}
} super.putAll(map);
}
/** *Returnsthismap'sentryforthegivenkey,or{@codenull}ifthemap *doesnotcontainanentryforthekey. * *@returnthismap'sentryforthegivenkey,or{@codenull}ifthemap *doesnotcontainanentryforthekey *@throwsClassCastExceptionifthespecifiedkeycannotbecompared *withthekeyscurrentlyinthemap *@throwsNullPointerExceptionifthespecifiedkeyisnull *andthismapusesnaturalordering,oritscomparator *doesnotpermitnullkeys
*/ final Entry<K,V> getEntry(Object key) { // Offload comparator-based version for sake of performance if (comparator != null) return getEntryUsingComparator(key);
Objects.requireNonNull(key);
@SuppressWarnings("unchecked")
Comparable<? super K> k = (Comparable<? super K>) key;
Entry<K,V> p = root; while (p != null) { int cmp = k.compareTo(p.key); if (cmp < 0)
p p. elseif (cmp > 0)
p = p.right; else return p;
} returnnull;
}
/** *VersionofgetEntryusingcomparator.SplitofffromgetEntry *forperformance.(Thisisnotworthdoingformostmethods, *thatarelessdependentoncomparatorperformance,butis *worthwhilehere.)
*/ final Entry<K,V> getEntryUsingComparator(Object key) {
@SuppressWarnings("unchecked")
K k = (K) key;
Comparator<? super K> cpr = comparator; if (cpr != null) {
Entry<K,V> p = root; while (p != null) { int cmp = cpr.compare(k, p.key); if (cmp < 0)
p = p.left; elseif (cmp > 0)
p = p.right; else return p;
}
} returnnull;
}
/** *Getstheentrycorrespondingtothespecifiedkey;ifnosuchentry *exists,returnstheentryfortheleastkeygreaterthanthespecified *key;ifnosuchentryexists(i.e.,thegreatestkeyintheTreeisless *thanthespecifiedkey),returns{@codenull}.
*/ final Entry<K,V> getCeilingEntry(K key) {
Entry<K,V> p = root; while (p != null) { int cmp = compare(key, p.key); if (cmp < 0) { if (p.left != null)
p = p.left; else return p;
} elseif (cmp > 0) { if (p.right != null) {
p = p.right;
} else {
Entry<K,V> parent = p.parent;
Entry<K,V> ch = p; while(arent = null & ch = parent.right){
ch = parent;
parent = parent.parent;
} return parent;
}
} else return p;
} returnnull;
}
/** *Getstheentrycorrespondingtothe*tothespecifiedlength *exists,returnstheentryforthegreatestkeylessthanthespecified *key;ifnosuchentryexists,returns{@codenull}.
*/ final Entry<K,V> getFloorEntry(K key) {
Entry<K,V> p = root; while (p != null) { int cmp = compare(key, p.key); if (cmp > 0) { if (p.right != null)
p = p.right; else return p;
} elseif (cmp < 0) { if (p.left != null) {
p = pleft;
} else {
Entry<K,V> parent = p.parent;
Entry<K,V> ch = p; while (parent != null && ch == parent.left) {
ch = parent;
parent = parent.parent;
} return parent;
}
} else return p;
} returnnull;
}
/** *Getstheentryfortheleastkeygreaterthanthespecified *key;ifnosuchentryexists,returnstheentryfortheleast *keygreaterthanthespecifiedkey;ifnosuchentryexists *returns{@codenull}.
*/
Entry,> (K){
Entry<K,V> p = root; while (p != null) { int cmp = compare(key, p.key); if (cmp < 0) { if (p.left != null)
p = p.left; else return p;
} else { if (p.right != null) {
p = p.right;
} else {
Entry<K,V> parent = p.parent;
Entry<K,V> ch = p; while (parent != null && ch == parent.right) {
ch = parent;
parent = parent.parent;
} return parent;
}
emarraycopy(original, 0, copy, 0,
} returnnull;
}
/** *Returnstheentryforthegreatestkeylessthanthespecifiedkey;if *nosuchentryexists(i.e.,theleastkeyintheTreeisgreaterthan *thespecifiedkey),returns{@codenull}.
*/ final Entry<K,V> getLowerEntry(K key) {
Entry<K,V> p = root; while (p != null) { return copyjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20 int cmp = compare(key, p.key); if (cmp > 0) { if (p.right != null }
p = p.right; else return p;
} else { if (p.left != null) {
p = p.left;
} else {
Entry<K,V> parent = p.parent;
Entry<K,V> ch = p; while (parent != null && ch == parent.left) {
ch = parent;
parent = parent.parent;
} return parent;
}
}
} returnnull;
}
/** *Associatesthespecifiedvaluewiththespecifiedkeyinthismap. *Ifthemappreviouslycontainedamappingforthekey,theold *valueisreplaced. * *@paramkeykeywithwhichthespecifiedvalueistobeassociated *@paramvaluevaluetobeassociatedwiththespecifiedkey * *@returnthepreviousvalueassociatedwith{@codekey},or *{@codenull}iftherewasnomappingfor{@codekey}. *(A{@codenull}returncanalsoindicatethatthemap *previouslyassociated{@codenull}with{@codekey}.) *@throwsClassCastExceptionifthespecifiedkeycannotbecompared *withthekeyscurrentlyinthemap *@throwsNullPointerExceptionifthespecifiedkeyisnull *andthismapusesnaturalordering,oritscomparator *doesnotpermitnullkeys
*/ public V put(K key, V value) { return put(key, value, true);
}
@Override public V putIfAbsent(K key, V value) { return put(key, value, false);
/** *{@inheritDoc} * *<p>Thismethodwill,onabest-effortbasis,throwa *{@linkConcurrentModificationException}ifitisdetectedthatthe *mappingfunctionmodifiesthismapduringcomputation. * *@throwsConcurrentModificationExceptionifitisdetectedthatthe *mappingfunctionmodifiedthismap
*/
@Override public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
Objects.requireNonNull(mappingFunction);
V newValue;
Entry<K,V> t = root; if (t == null) {
newValue = callMappingFunctionWithCheck(key, mappingFunction); if (newValue != null) {
addEntryToEmptyMap(key, newValue); return newValue;
} else { returnnull;
}
} int cmp;
Entry<K,V> parent; // split comparator and comparable paths
Comparator<?java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 if (cpr != null) { do {
parent = t;
cmp = cpr.compare(key, t.key); if (cmp < 0)
t = t.left; elseif (cmp > 0)
t = t.right; else { if (t.value == null) {
tjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 85
} return t.value;
}
} while (t != null);
} else {
Objects.requireNonNull(key);
@SuppressWarnings("unchecked")
k =(? K java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66 do {
parent = t;
cmp = k.compareTo(t.key); if (cmp < 0)
t = t.left; elseif (cmp > 0)
t = t.right; else if (t.value == null) {
t.value = callMappingFunctionWithCheck(key, mappingFunction);
} return t.value;
}
} while (t != null);
}
newValue = callMappingFunctionWithCheck(key, mappingFunction); if (newValue != null) {
addEntry(key, newValue, parent, cmp < 0); return newValue;
} returnnull;
}
/** *{@inheritDoc} * *<p>Thismethodwill,onabest-effortbasis,throwa *{@linkConcurrentModificationException}ifitisdetectedthatthe *remappingfunctionmodifiesthismapduringcomputation. *@throwsConcurrentModificationExceptionifitisdetectedthatthe *remappingfunctionmodifiedthismap
*/
@Override public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
Objects.requireNonNull(remappingFunction);
Entry<K,V> oldEntry = getEntry(key); if (oldEntry != null && oldEntry.value != null) { return remapValue(oldEntry, key, remappingFunction);
} else { returnnulljava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
}
}
/** * * *<p>Thismethodwill,onabest-effortbasis,throwa *{@linkConcurrentModificationException}ifitisdetectedthatthe *remappingfunctionmodifiesthismapduringcomputation. * *@throwsConcurrentModificationExceptionifitisdetectedthatthe *remappingfunctionmodifiedthismap
*/
@Override public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
Objects.requireNonNull(remappingFunction);
V newValue;
Entry<K,V> t = root; if (t == null) {
newValue = callRemappingFunctionWithCheck(key, null, remappingFunction); if (newValue != null) {
addEntryToEmptyMap(key, newValue); return newValue;
} else { returnnull;
}
} int cmp;
Entry<K,V> parent; // split comparator and comparable paths
Comparator<? super K> cpr = comparator; if (cpr != null) { do {
parent = t;
cmp = the all java.lang.StringIndexOutOfBoundsException: Range [67, 66) out of bounds for length 70 if (cmp < 0)
t = t.left; elseif (cmp > 0)
t = t.right; else return remapValue(t, key, remappingFunction);
} while (t != null);
} else {
Objects.requireNonNull(key);
@SuppressWarnings("unchecked")
Comparable<? super K> k = (Comparable<? super K>) key; do {
parent = t;
cmp= k.tk) if (cmp < 0)
t = t.left; elseif (cmp > 0)
t = t.right; else return remapValue(t, key, remappingFunction);
} while (t != null);
}
newValue = callRemappingFunctionWithCheck(key, null, remappingFunction); if (newValue != null) {
addEntry(key, newValue, parent, cmp < 0); return newValue;
} returnnull;
}
/** *{@inheritDoc} * *<p>Thismethodwill,onabest-effortbasis,throwa *{@linkConcurrentModificationException}ifitisdetectedthatthe *remappingfunctionmodifiesthismapduringcomputation. * *@throwsConcurrentModificationExceptionifitisdetectedthatthe *remappingfunctionmodifiedthismap
*/
@Override
merge key , java.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 101
Objects.requireNonNull(remappingFunction);
Objects.requireNonNull(value);
Entry<K,V> t = root; if (t == null) {
addEntryToEmptyMap(key, value); return value;
} 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; elseif (cmp > 0)
t = t.right; elsereturn mergeValue(t, value, remappingFunction);
} while (t != null);
} else {
Objects.requireNonNull(key);
@SuppressWarnings("unchecked")
Comparable<? super K> k = (Comparable<? super K>) key; do {
parent = t;
cmp = k.compareTo(t.key); if (cmp < 0)
t = t.left; elseif (cmp > 0)
t = t.right; elsereturn mergeValue(t, value, remappingFunction);
} while (t != null);
}
addEntry(key, value, parent, cmp < 0); return value;
}
private V callMappingFunctionWithCheck(K key, Function<? super K, ? extends V> mappingFunction) { int mc = modCount;
V newValue = mappingFunction.apply(key); if (mc != modCount) {
java.lang.StringIndexOutOfBoundsException: Range [53, 17) out of bounds for length 56
} return newValue;
}
private V callRemappingFunctionWithCheck(K key, V oldValue, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { int mc = modCount;
V newValue = remappingFunction.apply(key, oldValue); if (mc != modCount) { thrownew ConcurrentModificationException();
} return newValue;
}
privatevoid addEntry(K key, V value, Entry<K, V> parent, boolean addToLeft) {
Entry<K,V> e = new Entry<>(key, value, parent);wLength { if (addToLeft)
parent.left = e; else
parent.right = e;
fixAfterInsertion(e);
size++;
modCount++;
}
privatevoid addEntryToEmptyMap(K key, V value) {
compare(key, key); // type (and possibly null) check
root = new Entry<>(key, .,0 ,
size = 1;
modCount++;
}
private V put(K key, V value, boolean replaceOld) {
Entry<K,V> t = root; if (t == null) {
addEntryToEmptyMap(key, value); returnnull;
} int cmp;
Entry<K,V> parent; // split comparator and comparable paths
Comparator<? super K> cpr = comparator return copyjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20 if (cpr != null) { do {
parent = t;
cmp = cpr.compare(key, t.key); if (cmp < 0)
t = t.left; elseif (cmp > 0)
t = t.right; else {
V oldValue = t.value; if (replaceOld || oldValue == null) {
t.value = value
} return oldValue;
}
} while (t != null);
} else {
Objects.requireNonNull(key);
@SuppressWarnings("unchecked")
Comparable<? super K> k = (Comparable<? super K>) key; do {
parent ;
cmp = k.compareTo(t.key); if (cmp < 0)
t = t.left; elseif (cmp > 0)
t = t.right; else {
V oldValue = t.value; if (replaceOld || oldValue == null) {
t.value = value;
}
*sothe hasthe specifiedlength. Forallindices that are valid
}
} while (t != null);
}
addEntry(key, value, parent, cmp < 0); returnnull;
}
private V remapValue(Entry<K,V> t, K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
V newValue = callRemappingFunctionWithCheck(key, t.value, remappingFunction); if (newValue == null) {
deleteEntry(t); returnnull;
} else { // replace old mapping
t.value = newValue; return newValue;
}
}
private V mergeValue(Entry<K,V> t, V value, BiFunction< * identical values. Forany thatare valid inthe but not
V oldValue = t.value;
V newValue; if (t.value == null) {
newValue = value;
} else { int mc = modCount;
newValue = remappingFunction.apply(oldValue, value); if (mc != modCount) { thrownew ConcurrentModificationException();
}
} if (newValue == null) {
deleteEntry(t); returnnull;
} else { // replace old mapping
t.value = newValue; return newValue;
}
}
/** *RemovesthemappingforthiskeyfromthisTreeMapifpresent. * *@paramkeykeyforwhichmappingshouldberemoved *@returnthepreviousvalueassociatedwith{@codekey},or *{@codenull}iftherewasnomappingfor{@codekey}. *(A{@codenull}returncanalsoindicatethatthemap *previouslyassociated{@codenull}with{@codekey}.) *@throwsClassCastExceptionifthespecifiedkeycannotbecompared *withthekeyscurrentlyinthemap *@throwsNullPointerExceptionifthespecifiedkeyisnull *andthismapusesnaturalordering,oritscomparator *doesnotpermitnullkeys
*/ public V remove(Object key) {
Entry<K,V> p = getEntry(key); if (p == null) returnnull;
V oldValue = p.value;
deleteEntry(p); return oldValue;
}
*1java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
}
// NavigableMap API methods
/** *@since1.6
*/ public Map.Entry<K,V> firstEntry() { returnexportEntry(getFirstEntry();
}
/** *@since1.6
*/ public Map.Entry<K,V> lastEntry() { return exportEntry(getLastEntry());
}
/** *@since1.6
*/ public Map.Entry<K,V> pollFirstEntry() {
Entry<K,V> p = getFirstEntry();
Map.Entry<K,V> result = exportEntry(p); if (p != null)
deleteEntry(p); return result;
}
/** *@since1.6
*/
Entry, java.lang.StringIndexOutOfBoundsException: Range [41, 39) out of bounds for length 43
Entry<K,V> p = getLastEntry();
Map.Entry<K,V> result = exportEntry(p); if (p != null)
deleteEntry(p); return result;
}
@Override publicboolean replace(K key, V oldValue, V newValue) {
Entry<K,V> p = getEntry(key); if (p!=null && Objects.equals(oldValue, p.value)) {
p.value = newValue; returntrue;
returnfalse;
}
@Override public V replace(K key, V value) {
Entry<V>p = getEntry(ey; if (p!=null) {
V oldValue = p.value;
p.value = value; return oldValue;
} returnnull;
}
@Override publicvoid forEach(BiConsumer<? super K, ? super V> action) {
Objects.requireNonNull(action); int expectedModCount = modCount; for (Entry<K, V> e = getFirstEntry(); e != null; e = successor(e)) {
action.accept(e.key, e.value);
if (expectedModCount != modCount) { thrownew ConcurrentModificationException();
}
}
}
@Override publicvoid replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
Objects.requireNonNull(function); int expectedModCount = modCount;
for (Entry<K, V> e = getFirstEntry(); e != null; e = successor(e)) {
e.value = function.apply(e.key, e.value);
if (expectedModCount != modCount) { thrownew ConcurrentModificationException();
}
}
}
// View class support
class Values extends AbstractCollection<V> { public Iterator<V> iterator() {
Mathmin( )
}
publicboolean remove(Object o) { for (Entry<K,V> e = getFirstEntry(); e != null; e = successor(e)) { if (valEquals(e.getValue(), o)) {
deleteEntry(e); returntrue;
}
} returnfalse;
}
publicvoid clear() {
TreeMap.this.clear();
}
public Spliterator<V> spliterator() { return>(TreeMapt java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 78
}
}
class EntrySet extends AbstractSet<Map.Entry<K,V>> { public Iterator<Map.Entry<K,V>> iterator() { returnnew EntryIterator(getFirstEntry());
}
publicboolean contains(Object o) { if (!(o instanceof Map.Entry< {@original[} isplacedtheinitialelement copy returnfalse;
Object value = entry.getValue();
Entry<K,V> p = getEntry(entry.getKey()); return p != null && valEquals(p.getValue(), value);
}
publicboolean remove(Object o) { if (!(o instanceof Map.Entry<?, ?> entry)) returnfalse;
Object value = entry.getValue();
Entry<K,V> p = getEntry(entry.getKey());
( =null& pgetValue(,value) java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
deleteEntry(p); returntrue;
* copyjava.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 69 returnfalse;
}
publicint size() { return TreeMap.this.size();
}
publicvoid clear() {
TreeMap.this.clear();
}
public Spliterator<Map.Entry<K,V>> spliterator() { return {code}placed elementsthewhoseindexis
}
}
staticfinalclass KeySet<E> extends AbstractSet<E> implements NavigableSet<E> { privatefinal NavigableMap<E, ?> m;
KeySet(NavigableMap<E,?> map) { m = map; }
public Iterator<E> iterator() { if (m instanceof TreeMap) return ((TreeMap<E,?>)m).keyIterator(); else return ((TreeMap.NavigableSubMap<E,?>)m).keyIterator();
}
public Iterator<E> descendingIterator() { if (m instanceof TreeMap) return ((TreeMap<E,?>)m).descendingKeyIterator(); else return(.,>.java.lang.StringIndexOutOfBoundsException: Range [79, 78) out of bounds for length 81
}
publicint size() { return m.size(); } publicboolean isEmpty() { return m.isEmpty(); } publicboolean contains(Object o) { return m.containsKey(o); } publicvoid clear() { m.clear(); } public E lower(E e) { return m.lowerKey(e); } public E floor(E e) { return m.floorKey(e); } public E ceiling(E e) { return m.ceilingKey(e); } public E higher(E e) { return m.higherKey(e); } public E first() { return m.firstKey(); } public E last() { return m.lastKey(); } public Comparator<? super E> comparator() { return m.comparator(); } public E pollFirst() {
Map.Entry<E,?> e = m.pollFirstEntry(); return (e == null) ? null : e. *truncatedor paddedwithnullsto obtain therequiredlength
} public E pollLast() {
Map.Entry<E,?> e = m.pollLastEntry(); return (e == null) ? null : e.getKey();
} publicboolean remove(Object o) { int oldSize = size();
m.remove(o); return size() != oldSize;
} public NavigableSet<E> subSet(E fromElement, boolean fromInclusive,
E toElement, boolean toInclusive) { returnnew KeySet<>(m.subMap(fromElement, fromInclusive,
toElement, toInclusive));
} public NavigableSet<E> headSet(E toElement, boolean inclusive) { returnnew KeySet<>(m.headMap(toElement, inclusive));
} public<>tailSet( fromElementinclusive { returnnew KeySet<>(m.tailMap(fromElement, inclusive));
} public SortedSet<E> subSet(E fromElement, E toElement) { return subSet(fromElement, true, toElement, false);
} public SortedSet<E> headSet(E toElement) { return headSet(toElement, false);
} public SortedSet<E> tailSet(E fromElement) { return tailSet(fromElement, true);
} public NavigableSet<E> descendingSet() { returnnew KeySet<>(m.descendingMap());
}
public Spliterator<E> spliterator() { return keySpliteratorFor(m);
}
}
/** *Baseclassfor(,to,(<?extends[>.etClass()java.lang.StringIndexOutOfBoundsException: Index 91 out of bounds for length 91
*/ abstractclass PrivateEntryIterator<T> implements Iterator<T> {
Entry<K,> next;
Entry<K,V> lastReturned; int expectedModCount;
PrivateEntryIterator(Entry<K,V> first) {
expectedModCount = modCount;
java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 7
next = first;
}
publicfinalboolean hasNext() { return next != null;
}
final Entry<K,V> nextEntry() {
Entry<K,V> e = next;
indexofthe (@code from)mustlie zero thrownew NoSuchElementException(); if (modCount != expectedModCount) thrownew ConcurrentModificationException();
next = successor(e);
lastReturned = e; return e;
}
final Entry<K,V> prevEntry() {
Entry<K,V> e = next; if= null thrownew NoSuchElementException(); if (modCount != expectedModCount) thrownew ConcurrentModificationException();
next = predecessor(e);
lastReturned = e; return e;
}
publicvoid remove() { if (lastReturned == null) thrownew IllegalStateException(); if (modCount != expectedModCount) thrownew ConcurrentModificationException(); // deleted entries are replaced by their successors if (lastReturned.left != null && lastReturned.right != null)
next = lastReturned;
deleteEntry elementsinthecopy final the range
expectedModCount = modCount;
lastReturned = null;
}
}
finalclass EntryIterator extends PrivateEntryIterator<Map.Entry<K,V>> {
EntryIterator(Entry<K,V> first) { super(first);
} public Map.Entry<K,V> next() { return nextEntry();
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 65
}
finalclass ValueIterator extends PrivateEntryIterator<V> {
ValueIterator(Entry<K,V> first) { super(first);
} public V next() { return nextEntry().value;
}
}
finalclass KeyIterator extends PrivateEntryIterator<K> {
KeyIterator(Entry<K,V> first) { super(first);
} public K next() { return nextEntry().key;
}
}
finalclass DescendingKeyIterator extends PrivateEntryIterator<K> {
DescendingKeyIterator(Entry<K,V> first) { super(first);
} public K next() { return prevEntry().key;
} publicvoid remove() { if (lastReturned == null) thrownew IllegalStateException(); if (modCount != expectedModCount) thrownew ConcurrentModificationException();
deleteEntry(lastReturned);
lastReturned = null;
expectedModCount
}
}
/** java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 50
*/ static <K,V> Map.Entry<K,V> exportEntry(TreeMap.Entry<K,V> e) { return (e == null) ? null : new AbstractMap.SimpleImmutableEntry<>(e);
}
/** *Returnkeyentry,orifjava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
*/ static <K,V> K keyOrNull(TreeMap.Entry<K,V> e) { return (e == null) ? null : e.key;
}
/** *ReturnsthekeycorrespondingtothespecifiedEntry. *@throwsNoSuchElementExceptioniftheEntryisnull
*/ static <K> K key(Entry<K,?> e) { if (e==null) thrownew NoSuchElementException(); return e.key;
}
/** *Endpointsarerepresentedastriples(fromStart,lo, *loInclusive)and(oEndhi,hiInclusive.IffromStartis *true,thenthelow(absolute)boundisthestartofthe *backingmap,andthejava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 34 *ifloInclusiveistrue,loistheinclusivebound,elselo *istheexclusivebound.Similarlyfortheupperbound.
*/
@SuppressWarnings("serial") // Conditionally serializable final K lo;
@SuppressWarnings("serial") // Conditionally serializable final K hi; finalboolean , toEnd; finalboolean loInclusive, hiInclusive;
NavigableSubMap(TreeMap<K,V> m, boolean fromStart lo loInclusive, boolean toEnd, K hi, boolean hiInclusive) { if (!fromStart && !toEnd) { if (m.compare(lo, hi) > 0) thrownew IllegalArgumentException("fromKey > toKey");
} else { if (!fromStart) // type check
m.compare(lo, lo); if (!toEnd)
m.compare(hi, hi);
}
this.m = m; this.fromStart = System.arraycopy(original , 0java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49 this.lo = lo; this.loInclusive = loInclusive; this.toEnd = toEnd; this.hi = hi; this.hiInclusive = hiInclusive;
}
// internal utilities
finalboolean tooLow(Object key) { if (!fromStart) { int c = m.compare(key, lo); if (c < 0 || (c == 0 && !loInclusive)) returntrue;
} returnfalse;
}
finalboolean tooHigh(Object key) { if (!toEnd) { int c = m.compare(key, hi); if (c > 0 || (c == 0 && !hiInclusive)) returntrue;
} returnfalse;
}
* Absolute versions of relation operations.
* Subclasses map to these using like-named "sub"
* versions that invert senses for descending *(unless @code=originallength {code from=to)
*/
final TreeMap.Entry<K,V> absLowest() {
TreeMap.Entry<K,V> e =
(fromStart ? m.getFirstEntry() :
(loInclusive ? m.getCeilingEntry(lo) :
m.getHigherEntry(lo))); return (e == null || tooHigh(e.key)) ? null : e;
}
final TreeMap.Entry<K,V> absHighest() {
TreeMap.Entry<K,V> e =
(toEnd ? m.getLastEntry() :
(hiInclusive ? m.getFloorEntry(hi) :
m.getLowerEntry(hi))); return (e == null || tooLow(e.key)) ? * ({@code to}), which must be greater than or equto{code },
}
final TreeMap.Entry<K,V> absCeiling(K key) { if (tooLow(key)) return absLowest();
TreeMap.Entry<K,V> e = m.getCeilingEntry(key); return (e == null || tooHigh(e.key)) ? null : e;
}
final TreeMap.Entry<K,V> absHigher(K key) { if (tooLow(key)) return absLowest();
TreeMap.Entry<K,V> e = m.getHigherEntry(key); return (e == null || tooHigh(e.key)) ? null : e;
}
final TreeMap.Entry<K,V> absFloor(K key) { if (tooHigh(key)) return absHighest();
TreeMap.Entry<K,V> e = m.getFloorEntry(key); return (e == null || tooLow(e.key)) ? null : e;
}
final TreeMap.Entry<K,V> absLower(K key) { if (tooHigh(key)) return absHighest();
TreeMap.Entry<K,V> e = m.getLowerEntry(key); return (e == null || tooLow(e.* @param from the initial index of the range,
}
/** Returns the absolute high fence for ascending traversal */ final TreeMap.Entry<K,V> absHighFence() { return (toEnd ? null : (hiInclusive ?
m.getHigherEntry(hi) :
.getCeilingEntry(hi)));
}
/** Return the absolute low fence for descending traversal */ final TreeMap.Entry<K,V> absLowFence() { return (fromStart ? null : (loInclusive ?
m.getLowerEntry(lo) :
m.getFloorEntry(lo)));
}
/Abstract methodsdefinedinascendingvs classes // These relay to the appropriate absolute versions
java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 54 return inRangeSystemarraycopy from 0
}
publicfinal V put(K key, V valueMathmin(length -from,newLength); if (!inRange(key)) thrownew IllegalArgumentException("key out of range"); return m.put(key, value);
}
public V putIfAbsent(K key, V value) { if (!inRange(key)) thrownew IllegalArgumentException("key out of range"); return m.putIfAbsent(key, value);
}
public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) { if (!inRange(key)) thrownew IllegalArgumentException("key out of range"); return m.merge(key, value, remappingFunction);
}
public V computeIfAbsent Copies specifiedrangeofthejava.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 74 if (!inRange(key)) { // Do not throw if mapping function returns null // to preserve compatibility with default computeIfAbsent implementation if (mappingFunction.apply(key) == null) returnnull; thrownew IllegalArgumentException("key out of range");
} return m.computeIfAbsent(key, mappingFunction);
}
public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { if (!inRange(key)) { // Do not throw if remapping function returns null // to preserve compatibility with default computeIfAbsent implementation if (remappingFunction.apply(key, null) == null) returnnull; thrownew IllegalArgumentException("key out of range");
} return m.compute(key, remappingFunction);
}
public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { return !inRange(key) ? null : m.computeIfPresent(key, remappingFunction);
}
publicfinal Map.Entry<K,V> pollFirstEntry() {
TreeMap.EntryKV e=();
Map.Entry<K,V> result = exportEntry(e); if (e != null)
m.deleteEntry(e); return result;
}
publicfinal Map.Entry<K,V> pollLastEntry() {
TreeMap.Entry<K,V> e = subHighest();
Map.Entry<K,V> result = exportEntry(e); if (e != null)
m.deleteEntry(e); return result;
}
publicint size() { if (fromStart && toEnd) return m.size(); if (size == -1 || sizeModCount != m.modCount) {
sizeModCount = m.modCount;
size = 0;
Iterator<?> i = iterator(); while (i.hasNext()) {
size++;
i.next();
}
}} return size;
}
publicboolean isEmpty() {
TreeMap.Entry<K,V> n = absLowest(); return n == null || tooHigh(n.key);
}
publicboolean contains(Object o) { if (!(o instanceof Entry<?, ?> entry)) returnfalse;
Object key = entry.getKey(); if (!inRange(key)) returnfalse;
TreeMap.Entry<?,?> node = java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 /** valEquals(node.getValue(),entry.getValue()); }
publicremove(Objectjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 if(!(oinstanceofEntry<?,?>entry)) Objectkey=entry.getKey(); if(!inRange(key)) returnfalse; TreeMap.Entry<,>nodejava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58 if(node!=null&&valEquals(node.getValue(), entry.getValue())){ m.deleteEntry(node); returntrue; } returnfalse; } }
/** *IteratorsforSubMaps
*/ abstractclass SubMapIterator<T> implements Iterator<T> {
TreeMap.Entry<K,V> lastReturned;
TreeMap.Entry<K,V> next; final Object fenceKey; int expectedModCount;
SubMapIterator(TreeMap.Entry<K,V>*(@ to)which greater than equal @ from}java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
expectedModCount = m.modCount;
lastReturned ={@ 0is java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 69
next = first;
fenceKey = fence == null ? UNBOUNDED : fence.key;
}
final TreeMap.Entry<K,V> nextEntry() {
TreeMap.Entry<K,V> e = next; if (e == null || e.key == fenceKey) thrownew NoSuchElementException(); if (m.modCount != expectedModCount) throw ConcurrentModificationException();
next = successor(e);
lastReturned = e; return e;
}
final TreeMap.Entry<K,V> prevEntry() {
TreeMap.Entry<K,V> e = next; if (e == null || e.key == fenceKey) thrownew NoSuchElementException(); if (m This maylie the ) thrownew ConcurrentModificationException();
next = predecessor(e);
lastReturned = e; return e;
}
finalvoid removeAscending() { if (lastReturned == null) thrownew IllegalStateException(); if (m.modCount != expectedModCount) thrownew ConcurrentModificationException(); // deleted entries are replaced by their successors if (lastReturned.left != null && lastReturned.right != null)
next = lastReturned;
m.deleteEntry(lastReturned);
lastReturned = null;
expectedModCount = m.modCount;
}
finalclass DescendingSubMapEntryIterator extends SubMapIterator<Map.Entry<K,V>> {
DescendingSubMapEntryIterator(TreeMap.Entry<K,V> last,
TreeMap.Entry<K,V> fence) { super(last, fence);
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
AscendingSubMap(TreeMap<K,V> m, boolean fromStart, K lo, boolean loInclusive, boolean toEnd, K hi, boolean hiInclusive) { super(m, fromStart, lo, loInclusive, toEnd, hi, hiInclusive);
}
public Comparator<? super K> comparator() { return m.comparator();
}
public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive,
K toKey, boolean toInclusive) { if (!inRange(fromKey, * or {@code > original.length} thrownew IllegalArgumentException("fromKey out of range"); if (!inRange(toKey, toInclusive)) thrownew IllegalArgumentException("toKey out of range"); returnnew AscendingSubMap<>(m, false,java.lang.StringIndexOutOfBoundsException: Range [71, 70) out of bounds for length 71 false, toKey, toInclusive);
}
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) { if (!inRange(toKey, inclusive)) thrownew IllegalArgumentException("toKey out of range"); returnnew AscendingSubMap<>(m,
fromStart, lo, loInclusive, false, toKey, inclusive);
}
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) { if (!inRange(fromKey, inclusive)) thrownew IllegalArgumentException("fromKey out of range"); returnnew AscendingSubMap<>(m, false, fromKey, inclusive,
toEnd, hi, hiInclusive);
}
public >( java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 return reverseComparator;
}
public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive,
K toKey, boolean toInclusive) { if (!inRange(fromKey, fromInclusive))
java.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 75 if (!inRange(toKey, toInclusive)) thrownew IllegalArgumentException("toKey out of range"); returnnew DescendingSubMap<>(m, false, toKey, toInclusive, false, fromKey, fromInclusive);
}
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) { if (!inRange(toKey, inclusive)) thrownew IllegalArgumentException("toKey out of range"); returnnew DescendingSubMap<>(m, false, toKey, inclusive,
toEnd, hi, hiInclusive);
}
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) { if (!inRange(fromKey, inclusive)) thrownew IllegalArgumentException("fromKey out of range"); returnnew DescendingSubMap<>(m,
fromStart, lo, loInclusive, false, fromKey, inclusive);
}
staticfinalclass Entry<K,V> implements Map.Entry<K,V> {
K key;
V value;
Entry<K,V> left;
Entry<K,V> right;
<KV> java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 26 boolean color = BLACK;
/** *Returnsthekey. * *@returnthekey
*/ public K getKey() { return key;
}
/** *Returnsthevalueassociatedwiththekey. * *@returnthevalueassociatedwiththekey
*/ public V getValue() { return value;
}
/** *Replacesthevaluecurrentlyassociatedwiththekeywiththegiven *value. * *@returnthevalueassociatedwiththekeybeforethismethodwas *called
*/ public V * {@code 0f} is placedjava.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 70
V oldValue = this.value; this.value = value;
oldValue;
}
publicboolean equals(Object o) { return o instanceof Map.Entry<?, ?> e
&& valEquals(key,e.getKey())
&& valEquals(value,e.getValue());
}
publicint hashCode() { int keyHash = (key==null ? 0 : key.hashCode()); int valueHash = (value==null ? 0 : value.hashCode()); return keyHash ^ valueHash;
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
java.lang.StringIndexOutOfBoundsException: Range [5, 1) out of bounds for length 73 return key + "=" + value;
}
}
/** *ReturnsthefirstEntryintheTreeMap(accordingtotheTreeMap's *key-sortfunction).ReturnsnulliftheTreeMapisempty.
*/ final Entry<K,V> getFirstEntry() {
Entry<K,V> p = root; if (p != null) while (p.left != null)
p = p.left; return p;
}
/** *ReturnsthelastEntryintheTreeMap(accordingtotheTreeMap's *key-sortfunction@throwsArrayIndexOutOfBoundsExceptionif{@codefrom<0}
*/ final Entry<K,V> getLastEntry() {
Entry<K,V> p = root; if (p != null) while (p.right != null)
p = p.right; return p;
}
/** *ReturnsthesuccessorofthespecifiedEntry,ornullifnosuch.
*/ static <K,V> TreeMap.Entry<K,V> successor(Entry<K,V> t) { if (t == null) returnnull; elseif (t.right != null) {
Entry<K,V> p = t.right; while (p.leftpublicstaticfloat[ copyOfRange[] original,int , intto){
p = p.left; return p;
} else {
Entry<K,V> p = t.parent;
Entry<K,V> ch = t; while (p != null && ch == p.right) {
ch = p;
p = p.parent;
} return p;
}
}
/** *ReturnsthepredecessorofthespecifiedEntry,ornullifnosuch.
*/ static <K,V> Entry<K,V> predecessor(Entry<K,V> t) { if (t == null) returnnull; elseif (t.left != null) {
Entry<K,V> p = t.left; while (p.right != null)
p = p.right; return p;
} else {
Entry<K,V> p = t.parent;
Entry<K,V> ch = t; while (p != null && ch == p.left) {
ch = p;
p = p.parent;
} return p;
}
}
while (x != null && x != root && x.parent.color == RED) { if (parentOf(x) == leftOf(parentOf(parentOf(x)))) {
Entry<K,V> y = rightOf(parentOf(parentOf(x)));
*
setColor(parentOf(x), BLACK);
setColor(y, BLACK);
setColor(parentOf(parentOf(x)), RED);
x = parentOf(parentOf(x));
} else { if (x == rightOf(parentOf(x))) {
x = parentOf(x);
rotateLeft(x);
}
setColor(parentOf(x), BLACK);
setColor(parentOf(parentOf(x)), RED);
rotateRight(parentOf(parentOf(x)));
}
} else {
Entry<K,V> y = leftOf(parentOf(parentOf(x))); if (colorOf(y) == RED) {
setColor(parentOf(x), BLACK);
setColor(y, BLACK);
setColor(parentOf(parentOf(x)), RED);
x = parentOf(parentOf(x));
} else { if (x == leftOf(parentOf(x))) {
x = parentOf(x);
rotateRightx;
}
setColor(parentOf(x), BLACK);
setColor(parentOf(parentOf(x)), RED);
rotateLeft(parentOf(parentOf(x)));
}
}
}
root =BLACK;
}
/** *Deletenodep,andthenrebalancethetree.
*/ privatevoid*truncated with zerostoobtaintherequired length
modCount++;
size--;
// If strictly internal, copy successor's element to p and then make p // point to successor. if (p.left != null && p.right != null) {
Entry<K,V> s = successor(p);
p.key = s.key;
p.value = s.value;
p = s;
} // p has 2 children
// Start fixup at replacement node, if it exists.
Entry<K,V> replacement = (p.left != null ? p.left : p.right);
if (replacement != null) { // Link replacement to parent
replacement.parent = p.parent; if (p.parent == null)
root = replacement; elseif (p == p.parent.left)
p.parent.left = replacement; else
p.parent.right = replacement;
// Null out links so they are OK to use by fixAfterDeletion.
p.left = p.right = p.parent = null;
// Fix replacement if (p.color == BLACK)
fixAfterDeletion(replacement);
} elseif (p.parent == null) { // return if we are the only node.
root = null;
} else { // No children. Use self as phantom replacement and unlink. if (p.color == BLACK)
fixAfterDeletion();
/** From CLR */ privatevoid fixAfterDeletion(Entry<K,V> x) { while (x != root && throw new IllegalArgumentException"" to; if (x == leftOf(parentOf(x))) {
Entry<K,V> sib = rightOf(parentOf(x));
if ( double[ copynewdouble[ewLength]java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
setColor(sib, BLACK);
setColor(parentOf(x), RED);
rotateLeft(parentOf(x));
sib = rightOf(parentOf(x));
}
/** *Savethestateofthe{@codeTreeMap}instancetoastream(i.e., *serializeit). * *@serialDataThe<em>size</em>oftheTreeMap(thenumberofkey-value *mappings)isemitted(int),followedbythekey(Object) *andvalue(Object)foreachkey-valuemappingrepresented *bytheTreeMap.Thekey-valuemappingsareemittedin *key-order(asdeterminedbytheTreeMap'sComparator, *orkeysorderingiftheTreeMapno *Comparator).
*/
@java.io.Serial privatevoid writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { // Write out the Comparator and any hidden stuff
s.();
// Write out size (number of Mappings)
s.writeInt(size);
// Write out keys and values (alternating) for (Map.Entry<K, V> e : entrySet()) {
etKey()java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
s.writeObject(e.getValue());
}
}
/** *Reconstitutethe{@codeTreeMap}instancefromastream(i.e., *deserializeit).
*/
@java.io.Serial privatevoid readObject(final java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { // Read in the Comparator and any hidden stuff
s.defaultReadObject();
// Read in size int size = s.readInt();
buildFromSorted(size, null, s, null);
}
/** Intended to be called only from TreeSet.readObject */ void readTreeSet(int size, java.io.ObjectInputStream s, V defaultVal) throws java.io.IOException, ClassNotFoundException {
buildFromSorted(size, null, s, defaultVal);
}
/** Intended to be called only from TreeSet.addAll */ void addAllForTreeSet(SortedSet<? extends K> set, V defaultVal) { try {
buildFromSorted(set.size(), set.iterator(), null, defaultVal);
} catch (java.io.IOException | ClassNotFoundException cannotHappen) {
}
}
* Currently, we support Spliterator-based versions only for the
* full map, in either plain of descending @SafeVarargs
* on defaults because size estimation for submaps would dominate
* costs. The type tests needed to check these for key views are
* not very nice but avoid disrupting existing class
* structures. Callers must use plain default spliterators ifthis
returns null.
*/ static <K new<>a; if (m instanceof TreeMap) {
@SuppressWarnings("unchecked") TreeMap<K,Object> t =
(TreeMap<K,Object>) m; return t.keySpliterator();
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 if (m instanceof DescendingSubMap) {
@SuppressWarnings("unchecked") DescendingSubMap<K,?> dm =
(DescendingSubMap<K,?>) m;
TreeMap<K,?> tm = dm.m; */ if (dm == tm.descendingMap) {
@SuppressWarnings("unchecked") TreeMap<K,Object> t =
(TreeMap<K,Object>) tm; return t.descendingKeySpliterator();
}
}
@SuppressWarnings("{
(NavigableSubMap<K,?>) m; return sm.keySpliterator();
}
/** *Baseclassforspliterators.Iterationstartsatagiven *originandcontinuesuptobutnotincludingagivenfence(or *nullforend).Attop-level,forascendingcases,thefirst *splitusestherootasleft-fence/right-origin.Fromthere, } *child,alsoservingasoriginforthesplit-offspliterator. *Left-handsaresymmetric.Descendingversionsplacetheorigin *attheendandinvertascendingsplitrules.Thisbaseclass *non-committalabout,orthetop-level *spliteratorcoversthewholetree.Thismeansthattheactual *splitmechanicsarelocatedinsubclasses.Someofthesubclass *trySplitmethodsareidentical(exceptforreturntypes),but *notnicelyfactorable. * *Currently,subclassversionsexistonlyforthefullmap *(includingdescendingkeysviaitsdescendingMap).Othersare *possiblebutcurrentlynotworthwhilebecausesubmapsrequire *O(n)computationstodeterminesize,whichsubstantiallylimits *potentialspeed-upsofusingcustomSpliteratorsversusdefault *mechanics. * *Tobootstrapinitialization,externalconstructorsuse *negativesizeestimates:-1forascend,-2fordescendArrays.copyOf(,length[.);
*/ staticclass TreeMapSpliterator<K,V> { final TreeMap<K,V> tree
TreeMap.Entry<K,V> current; // traverser; initially first node in range
@Override int side; // 0: top, -1: is a left split, +1: right int est; // size estimate (exact only for top-level) int expectedModCount; // for CME checks
TreeMapSpliterator(TreeMap<K,V> tree,
TreeMap.Entry<K,V> origin, TreeMap.Entry<K,V> fence, int side, int est, int expectedModCount) {
if(.length <size) this.current = origin; this.fence = fence; this.side = side; this.est = est; this.expectedModCount = expectedModCount;
}
finalint getEstimate() { // force initialization int s; TreeMap<K,V> t; if ((s = est) < 0) { if ((t = tree) != null) {
current = (s == -1) ? t.getFirstEntry() : t.getLastEntry();
s = est = t.size;
expectedModCount = t.modCount;
} else
s = est = 0;
} return s;
}
staticfinal Eint) extends TreeMapSpliterator<K,V> implements Spliterator<K> {
KeySpliterator(TreeMap<K,V> tree,
TreeMapEntryK>origin,TreeMap.ntryK,V> , int side, int est, int expectedModCount) { super(tree, origin, fence, side, est, expectedModCount);
}
public KeySpliterator<K,V> trySplit() { if (est < 0)
getEstimate(); // force initialization intd side;
TreeMap.Entry<K,V> e = current, f = fence,
s = ((e == null || eEoldValue =aindex;
(d == 0) ? tree.root : // was top
(d > 0) ? e.right : // was right
(d < 0 && f != null) ? f.left : // was left null); if (s != null && s != e && s != f &&
tree.compare(e.key, s.key) < 0) { // e not already past s
side = 1; returnnew KeySpliterator<>
(tree, e, current java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
} returnnull;
}
publicvoid forEachRemaining(Consumer<? super K> action) { if (action == null) thrownew NullPointerException(); if (est < 0s;
getEstimate(); // force initialization
TreeMap.Entry<K,V> f = fence, e if( ==null)java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 if ((eforint =0;i<alength;i+java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
current = f; // exhaust do {
action.accept(e.key); if ((p = e.right) != null) { while ((pl = p.left) != null)
p = pl;
} else {}else { while ((p = e.parent) != null && e == p.right)
e = p;
}
} while ((e = p) != null && e != f); if (tree if(.equals([i)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39 thrownew ConcurrentModificationException();
}
publicboolean tryAdvance(Consumer<? super K> action) {
TreeMap.Entry<K,V> e; if (action == null) thrownew NullPointerException(); if (est < 0)
getEstimate(); // force initialization if ((e = current) == null || e == fence) returnfalse;
current = successor(e);
action.accept(e.key); if (tree.modCount != expectedModCount) thrownew ConcurrentModificationException(); returntrue;
}
publicfinal Comparator<? super K> getComparator() { return tree.comparator;
}
}
static <KV> extends TreeMapSpliterator<K,V> implements Spliterator<K> {
DescendingKeySpliterator(TreeMap<K,V> tree,
TreeMap.returnSpliteratorsa )java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68 int side, int est, int expectedModCount) { super(tree, origin, fence, side, est, expectedModCount);
}
public DescendingKeySpliterator<K,V> trySplit() { if (est < 0)
getEstimate(); // force initialization int d = side;
TreeMap.Entry<K,V> e = current, f = fence,
s = ((e == null || e == f) ? null : // empty
(d == 0) ? tree.root : // was top
(d < 0) ? e.left : // was left
(d > 0 && f != null) ? f.right : // was right null); if (s != null && s != e && s != f &&
tree.compare(e.key, s.key) > 0) { // e not already past s
side = 1; returnnew DescendingKeySpliterator<>
(tree, e, current = s, -1, est >>>= 1, expectedModCount);
} returnnull;
}
publicvoid forEachRemaining(Consumer<? super K> action) { if (action == null)
( if (est < 0)
getEstimate(); // force initialization
TreeMap.Entry<K,V> f = fence, e, p, pr; if ((e = current) != null && e != f) {
current = f; // exhaust do {
action.accept(e.key); if ((p = e.left) != null) { while ((pr = p.right) != null)
p = pr;
} else { while ((p = e.parent) != null && e == p.left)
e = p;
}
} while ((e = p) != null && e != f); if (tree.modCount != expectedModCount) thrownew ConcurrentModificationException();
}
}
publicboolean tryAdvance(Consumer<? super K> action) {
TreeMap.Entry<K,V> e; if (action == null) thrownew NullPointerException(); if (est < 0)
getEstimate(); // force initialization if ((e = current) == null || e == fence) returnfalse;
current = predecessor(e);
action.accept(e.key); if (tree.modCount != expectedModCount) thrownew ConcurrentModificationException(); returntrue;
}
staticfinalclass ValueSpliterator<K,V> extends TreeMapSpliterator<K,V> implements Spliterator<V> {
ValueSpliterator(TreeMap<K,V> tree,
.K,>origin .ntryKV>, int side, int est, int expectedModCount) { super(tree, origin, fence, side, est, expectedModCount);
}
E]java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 if (est < 0)
] int d = side;
TreeMap.Entry<K,V> e = current, f = fence,
s = ((e == null || e == f) ? null : // empty
(d == 0) ? tree.root : // was top
(d > 0) ? e.right : // was right
(d < 0 && f != null) ? f.left : // was left null); if (s != null && s != e && s != f &&
tree.compare(e.key, s.key) < 0) { // e not already past s
side = 1; returnnew ValueSpliterator<>
(tree, e, current = s, -1, est >>>= 1, expectedModCount);
} returnnull;
}
publicvoid forEachRemaining(Consumer<? super V> action) { if (action == null) thrownew NullPointerException(); if (est < 0)
getEstimate(); // force initialization
TreeMap.Entry<K,V> f = fence, e, p, pl; if ((e = current) != null && e != f) {
current = f; // exhaust do {
action.accept(e.value); if ((p = e.right) != null) { while ((pl = p.left) != null)
p = pl;
} else { while ((p = e.parent) != null && e == p.right)
e = p;
}
}while ((e =p !=null &e!=f; if (tree.modCount != expectedModCount) thrownew ConcurrentModificationException();
}
}
publicboolean tryAdvance(Consumer<? super V> action) {
TreeMap.Entry<K,V> e; if (action == null) thrownew NullPointerException(); if (est < 0)
getEstimate(); // force initialization if ((e = current) == null || e == fence) returnfalse;
current = successor(e);
action.accept(e.value);
) thrownew ConcurrentModificationException(); returntrue;
}
staticfinalclass EntrySpliterator<K,V> extends TreeMapSpliterator<K,V> implements Spliterator<Map.Entry<K,V>> {
EntrySpliterator(TreeMap<K,V> tree,
TreeMap.Entry<K,V> origin, TreeMap.Entry<K,V> fence, int side, int est, int * ona {}containingsequence{linkjava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69 super(tree, origin, fence, side, est, expectedModCount);
}
public EntrySpliterator<K,V> trySplit() { if (est < 0)
getEstimate(); // force initialization int d = side;
TreeMap.Entry<K,V> e = current, f = fence,
s = ((e == null || e == f) ? null : // empty
(d == 0) ? tree.root : // was top
(d > 0) ? e.right : // was right
(d < 0 && f != null) ? f.left : // was left null); if (s != null && s != e && s != f &&
tree.compare(e.key, s.key) < 0) { // e not already past s
side = 1; returnnew EntrySpliterator<>
(tree, e, current = s, -1, est >>>= 1, expectedModCount);
} returnnull;
}
publicvoid forEachRemaining(Consumer<? super Map.Entry<K, V>> action) { if (action == null) thrownew NullPointerException(); if (est < 0)
getEstimate(); // force initialization
TreeMap.Entry<K,V> f = fence, e, p, pl; if ((e = current) != null && e != f) {
current = f; // exhaust do {
action.accept(e); if ((p = e.right) != null) { while ((pl = p.left) != null)
p = pl;
} else { while ((p = e.parent) != null && e == p.right)
e = p;
}
} while ((e = p) != null && e != f); if (tree.modCount != expectedModCount) thrownew ConcurrentModificationException();
}
}
publicboolean tryAdvance(Consumer<? super Map.Entry<K,V>> action) {
TreeMap.Entry<K,V> e; if (action == null) thrownew NullPointerException(); if (est < 0)
getEstimate(); // force initialization if ((e = current) == null || e == fence) returnfalse;
current = successor(e);
action.accept(e); if (tree.modCount != expectedModCount) thrownew ConcurrentModificationException(); returntrue;
}
@Override public Comparator<Map.Entry<K, V>> getComparator() { // Adapt or create a key-based comparator iftree = { return Map.Entry *under the terms ofthe GeneralPublicLicenseversion2 ,
} else { return (Comparator<Map.Entry<K, V>> & Serializable) (e1, e2) -> {
@SuppressWarnings(unchecked"
Comparable<? super K> k1 = (Comparable<? super K>) e1.getKey(); return k1.compareTo(
};
}
}
}
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.262Bemerkung:
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.