getEntriesForXValue method

  1. @override
List<T> getEntriesForXValue (
  1. double xValue
)
override

Implementation

@override
List<T> getEntriesForXValue(double xValue) {
  List<T> entries = List<T>();

  int low = 0;
  int high = _values.length - 1;

  while (low <= high) {
    int m = (high + low) ~/ 2;
    T entry = _values[m];

    // if we have a match
    if (xValue == entry.x) {
      while (m > 0 && _values[m - 1].x == xValue) m--;

      high = _values.length;

      // loop over all "equal" entries
      for (; m < high; m++) {
        entry = _values[m];
        if (entry.x == xValue) {
          entries.add(entry);
        } else {
          break;
        }
      }

      break;
    } else {
      if (xValue > entry.x)
        low = m + 1;
      else
        high = m - 1;
    }
  }

  return entries;
}