Line data Source code
1 : // Copyright 2018 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 : // of this source code is governed by a BSD-style license that can be found in 3 : // the LICENSE file. 4 : 5 : package keyspan 6 : 7 : import "github.com/cockroachdb/pebble/internal/base" 8 : 9 : // SeekLE seeks to the span that contains or is before the target key. If an 10 : // error occurs while seeking iter, a nil span and non-nil error is returned. 11 2 : func SeekLE(cmp base.Compare, iter FragmentIterator, key []byte) (*Span, error) { 12 2 : // Seek to the smallest span that contains a key ≥ key. If some span 13 2 : // contains the key `key`, SeekGE will return it. 14 2 : iterSpan, err := iter.SeekGE(key) 15 2 : if err != nil { 16 1 : return nil, err 17 1 : } 18 2 : if iterSpan != nil && cmp(key, iterSpan.Start) >= 0 { 19 2 : return iterSpan, nil 20 2 : } 21 : // No span covers exactly `key`. Step backwards to move onto the largest 22 : // span < key. 23 2 : return iter.Prev() 24 : }