X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2Fjalview%2Futil%2FQuickSort.js;h=a8cc65276a379a5456e6b035274336a6e6187bcd;hp=fb8f9348fa4c4534a5ee975a076ad1cba62424df;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=8ffd05b3abe52c0b6b79b011c0966361f82d5fe6 diff --git a/site/j2s/jalview/util/QuickSort.js b/site/j2s/jalview/util/QuickSort.js index fb8f934..a8cc652 100644 --- a/site/j2s/jalview/util/QuickSort.js +++ b/site/j2s/jalview/util/QuickSort.js @@ -1,231 +1,231 @@ -Clazz.declarePackage ("jalview.util"); -Clazz.load (null, "jalview.util.QuickSort", ["java.lang.Float", "java.util.Arrays"], function () { -c$ = Clazz.declareType (jalview.util, "QuickSort"); -c$.sortInt = Clazz.defineMethod (c$, "sortInt", -function (arr, s) { -jalview.util.QuickSort.sortInt (arr, 0, arr.length - 1, s); -}, "~A,~A"); -c$.sortFloatObject = Clazz.defineMethod (c$, "sortFloatObject", -function (arr, s) { -jalview.util.QuickSort.sortFloat (arr, 0, arr.length - 1, s); -}, "~A,~A"); -c$.sortDouble = Clazz.defineMethod (c$, "sortDouble", -function (arr, s) { -jalview.util.QuickSort.sortDouble (arr, 0, arr.length - 1, s); -}, "~A,~A"); -c$.sort = Clazz.defineMethod (c$, "sort", -function (arr, s) { -jalview.util.QuickSort.stringSort (arr, 0, arr.length - 1, s); -}, "~A,~A"); -c$.stringSort = Clazz.defineMethod (c$, "stringSort", - function (arr, p, r, s) { -var q; -if (p < r) { -q = jalview.util.QuickSort.stringPartition (arr, p, r, s); -jalview.util.QuickSort.stringSort (arr, p, q, s); -jalview.util.QuickSort.stringSort (arr, q + 1, r, s); -}}, "~A,~N,~N,~A"); -c$.sortFloat = Clazz.defineMethod (c$, "sortFloat", - function (arr, p, r, s) { -var q; -if (p < r) { -q = jalview.util.QuickSort.partitionFloat (arr, p, r, s); -jalview.util.QuickSort.sortFloat (arr, p, q, s); -jalview.util.QuickSort.sortFloat (arr, q + 1, r, s); -}}, "~A,~N,~N,~A"); -c$.sortInt = Clazz.defineMethod (c$, "sortInt", - function (arr, p, r, s) { -var q; -if (p < r) { -q = jalview.util.QuickSort.partitionInt (arr, p, r, s); -jalview.util.QuickSort.sortInt (arr, p, q, s); -jalview.util.QuickSort.sortInt (arr, q + 1, r, s); -}}, "~A,~N,~N,~A"); -c$.partitionFloat = Clazz.defineMethod (c$, "partitionFloat", - function (arr, p, r, s) { -var x = arr[p]; -var i = p - 1; -var j = r + 1; -while (true) { -do { -j = j - 1; -} while (arr[j] > x); -do { -i = i + 1; -} while (arr[i] < x); -if (i < j) { -var tmp = arr[i]; -arr[i] = arr[j]; -arr[j] = tmp; -var tmp2 = s[i]; -s[i] = s[j]; -s[j] = tmp2; -} else { -return j; -}} -}, "~A,~N,~N,~A"); -c$.partitionInt = Clazz.defineMethod (c$, "partitionInt", - function (arr, p, r, s) { -var x = arr[p]; -var i = p - 1; -var j = r + 1; -while (true) { -do { -j = j - 1; -} while (arr[j] > x); -do { -i = i + 1; -} while (arr[i] < x); -if (i < j) { -var tmp = arr[i]; -arr[i] = arr[j]; -arr[j] = tmp; -var tmp2 = s[i]; -s[i] = s[j]; -s[j] = tmp2; -} else { -return j; -}} -}, "~A,~N,~N,~A"); -c$.stringPartition = Clazz.defineMethod (c$, "stringPartition", - function (arr, p, r, s) { -var x = arr[p]; -var i = p - 1; -var j = r + 1; -while (true) { -do { -j = j - 1; -} while (arr[j].compareTo (x) < 0); -do { -i = i + 1; -} while (arr[i].compareTo (x) > 0); -if (i < j) { -var tmp = arr[i]; -arr[i] = arr[j]; -arr[j] = tmp; -var tmp2 = s[i]; -s[i] = s[j]; -s[j] = tmp2; -} else { -return j; -}} -}, "~A,~N,~N,~A"); -c$.sortFloatChar = Clazz.defineMethod (c$, "sortFloatChar", -function (arr, s) { -var f1 = Clazz.newFloatArray (arr.length, 0); -var s1 = Clazz.newCharArray (s.length, '\0'); -var nextZeroValue = 0; -var nextNonZeroValue = arr.length - 1; -for (var i = 0; i < arr.length; i++) { -var val = arr[i]; -if (val > 0) { -f1[nextNonZeroValue] = val; -s1[nextNonZeroValue] = s[i]; -nextNonZeroValue--; -} else { -f1[nextZeroValue] = val; -s1[nextZeroValue] = s[i]; -nextZeroValue++; -}} -System.arraycopy (f1, 0, arr, 0, nextZeroValue); -System.arraycopy (s1, 0, s, 0, nextZeroValue); -if (nextZeroValue == arr.length) { -return; -}var nonZeroFloats = java.util.Arrays.copyOfRange (f1, nextZeroValue, f1.length); -var nonZeroChars = java.util.Arrays.copyOfRange (s1, nextZeroValue, s1.length); -jalview.util.QuickSort.externalSortFloat (nonZeroFloats, nonZeroChars); -System.arraycopy (nonZeroFloats, 0, arr, nextZeroValue, nonZeroFloats.length); -System.arraycopy (nonZeroChars, 0, s, nextZeroValue, nonZeroChars.length); -}, "~A,~A"); -c$.externalSortFloat = Clazz.defineMethod (c$, "externalSortFloat", - function (arr, s) { -var length = arr.length; -var indices = jalview.util.QuickSort.makeIndexArray (length); -java.util.Arrays.sort (indices, new jalview.util.QuickSort.FloatComparator (arr)); -var sortedFloats = Clazz.newFloatArray (length, 0); -var sortedChars = Clazz.newCharArray (s.length, '\0'); -for (var i = 0; i < length; i++) { -sortedFloats[i] = arr[indices[i]]; -sortedChars[i] = s[indices[i]]; -} -System.arraycopy (sortedFloats, 0, arr, 0, length); -System.arraycopy (sortedChars, 0, s, 0, s.length); -}, "~A,~A"); -c$.makeIndexArray = Clazz.defineMethod (c$, "makeIndexArray", - function (length) { -var indices = new Array (length); -for (var i = 0; i < length; i++) { -indices[i] = new Integer (i); -} -return indices; -}, "~N"); -c$.sortIntChar = Clazz.defineMethod (c$, "sortIntChar", -function (arr, s) { -var f1 = Clazz.newIntArray (arr.length, 0); -var s1 = Clazz.newCharArray (s.length, '\0'); -var nextZeroValue = 0; -var nextNonZeroValue = arr.length - 1; -for (var i = 0; i < arr.length; i++) { -var val = arr[i]; -if (val > 0) { -f1[nextNonZeroValue] = val; -s1[nextNonZeroValue] = s[i]; -nextNonZeroValue--; -} else { -f1[nextZeroValue] = val; -s1[nextZeroValue] = s[i]; -nextZeroValue++; -}} -System.arraycopy (f1, 0, arr, 0, nextZeroValue); -System.arraycopy (s1, 0, s, 0, nextZeroValue); -if (nextZeroValue == arr.length) { -return; -}var nonZeroInts = java.util.Arrays.copyOfRange (f1, nextZeroValue, f1.length); -var nonZeroChars = java.util.Arrays.copyOfRange (s1, nextZeroValue, s1.length); -jalview.util.QuickSort.externalSortInt (nonZeroInts, nonZeroChars); -System.arraycopy (nonZeroInts, 0, arr, nextZeroValue, nonZeroInts.length); -System.arraycopy (nonZeroChars, 0, s, nextZeroValue, nonZeroChars.length); -}, "~A,~A"); -c$.externalSortInt = Clazz.defineMethod (c$, "externalSortInt", - function (arr, s) { -var length = arr.length; -var indices = jalview.util.QuickSort.makeIndexArray (length); -java.util.Arrays.sort (indices, new jalview.util.QuickSort.IntComparator (arr)); -var sortedInts = Clazz.newIntArray (length, 0); -var sortedChars = Clazz.newCharArray (s.length, '\0'); -for (var i = 0; i < length; i++) { -sortedInts[i] = arr[indices[i]]; -sortedChars[i] = s[indices[i]]; -} -System.arraycopy (sortedInts, 0, arr, 0, length); -System.arraycopy (sortedChars, 0, s, 0, s.length); -}, "~A,~A"); -Clazz.pu$h(self.c$); -c$ = Clazz.decorateAsClass (function () { -this.values = null; -Clazz.instantialize (this, arguments); -}, jalview.util.QuickSort, "FloatComparator", null, java.util.Comparator); -Clazz.makeConstructor (c$, -function (a) { -this.values = a; -}, "~A"); -Clazz.overrideMethod (c$, "compare", -function (a, b) { -return Float.compare (this.values[a.intValue ()], this.values[b]); -}, "Integer,Integer"); -c$ = Clazz.p0p (); -Clazz.pu$h(self.c$); -c$ = Clazz.decorateAsClass (function () { -this.values = null; -Clazz.instantialize (this, arguments); -}, jalview.util.QuickSort, "IntComparator", null, java.util.Comparator); -Clazz.makeConstructor (c$, -function (a) { -this.values = a; -}, "~A"); -Clazz.overrideMethod (c$, "compare", -function (a, b) { -return Integer.compare (this.values[a], this.values[b]); -}, "Integer,Integer"); -c$ = Clazz.p0p (); -}); +Clazz.declarePackage ("jalview.util"); +Clazz.load (null, "jalview.util.QuickSort", ["java.lang.Float", "java.util.Arrays"], function () { +c$ = Clazz.declareType (jalview.util, "QuickSort"); +c$.sortInt = Clazz.defineMethod (c$, "sortInt", +function (arr, s) { +jalview.util.QuickSort.sortInt (arr, 0, arr.length - 1, s); +}, "~A,~A"); +c$.sortFloatObject = Clazz.defineMethod (c$, "sortFloatObject", +function (arr, s) { +jalview.util.QuickSort.sortFloat (arr, 0, arr.length - 1, s); +}, "~A,~A"); +c$.sortDouble = Clazz.defineMethod (c$, "sortDouble", +function (arr, s) { +jalview.util.QuickSort.sortDouble (arr, 0, arr.length - 1, s); +}, "~A,~A"); +c$.sort = Clazz.defineMethod (c$, "sort", +function (arr, s) { +jalview.util.QuickSort.stringSort (arr, 0, arr.length - 1, s); +}, "~A,~A"); +c$.stringSort = Clazz.defineMethod (c$, "stringSort", + function (arr, p, r, s) { +var q; +if (p < r) { +q = jalview.util.QuickSort.stringPartition (arr, p, r, s); +jalview.util.QuickSort.stringSort (arr, p, q, s); +jalview.util.QuickSort.stringSort (arr, q + 1, r, s); +}}, "~A,~N,~N,~A"); +c$.sortFloat = Clazz.defineMethod (c$, "sortFloat", + function (arr, p, r, s) { +var q; +if (p < r) { +q = jalview.util.QuickSort.partitionFloat (arr, p, r, s); +jalview.util.QuickSort.sortFloat (arr, p, q, s); +jalview.util.QuickSort.sortFloat (arr, q + 1, r, s); +}}, "~A,~N,~N,~A"); +c$.sortInt = Clazz.defineMethod (c$, "sortInt", + function (arr, p, r, s) { +var q; +if (p < r) { +q = jalview.util.QuickSort.partitionInt (arr, p, r, s); +jalview.util.QuickSort.sortInt (arr, p, q, s); +jalview.util.QuickSort.sortInt (arr, q + 1, r, s); +}}, "~A,~N,~N,~A"); +c$.partitionFloat = Clazz.defineMethod (c$, "partitionFloat", + function (arr, p, r, s) { +var x = arr[p]; +var i = p - 1; +var j = r + 1; +while (true) { +do { +j = j - 1; +} while (arr[j] > x); +do { +i = i + 1; +} while (arr[i] < x); +if (i < j) { +var tmp = arr[i]; +arr[i] = arr[j]; +arr[j] = tmp; +var tmp2 = s[i]; +s[i] = s[j]; +s[j] = tmp2; +} else { +return j; +}} +}, "~A,~N,~N,~A"); +c$.partitionInt = Clazz.defineMethod (c$, "partitionInt", + function (arr, p, r, s) { +var x = arr[p]; +var i = p - 1; +var j = r + 1; +while (true) { +do { +j = j - 1; +} while (arr[j] > x); +do { +i = i + 1; +} while (arr[i] < x); +if (i < j) { +var tmp = arr[i]; +arr[i] = arr[j]; +arr[j] = tmp; +var tmp2 = s[i]; +s[i] = s[j]; +s[j] = tmp2; +} else { +return j; +}} +}, "~A,~N,~N,~A"); +c$.stringPartition = Clazz.defineMethod (c$, "stringPartition", + function (arr, p, r, s) { +var x = arr[p]; +var i = p - 1; +var j = r + 1; +while (true) { +do { +j = j - 1; +} while (arr[j].compareTo (x) < 0); +do { +i = i + 1; +} while (arr[i].compareTo (x) > 0); +if (i < j) { +var tmp = arr[i]; +arr[i] = arr[j]; +arr[j] = tmp; +var tmp2 = s[i]; +s[i] = s[j]; +s[j] = tmp2; +} else { +return j; +}} +}, "~A,~N,~N,~A"); +c$.sortFloatChar = Clazz.defineMethod (c$, "sortFloatChar", +function (arr, s) { +var f1 = Clazz.newFloatArray (arr.length, 0); +var s1 = Clazz.newCharArray (s.length, '\0'); +var nextZeroValue = 0; +var nextNonZeroValue = arr.length - 1; +for (var i = 0; i < arr.length; i++) { +var val = arr[i]; +if (val > 0) { +f1[nextNonZeroValue] = val; +s1[nextNonZeroValue] = s[i]; +nextNonZeroValue--; +} else { +f1[nextZeroValue] = val; +s1[nextZeroValue] = s[i]; +nextZeroValue++; +}} +System.arraycopy (f1, 0, arr, 0, nextZeroValue); +System.arraycopy (s1, 0, s, 0, nextZeroValue); +if (nextZeroValue == arr.length) { +return; +}var nonZeroFloats = java.util.Arrays.copyOfRange (f1, nextZeroValue, f1.length); +var nonZeroChars = java.util.Arrays.copyOfRange (s1, nextZeroValue, s1.length); +jalview.util.QuickSort.externalSortFloat (nonZeroFloats, nonZeroChars); +System.arraycopy (nonZeroFloats, 0, arr, nextZeroValue, nonZeroFloats.length); +System.arraycopy (nonZeroChars, 0, s, nextZeroValue, nonZeroChars.length); +}, "~A,~A"); +c$.externalSortFloat = Clazz.defineMethod (c$, "externalSortFloat", + function (arr, s) { +var length = arr.length; +var indices = jalview.util.QuickSort.makeIndexArray (length); +java.util.Arrays.sort (indices, new jalview.util.QuickSort.FloatComparator (arr)); +var sortedFloats = Clazz.newFloatArray (length, 0); +var sortedChars = Clazz.newCharArray (s.length, '\0'); +for (var i = 0; i < length; i++) { +sortedFloats[i] = arr[indices[i]]; +sortedChars[i] = s[indices[i]]; +} +System.arraycopy (sortedFloats, 0, arr, 0, length); +System.arraycopy (sortedChars, 0, s, 0, s.length); +}, "~A,~A"); +c$.makeIndexArray = Clazz.defineMethod (c$, "makeIndexArray", + function (length) { +var indices = new Array (length); +for (var i = 0; i < length; i++) { +indices[i] = new Integer (i); +} +return indices; +}, "~N"); +c$.sortIntChar = Clazz.defineMethod (c$, "sortIntChar", +function (arr, s) { +var f1 = Clazz.newIntArray (arr.length, 0); +var s1 = Clazz.newCharArray (s.length, '\0'); +var nextZeroValue = 0; +var nextNonZeroValue = arr.length - 1; +for (var i = 0; i < arr.length; i++) { +var val = arr[i]; +if (val > 0) { +f1[nextNonZeroValue] = val; +s1[nextNonZeroValue] = s[i]; +nextNonZeroValue--; +} else { +f1[nextZeroValue] = val; +s1[nextZeroValue] = s[i]; +nextZeroValue++; +}} +System.arraycopy (f1, 0, arr, 0, nextZeroValue); +System.arraycopy (s1, 0, s, 0, nextZeroValue); +if (nextZeroValue == arr.length) { +return; +}var nonZeroInts = java.util.Arrays.copyOfRange (f1, nextZeroValue, f1.length); +var nonZeroChars = java.util.Arrays.copyOfRange (s1, nextZeroValue, s1.length); +jalview.util.QuickSort.externalSortInt (nonZeroInts, nonZeroChars); +System.arraycopy (nonZeroInts, 0, arr, nextZeroValue, nonZeroInts.length); +System.arraycopy (nonZeroChars, 0, s, nextZeroValue, nonZeroChars.length); +}, "~A,~A"); +c$.externalSortInt = Clazz.defineMethod (c$, "externalSortInt", + function (arr, s) { +var length = arr.length; +var indices = jalview.util.QuickSort.makeIndexArray (length); +java.util.Arrays.sort (indices, new jalview.util.QuickSort.IntComparator (arr)); +var sortedInts = Clazz.newIntArray (length, 0); +var sortedChars = Clazz.newCharArray (s.length, '\0'); +for (var i = 0; i < length; i++) { +sortedInts[i] = arr[indices[i]]; +sortedChars[i] = s[indices[i]]; +} +System.arraycopy (sortedInts, 0, arr, 0, length); +System.arraycopy (sortedChars, 0, s, 0, s.length); +}, "~A,~A"); +Clazz.pu$h(self.c$); +c$ = Clazz.decorateAsClass (function () { +this.values = null; +Clazz.instantialize (this, arguments); +}, jalview.util.QuickSort, "FloatComparator", null, java.util.Comparator); +Clazz.makeConstructor (c$, +function (a) { +this.values = a; +}, "~A"); +Clazz.overrideMethod (c$, "compare", +function (a, b) { +return Float.compare (this.values[a.intValue ()], this.values[b]); +}, "Integer,Integer"); +c$ = Clazz.p0p (); +Clazz.pu$h(self.c$); +c$ = Clazz.decorateAsClass (function () { +this.values = null; +Clazz.instantialize (this, arguments); +}, jalview.util.QuickSort, "IntComparator", null, java.util.Comparator); +Clazz.makeConstructor (c$, +function (a) { +this.values = a; +}, "~A"); +Clazz.overrideMethod (c$, "compare", +function (a, b) { +return Integer.compare (this.values[a], this.values[b]); +}, "Integer,Integer"); +c$ = Clazz.p0p (); +});