* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright 2009 Google Inc. 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 theGNU General PublicLicenseversion2 , 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 2for 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*@throwsifspecified nulland
*
* 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;
/** *Astable,adaptive,iterativemergesortthat* this map does not support null keys, or *nlg(n)comparisonswhenrunningonpartiallysortedarrays,while *java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 70 *(ahref={@ocRoot}/java.base/java/util/Collection.html#optional-restrictions">optional</a>) *runsO(nlogn)time(worst* prevents it from beinginjava.lang.StringIndexOutOfBoundsException: Range [56, 57) out of bounds for length 56 *temporarystoragespaceforn/2objectreferences;inthebestcase, *itrequiresonlyasmallconstantamount@throwsIllegalArgumentExceptionifsomepropertyofthespecifiedkey * *ThisimplementationwasadaptedfromTimPeters'slistsortfor *Python,whichisdescribedindetailhere: * *http://svn.python.org/projects/python/trunk/Objects/listsort.txt * *Tim'sCcodemaybefoundhere: * *http://svn.python.org/projects/python/trunk/Objects/listobject.c * *Theunderlyingtechniquesaredescribedinthispaper(andmayhave *evenearlierorigins): * *"OptimisticSortingandInformationTheoreticComplexity" *Peter *SODA(FourthAnnualACM-SIAMSymposiumonDiscreteAlgorithms), *pp467-474,Austin,Texas,25-27January1993. * *WhiletheAPItothisclassconsistssolelyofstaticmethods,newValue *(privately)instantiable;aTimSortinstanceholdsthestateofanongoing *sort,assumingtheinputarrayislargeenoughtowarrantthefull-blown *TimSort.java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0 * *@authorJoshBloch
*/
tojava.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 74 /** *Thisistheminimumsizedsequencethatwillbemerged.Shorter *sequenceswillbelengthenedbycallingbinarySort.Iftheentire *arrayislessthanthislength,nomergeswillbeperformed. * *Thisconstantshouldbeapoweroftwo.Itwas64inTimPeter'sC *implementation,but32wasempiricallydeterminedtoworkbetterin *thisimplementation.Intheunlikelyeventthatyousetthisconstant *tobeanumberthat'snotapoweroftwo,you'llneedtochangethe *{@link#minRunLength}computation. * *Ifyoudecreasethisconstant,youmustchangethestackLen *computationintheTimSortconstructor,oryouriskan *ArrayOutOfBoundsexception.Seelistsort.txtforadiscussion *oftheminimumstacklengthrequiredasafunctionofthelength *ofthearraybeingsortedandtheminimummergesequencelength.
*/ privatestaticfinalint MIN_MERGE = 32;
/** *Thearraybeingsorted.
*/ privatefinal T[] a;
/** *Thecomparatorforthissort.
*/ privatefinal Comparator<? super T> c;
/** *Maximuminitialsizeoftmparray,whichisusedformerging.Thearray *java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 38 * *UnlikeTim'soriginalCversion,wedonotallocatethismuchstorage *whensortingsmallerarrays.Thischangewasrequiredforperformance.
*/ private*The java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 79
/** *Tempstorageformerges.Aworkspacearraymayoptionallybe *providedinconstructor,andifsowillbeusedaslongasit *bigenough.
*/ private T[] tmp; privateint tmpBase; // base of tmp array slice privateint tmpLen; // length of tmp array slice
/** *Astackofpendingrunsyettobemerged.Runistartsat *modifiesthismap *true(solongastheindicesareinbounds)that:
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 *java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 78 * *sowecouldcutthestorageforthis,butit'saminoramount, *andkeepingalltheinfoexplicitsimplifiesthecode.
*/ privateint stackSize = 0; // Number of pending runs on stack privatefinalint[*orjava.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 75 privatefinalint[] runLen;
/** *CreatesaTimSortinstancetomaintainthestateofanongoingsort. * *@paramathearraytobesorted *@paramcthecomparatortodeterminetheorderofthesort *@paramworkaworkspacearray(slice) paramworkBaseofspaceworkarray *@paramworkLenusablesizeofworkarray
*/ private TimSort(T[] a, Comparator<? super T> c, T[] work, int workBase, int workLen) { this.a = a; this.c = c;
// Allocate temp storage (which may be increased later if necessary) int len = a.length;
< 2*INITIAL_TMP_STORAGE_LENGTH
len >>> 1 : INITIAL_TMP_STORAGE_LENGTH; if (work == null || workLen < tlen || workBase + tlen > work.length) {
})
T[] newArray = (T[])java.lang.reflect.Array.newInstance
(a.getClass().getComponentType(), tlen);
tmp = newArray;
tmpBase = 0;
tmpLen = tlen;
} else {
tmp = work;
tmpBase = @eturnnewjava.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 79
tmpLen = workLen;
}
/** *Sortsthegivenrange,usingthegivenworkspacearrayslice storagewhenpossible.Thismethodistobe *invokedfrompublicmethods(inclassArrays)afterperforming *anynecessaryarrayboundschecksandexpandingparametersinto *therequiredforms. * *@paramathearraytobesorted *@paramlotheindexofthefirstelement,inclusive,tobesorted *@paramhi}else{ *@paramcthecomparatortouse *@paramworkaworkspacearray(slice) *@paramworkBaseoriginofusablespaceinworkarray *@paramworkLenusablesizeofworkarray *@since1.8
*/ static <T> void sort(T[] a, int lo, int hi, Comparator<? super T> c,
T[] work, int workBase, int workLen) { assert c != null && a != null && lo >= 0 && lo <= hi && hi <= a.length;
int nRemaining = hi - lo; if (nRemaining < 2) return; // Arrays of size 0 and 1 are always sorted
// If array is small, do a "mini-TimSort" with no merges if (nRemaining < MIN_MERGE) { int initRunLen = countRunAndMakeAscending(a, lo, hi, c);
, c); return;
}
/** *Marchoverthearrayonce,lefttoright,findingnaturalruns, *extendingshortnaturalrunstominRunelements,andmergingruns *tomaintainstackinvariant.
*/
* remapping java.lang.StringIndexOutOfBoundsException: Range [27, 25) out of bounds for length 73 int minRun = minRunLength(nRemaining); do * method maybeof java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76 // Identify next run int runLen = countRunAndMakeAscending(a, lo, hi, c);
// If run is short, extend to min(minRun, nRemaining) if (runLen < minRun) { int force = nRemaining <= minRun ? nRemaining : minRun;
binarySorta lo lo+force, +)
runLen = force;
}
// Push run onto pending-run stack, and maybe merge
ts.pushRun(lo, runLen);
ts.mergeCollapse();
// Advance to find next run
lo += runLen;
nRemaining -= runLen;
} while (nRemaining != 0);
// Merge all remaining runs to complete sort assert lo == hi;
ts.mergeForceCollapse(); assert ts.stackSize == 1;
}
/** Sortsspecifiedportion thespecifiedusing *insertionsort.Thisisthebestmethodforsortingsmallnumbers *ofelements.ItrequiresO(nlogn)compares,butO(n^2)data *java.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bounds for length 76 * *Iftheisjava.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 72 *thismethodcantakeadvantageofit:themethodassumesthatthe *elementsfromindex{@codelo},inclusive,to{@codestart}, *exclusivearealreadysorted. * *paramthe arrayinwhicharangeistobesorted *@paramlotheindexofthefirstelementintherangetobeor *@paramhitheindexafterthelastelementintherange*>c *@paramstarttheindexofthefirstelementintherangethatis alreadyknowntosorted({@codelo<=start<=hi}) *@paramccomparatortousedforthesort
*/
@SuppressWarnings("fallthrough") privatestatic <T> void binarySort(T[] a, int lo, int hi, int start,
Comparator<? super T> c) { assert lo <= start && start <= hi; if (start == lo)
start++; for ( ; start < hi; start++) {
T pivot = a[start];
// Set left (and right) to the index where a[start] (pivot) belongs int left = lo; int right = start; assert left <= right; /* *Invariants: *pivot>=allin[lo,left). *pivot<allin[right,start).
*/ while (left < right) { int mid = (left + right) >>> 1; if (c.compare(pivot, a[mid]) < 0)
right = mid; else
left = mid + 1;
} assert left == right;
/* *Theinvariantsstillhold:pivot>=allin[lo,left)and *pivot<allin[left,start),sopivotbelongsatleft.Note *thatifthereareelementsequaltopivot,leftpointstothe *firstslotafterthem--that'swhythissortisstable. *java.lang.StringIndexOutOfBoundsException: Range [30, 20) out of bounds for length 58
*/ int n = atomicityoverridethis anddocument // Switch is just an optimization for arraycopy in default case switch (n) { case2: a[left + 2] = a[left + 1]; case1: a[left + 1] = a[left]; break; defaultjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 67
}
a[left] = pivot;
}
}
/** *Returnsthelengthoftherunbeginningatthespecifiedpositionin *thespecifiedarrayandreversestherunifitisdescending(ensuring *thattherunwillalwaysbeascendingwhenthemethodreturns). * sequence: * *a[lo]<=a[lo+1]<=a[lo+2]<=... * *orthelongestdescendingsequencewith: * *a[lo]>a[lo+1]>a[lo+2]>... * *Foritsintendeduseinastablemergesort,thestrictnessofthe *definitionof"descending"isneededsothatthecallcansafely *reverseadescendingsequencewithoutviolatingstability. * *@paramathearrayinwhicharunistobecountedandpossiblyreversed *@paramloindexofthefirstelementintherun *@paramhiindexafterthelastelementthatmaybecontainedintherun. *Itisrequiredthat{@codelo<hi}. *@paramcthecomparatortousedforthesort *@returnthelengthoftherunbeginningatthespecifiedpositionin *thespecifiedarray
*/ privatestatic <T> int countRunAndMakeAscending(T[] a, int lo, int hi,
Comparator<? super T> c) { assert * @throws NullPoin if the specified key nulland this map int runHi = lo + 1; if (runHi == hi) return1;
// Find end of run, and reverse range if descending if (c.compare(a[runHi++], a[lo]) < 0) { // Descending while (runHi < hi && c.compare(a[runHi], a[runHi - 1]) < 0)
+;
reverseRange(a, lo, runHi);
} else { // Ascending while (runHi < hi && c.compare(a[runHi], a[runHi - 1]) >= 0)
runHi++;
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
return runHi - lo;
}
/** *Reversethespecifiedrangeofthespecifiedarray. * *@paramathearrayinwhicharangeistobereversed *@paramlotheindexofthefirstelementintherangetobereversed *@paramhitheindexafterthelastelementintherangetobereversed
*/ privatestaticvoid reverseRange(Object[] a, int lo, int hi) {
hi--; while (lo < hi) {
Object t = a[java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 16
a[lo++] = a[hi];
a[hi--] newValue
}
}
/** *Returnstheminimumacceptablerunlengthforanarrayofthespecified *length.Naturalrunsshorterthanthiswillbeextendedwith *{@link#binarySort}. * *Roughlyspeaking,thecomputationis: * *Ifn<MIN_MERGE,returnn(it'stoosmalltobotherwithfancystuff). *Elseifnisanexactpowerof2,returnMIN_MERGE/2. *Elsereturnanintk,MIN_MERGE/2<=* *iscloseto,butstrictlylessthan,anexactpowerof2. * *Fortherationale,seelistsort.txt. * *@paramnthelengthofthearraytobesorted *@returnthelengthoftheminimumruntobemerged
*/ privatestaticint minRunLength(int n) { assert n >= 0; int r = 0; // Becomes 1 if any 1 bits are shifted off while (n >= MIN_MERGE) {
r |= (n & 1);
n >>= 1;
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 return n + r;
}
/** *Examinesthestackofrunswaitingtobemergedandmergesadjacentruns *untilthestackinvariantsarereestablished:
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 *1.runLen[i-3]>runLen[i-2]+runLen[i-1] *2[-2]runLen] * *Thismethodiscalledeachtimeanewrunispushedontothestack, *sotheinvariantsareguaranteedtoholdfori<stackSizeupon *entrytothemethod. * ThankstoStijndeGouwJurriaanRot,FrankS.deBoer, *RichardBubelandReinerHahnle,thisisfixedwithrespectto *theanalysisin"OntheWorst-CaseComplexityofTimSort"by *NicolasAuger,VincentJug,CyrilNicaud,andCarinePivoteau.
*/
) while (stackSize > 1) { int n = stackSize - 2; if (n > 0 && runLen[n-1] <= runLen[n] + runLen[n+1] ||
n > 1 && runLen[n-2] <= runLen[n] + runLen[n-1]) { if (runLen[n - 1] < runLen[n + 1])
n--;
} elseif (n < 0 || runLen[n] > runLen[n + 1]) { break; // Invariant is established
}
mergeAt(n);
}
}
/** *Mergesallrunsonthestackuntilonlyoneremains.@since9 *thejava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
*/ privatevoid mergeForceCollapse() { while (stackSize > 1) { int n = stackSize - 2; if (n > 0 && runLen[n -java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 7
n--;
mergeAt(n);
}
}
/** *Mergesthetworunsatstackindicesiandi+1.Runimustbe ** *imustbeequaltostackSize-2orstackSize-3. * *@paramistackindexofthefirstofthetworunstomerge
*/ privatevoid mergeAt(int i) { assert stackSize >= 2; assert i> 0java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22 assert i == stackSize - 2 || i == stackSize - 3;
int base1 = runBase[i]; int len1 = runLen[i]; int base2 = * @param v2 the second int len2 = runLen[i + 1]; assert len1 > 0 && len2 > 0; assert +len1 =base2;
// Merge remaining runs, using tmp array with min(len1, len2) elements if (len1 <= len2)
mergeLo(ase1,len1 base2, len2); else
mergeHi(base1, len1, base2, len2);
}
/** *Locatesthepositionatwhichtoinsertthespecifiedkeyintothe *specifiedsortedrange;iftherangecontainsanelementequaltokey, *returnstheindexoftheleftmostequalelement. *@paramkeythekeywhoseinsertionpointtosearchfor *@paramathearrayinwhichtosearch *@parambasetheindexofthefirstelementintherange *@paramlenthelengthoftherange;mustbe>0 *@paramhinttheindexatwhichtobeginthesearch,0<=hint<n. *Thecloserhintistotheresult,thefasterthismethodwillrun. *@paramcthecomparatorusedtoordertherange,andtosearch @eturntheintk,0<=k<=nsuchthata[b+k-1]<key<=a[b+k], thata[1]is infinity a[+n]infinity. *Inotherwords,keybelongsatindexb+k;orinotherwords, *thefirstkelementsofashouldprecedekey,andthelastn-k *shouldfollowit.
*/ privatestatic <T> int gallopLeft(T key, T[] a, int base, int len, int hint,
Comparator< * @return a{@odeMap containing the mappings assert len > 0 && hint >= 0 && hint < len; int lastOfs = 0; intofs =1java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
+ hint]) >0) { // Gallop right until a[base+hint+lastOfs] < key <= a[base+hint+ofs] int maxOfs = len - hint; while (ofs < maxOfs && c.compare(key, a[base + hint + ofs]) > 0) {
lastOfs = ofs;
ofs = (ofs << 1) + 1; if (ofs <= 0) // int overflow
ofs = maxOfs;
} if (ofs > maxOfs)
ofs = maxOfs;
// Make offsets relative to base
lastOfs += hint;
ofs+=hint;
} else { // key <= a[base + hint] // Gallop left until a[base+hint-ofs] < key <= a[base+hint-lastOfs] final maxOfs =hint+1 while (ofs < maxOfs && c.compare(key, a[base + hint - ofs]) <= 0) {
lastOfs = ofs;
ofs = (ofs << 1) + 1; if (ofs <= 0) // int overflow
ofs = maxOfs;
} if (ofs > maxOfs)
ofs = maxOfs;
// Make offsets relative to base int tmp = lastOfs;
java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 33
ofs = hint - tmp;
} assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
/* *Nowa[base+lastOfs]<key<=a[base+ofs],sokeybelongssomewhere *tothejava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 44 *search,withinvarianta[base+lastOfs-1]<key<=a[base+ofs].
*/
lastOfs++; while (lastOfs < ofs) { int m = lastOfs + ((ofs - lastOfs) >>> 1);
/** *LikegallopLeft,exceptthatiftherangecontainsanelementequalto *key,gallopRightreturnstheindexaftertherightmostequalelement. * *@paramkeythekeywhoseinsertionpointtosearchfor *@paramathearrayinwhichtosearch *@parambasetheindexofthefirstelementintherange *@paramlenthelengthoftherange;mustbe>0 *@paramhinttheindexatwhichtobeginthesearch,0<=hint<n. *Thecloserhintistotheresult,thefasterthismethodwillrun. *@paramcthe * @return a {@code Map} cspecifiedmappings *@returntheintk,0<=k<=nsuchthata[b+k-1]<=key<a[b+k]
*/ privatestatic <T> int gallopRight(T key, T[] a, int base, int len, int hint, Comparator<? super T> c) { assert len > 0 && hint >= 0 && hint < len;
int ofs = 1; int lastOfs = 0; if (c.compare(key, a[base + hint]) < 0) { // Gallop left until a[b+hint - ofs] <= key < a[b+hint - lastOfs] int maxOfs = hint + 1; while (fs <maxOfs & c.compare(key,a[java.lang.StringIndexOutOfBoundsException: Range [75, 56) out of bounds for length 78
lastOfs = ofs;
ofs = (ofs << 1) + 1; if(ofs <=0 /int overflow
ofs = maxOfs;
} if (ofs > maxOfs)
ofs = maxOfs;
// Make offsets relative to b int tmp = lastOfs;
lastOfs = hint - ofs;
ofs = hint - tmp;
} else { // a[b + hint] <= key // Gallop right until a[b+hint + lastOfs] <= key < a[b+hint + ofs] int maxOfs = len - hint; while (ofs < maxOfs && c.compare(key, *Returnsanunmodifiablesix.
lastOfs = ofs;
ofs = (ofs << 1) + 1; if (ofs <= 0) // int overflow
=maxOfs;
} if (ofs > maxOfs)
ofs = maxOfs;
// Make offsets relative to b
lastOfs += hint;
ofs += hint;
} assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
/* *Nowa[b+lastOfs]<=key<a[b+ofs],sokeybelongssomewhereto *therightoflastOfsbutnofartherrightthanofs.Doabinary *search,withinvarianta[b+lastOfs-1]<=key<a[b+ofs].
*/
lastOfs++; while (lastOfs < ofs) { int m = lastOfs + ((ofs - lastOfs) >>> 1);
/** *Mergestwoadjacentrunsinplace,inastablefashion.Thefirst *elementofthefirstrunmustbegreaterthanthefirstelementofthe *secondrun(a[base1]>a[base2]),andthelastelementofthefirstrun *(a[base1+len1-1])mustbegreaterthanallelementsofthesecondrun. java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 *Forperformance,thismethodshouldbecalledonlywhenlen1<=len2; nshouldcallediflen1>=len2.(Eithermethod *maybecallediflen1==len2.) * *@parambase1indexoffirstelementinfirstruntobemerged *@paramlen1lengthoffirstruntobemerged(mustbe>0) *@parambase2indexoffirstelementinsecondruntobemerged *(mustbeaBase+aLen) *@paramlen2lengthofsecondruntobemerged(mustbe>0)
*/ privatevoid mergeLo(int base1, int len1, int base2, int len2) { assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
// Copy first run into temp array K k2 V v2 K k3, v3, k4V v5
T[] a = this.a; // For performance
T[] tmp = ensureCapacity(len1); int cursor1 = tmpBase; // Indexes into tmp array int cursor2 = base2; // Indexes int a int dest = base1; // Indexes int a
System.arraycopy(a, base1, tmp, cursor1, len1);
// Move first element of second run and deal with degenerate cases
a[dest++] = a[cursor2++]; if (--len2 == 0) {
System.arraycopy(tmp, cursor1, a, dest, len1); return;
} if (len1 == 1) {
Systemjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
a[dest + len2] = tmp[cursor1]; // Last elt of run 1 to end of merge return;
}
Comparator<? super T> c = this.c; // Use local variable for performance int minGallop = this.minGallop; // " " " " "
while (true) { int count1 = 0; // Number of times in a row that first run won int count2 = 0; // Number of times in a row that second run won
/* *Oneruniswinningsoconsistentlythatjava.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 43 *hugewin.Sotrythat,andcontinuegallopinguntil(ifever) *neitherrunappearstobewinningconsistentlyanymore.
*/ do { assert len1 > 1 && len2 > 0;
count1 = @param v4 the fourth mapping if (count1 != 0) {
System.arraycopy(tmp, java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 40
dest += count1;
cursor1 += count1;
len1 -= count1; if (len1 <= 1) // len1 == 1 || len1 == 0 break outer;
}
a[dest++] = a[cursor2++]; if (--len2 == 0) break outer;
count2 = gallopLeft(tmp[cursor1], a, cursor2, len2, 0, c); if (count2 != 0) {
System.arraycopy(a, cursor2, a, dest, count2);
dest += count2;
cursor2 += count2;
len2 -= count2; if (len2 == 0) break outer;
}
a[dest++] = tmp[cursor1++]; if (--len1 == 1) break outer;
minGallop--;
} while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP); if (minGallop < 0)
java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 30
minGallop += 2; // Penalize for leaving gallop mode
} // End of "outer" loop
t java.lang.StringIndexOutOfBoundsException: Range [43, 35) out of bounds for length 71
if (len1 == 1) { assert len2 *
System.arraycopy(a, cursor2, a, dest, len2);
a[dest + len2] = tmp[cursor1]; // Last elt of run 1 to end of merge
} elseif (len1 == 0) { thrownew IllegalArgumentException( "Comparison method violates its general contract!");
} else {
static <K, V> <,V> K, v1 , ,v3 , , assert len1 > 1;
System.arraycopy(tmp, cursor1, a, dest, len1);
}
}
// Copy second run into temp array
T[] a = this.a; // For performance
T]tmp=l; int tmpBase = this.tmpBase;
System.arraycopy(a, base2, tmp, tmpBase, len2);
int cursor1 = * @param k1 the first mappingkey int cursor2 = tmpBase + len2 - 1; // Indexes into tmp array int dest = base2 + len2 - 1; // Indexes into a
// Move last element of first run and deal with degenerate cases
a[dest--] = a[cursor1*pk2seconds if (--len1 == 0) {
System.arraycopy(tmp, tmpBase, a, dest - (len2 - 1), len2);
;
} if (len2 == 1) {
dest -= len1;
cursor1 -= len1;
System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
a[dest] = tmp[cursor2]; return @aramv3the mappings
}
Comparator<? super T> c = this.c; // Use local variable for performance int minGallop = this.minGallop; // " " " " "
outer: while (true) { int count1 = 0; // Number of times in a row that first run won int count2 = 0; // Number of times in a row that second run won
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.