get method

Bytes? get(
  1. Uint8List key
)

Reads key, or null when absent, deleted, or shadowed by a tombstone.

Views returned from a segment point into the segment's buffer; views from the memtable point into the arena. Both stay valid until the next flush.

Implementation

Bytes? get(Uint8List key) {
  _checkOpen();
  final transaction = _txOps;
  if (transaction != null) {
    final pending = transaction[String.fromCharCodes(key)];
    if (pending != null) {
      if (pending.kind == WalOpKind.delete) return null;
      final bytes = pending.value!;
      return Bytes.view(bytes, 0, bytes.length);
    }
  }
  final ref = _memtable.get(key);
  if (ref != null) {
    return ref.length < 0
        ? null
        : _arena.view(ref.chunk, ref.offset, ref.length);
  }
  for (var i = _segments.length - 1; i >= 0; i--) {
    final hit = _segments[i].lookup(key);
    if (hit == null) continue;
    return hit.tombstone ? null : hit.document?.toBytes();
  }
  return null;
}