code: private double findGamma(double[] C, double d)
      {
          if(it == null )
              it = new IndexTable(C);
          else
              it.sort(C);//few will change from iteration to iteration, Java's TimSort should be able to exploit this 
          
          double sum = 0;
          double max;
          double finalScore = 0, prevScore = 0;
          
          int i;
          for(i = 0; i < it.length(); i++)
          {
              max = C[it.index(i)];
              sum += max;
              
              double score = max*i-sum;
              prevScore = finalScore;
              finalScore = (d-max*i+sum)/i+max;
              
              if(score >= d)
                  break;
          }
          
          return prevScore;
      }
docs: TODO add bias version of findGamma