public boolean iterate(Double o, int n) {
      boolean ascending = getAscending();
      state.n = n;
      if (o != null) {
        boolean doInsert = state.a.size() < n;
        if (!doInsert) {
          Double last = state.a.get(state.a.size()-1);
          if (ascending) {
            doInsert = o < last; 
          } else {
            doInsert = o > last;
          }
        }
        if (doInsert) {
          binaryInsert(state.a, o, ascending);   
          if (state.a.size() > n) {
            state.a.remove(state.a.size()-1);
          }
        }
      }
      return true;
    }
Iterate through one row of original data.
This function will update the internal max/min buffer if the internal buffer is not full,
or the new row is larger/smaller than the current max/min n.
contrib/src/java/org/apache/hadoop/hive/contrib/udaf/example/UDAFExampleMaxMinNUtil.java