void quickSort(int a[], int lo0, int hi0, int longDimMask) {
   // Based on the QuickSort method by James Gosling from Sun's SortDemo applet

      int lo = lo0;
      int hi = hi0;
      int mid, t;

      if ( hi0 > lo0) {
         mid = a[ ( lo0 + hi0 ) / 2 ] & longDimMask;
         while( lo <= hi ) {
            while( ( lo < hi0 ) && ( (a[lo] & longDimMask) < mid ) )
               ++lo;
            while( ( hi > lo0 ) && ( (a[hi] & longDimMask) > mid ) )
               --hi;
            if( lo <= hi ) {
              t = a[lo];
              a[lo] = a[hi];
              a[hi] = t;

              t = counts[lo];
              counts[lo] = counts[hi];
              counts[hi] = t;

               ++lo;
               --hi;
            }
         }
         if( lo0 < hi )
            quickSort( a, lo0, hi, longDimMask);
         if( lo < hi0 )
            quickSort( a, lo, hi0, longDimMask);
      }
   }