X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=bin%2Fjalview%2Futil%2FQuickSort.js;h=f8fb52f098866805920ce2396aaa537fe4aa831a;hp=a0960b578528fcd9bf5249c63d0789197b341564;hb=7301a2415adab88038b291fc54caeeb3a5a47a44;hpb=6154cb57a6eac3bb1344b8342495f5bb701ee921 diff --git a/bin/jalview/util/QuickSort.js b/bin/jalview/util/QuickSort.js index a0960b5..f8fb52f 100644 --- a/bin/jalview/util/QuickSort.js +++ b/bin/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", -($fz = 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); -}}, $fz.isPrivate = true, $fz), "~A,~N,~N,~A"); -c$.sortFloat = Clazz.defineMethod (c$, "sortFloat", -($fz = 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); -}}, $fz.isPrivate = true, $fz), "~A,~N,~N,~A"); -c$.sortInt = Clazz.defineMethod (c$, "sortInt", -($fz = 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); -}}, $fz.isPrivate = true, $fz), "~A,~N,~N,~A"); -c$.partitionFloat = Clazz.defineMethod (c$, "partitionFloat", -($fz = 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; -}} -}, $fz.isPrivate = true, $fz), "~A,~N,~N,~A"); -c$.partitionInt = Clazz.defineMethod (c$, "partitionInt", -($fz = 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; -}} -}, $fz.isPrivate = true, $fz), "~A,~N,~N,~A"); -c$.stringPartition = Clazz.defineMethod (c$, "stringPartition", -($fz = 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; -}} -}, $fz.isPrivate = true, $fz), "~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", -($fz = 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); -}, $fz.isPrivate = true, $fz), "~A,~A"); -c$.makeIndexArray = Clazz.defineMethod (c$, "makeIndexArray", -($fz = function (length) { -var indices = new Array (length); -for (var i = 0; i < length; i++) { -indices[i] = new Integer (i); -} -return indices; -}, $fz.isPrivate = true, $fz), "~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", -($fz = 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); -}, $fz.isPrivate = true, $fz), "~A,~A"); -Clazz.pu$h (); -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 (); -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", +($fz = 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); +}}, $fz.isPrivate = true, $fz), "~A,~N,~N,~A"); +c$.sortFloat = Clazz.defineMethod (c$, "sortFloat", +($fz = 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); +}}, $fz.isPrivate = true, $fz), "~A,~N,~N,~A"); +c$.sortInt = Clazz.defineMethod (c$, "sortInt", +($fz = 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); +}}, $fz.isPrivate = true, $fz), "~A,~N,~N,~A"); +c$.partitionFloat = Clazz.defineMethod (c$, "partitionFloat", +($fz = 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; +}} +}, $fz.isPrivate = true, $fz), "~A,~N,~N,~A"); +c$.partitionInt = Clazz.defineMethod (c$, "partitionInt", +($fz = 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; +}} +}, $fz.isPrivate = true, $fz), "~A,~N,~N,~A"); +c$.stringPartition = Clazz.defineMethod (c$, "stringPartition", +($fz = 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; +}} +}, $fz.isPrivate = true, $fz), "~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", +($fz = 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); +}, $fz.isPrivate = true, $fz), "~A,~A"); +c$.makeIndexArray = Clazz.defineMethod (c$, "makeIndexArray", +($fz = function (length) { +var indices = new Array (length); +for (var i = 0; i < length; i++) { +indices[i] = new Integer (i); +} +return indices; +}, $fz.isPrivate = true, $fz), "~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", +($fz = 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); +}, $fz.isPrivate = true, $fz), "~A,~A"); +Clazz.pu$h (); +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 (); +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 (); +});