forEachRange method

void forEachRange(
  1. Uint8List? lower,
  2. Uint8List? upper,
  3. void visit(
    1. Uint8List key,
    2. int chunk,
    3. int offset,
    4. int length,
    ), {
  4. bool includeLower = true,
  5. bool includeUpper = false,
})

Visits entries whose key is in [lower, upper) in ascending key order.

Seeks with the skip list, so a narrow range costs O(log n + k) instead of scanning the whole memtable.

Implementation

void forEachRange(
  Uint8List? lower,
  Uint8List? upper,
  void Function(Uint8List key, int chunk, int offset, int length) visit, {
  bool includeLower = true,
  bool includeUpper = false,
}) {
  var index = _firstAtOrAfter(lower);
  while (index >= 0) {
    final key = keyAt(index);
    if (lower != null &&
        !includeLower &&
        _compareKeyToEntry(lower, index) == 0) {
      index = _levels[0][index];
      continue;
    }
    if (upper != null) {
      final comparison = _compareKeyToEntry(upper, index);
      if (comparison > 0 || (comparison == 0 && !includeUpper)) break;
    }
    visit(
      key,
      _valueChunks[index],
      _valueOffsets[index],
      _valueLengths[index],
    );
    index = _levels[0][index];
  }
}