/** * Returns the index of the median of the three indexed chars. */ private static int med3(short x[], int a, int b, int c, ShortComparator comp) { int ab = comp.compare(x[a],x[b]); int ac = comp.compare(x[a],x[c]); int bc = comp.compare(x[b],x[c]); return (ab<0 ? (bc<0 ? b : ac<0 ? c : a) : (bc>0 ? b : ac>0 ? c : a)); }
/** * Returns the index of the median of the three indexed chars. */ private static int med3(short x[], int a, int b, int c, ShortComparator comp) { int ab = comp.compare(x[a], x[b]); int ac = comp.compare(x[a], x[c]); int bc = comp.compare(x[b], x[c]); return (ab < 0 ? (bc < 0 ? b : ac < 0 ? c : a) : (bc > 0 ? b : ac > 0 ? c : a)); }
/** * Returns the index of the median of the three indexed chars. */ private static int med3(short x[], int a, int b, int c, ShortComparator comp) { int ab = comp.compare(x[a],x[b]); int ac = comp.compare(x[a],x[c]); int bc = comp.compare(x[b],x[c]); return (ab<0 ? (bc<0 ? b : ac<0 ? c : a) : (bc>0 ? b : ac>0 ? c : a)); }
private static void mergeSort1(short src[], short dest[], int low, int high, ShortComparator c) { int length = high - low; // Insertion sort on smallest arrays if (length < SMALL) { for (int i = low; i < high; i++) for (int j = i; j > low && c.compare(dest[j - 1], dest[j]) > 0; j--) swap(dest, j, j - 1); return; } // Recursively sort halves of dest into src int mid = (low + high) / 2; mergeSort1(dest, src, low, mid, c); mergeSort1(dest, src, mid, high, c); // If list is already sorted, just copy from src to dest. This is an // optimization that results in faster sorts for nearly ordered lists. if (c.compare(src[mid - 1], src[mid]) <= 0) { System.arraycopy(src, low, dest, low, length); return; } // Merge sorted halves (now in src) into dest for (int i = low, p = low, q = mid; i < high; i++) { if (q >= high || p < mid && c.compare(src[p], src[q]) <= 0) dest[i] = src[p++]; else dest[i] = src[q++]; } }
for (int j=i; j>off && comp.compare(x[j-1],x[j])>0; j--) swap(x, j, j-1); return; while(true) { int comparison; while (b <= c && (comparison=comp.compare(x[b],v))<=0) { if (comparison == 0) swap(x, a++, b); b++; while (c >= b && (comparison=comp.compare(x[c],v))>=0) { if (comparison == 0) swap(x, c, d--);
for (int j=i; j>off && comp.compare(x[j-1],x[j])>0; j--) swap(x, j, j-1); return; while(true) { int comparison; while (b <= c && (comparison=comp.compare(x[b],v))<=0) { if (comparison == 0) swap(x, a++, b); b++; while (c >= b && (comparison=comp.compare(x[c],v))>=0) { if (comparison == 0) swap(x, c, d--);
for (int j = i; j > off && comp.compare(x[j - 1], x[j]) > 0; j--) swap(x, j, j - 1); return; while (true) { int comparison; while (b <= c && (comparison = comp.compare(x[b], v)) <= 0) { if (comparison == 0) swap(x, a++, b); b++; while (c >= b && (comparison = comp.compare(x[c], v)) >= 0) { if (comparison == 0) swap(x, c, d--);