LCOV - code coverage report
Current view: top level - pebble/internal/rangedel - rangedel.go (source / functions) Hit Total Coverage
Test: 2023-12-13 08:15Z 556b4e0e - tests + meta.lcov Lines: 18 22 81.8 %
Date: 2023-12-13 08:16:53 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2022 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 rangedel
       6             : 
       7             : import (
       8             :         "github.com/cockroachdb/pebble/internal/base"
       9             :         "github.com/cockroachdb/pebble/internal/keyspan"
      10             : )
      11             : 
      12             : // Encode takes a Span containing only range deletions. It invokes the provided
      13             : // closure with the encoded internal keys that represent the Span's state. The
      14             : // keys and values passed to emit are only valid until the closure returns.  If
      15             : // emit returns an error, Encode stops and returns the error.
      16           2 : func Encode(s *keyspan.Span, emit func(k base.InternalKey, v []byte) error) error {
      17           2 :         for _, k := range s.Keys {
      18           2 :                 if k.Kind() != base.InternalKeyKindRangeDelete {
      19           0 :                         return base.CorruptionErrorf("pebble: rangedel.Encode cannot encode %s key", k.Kind())
      20           0 :                 }
      21           2 :                 ik := base.InternalKey{
      22           2 :                         UserKey: s.Start,
      23           2 :                         Trailer: k.Trailer,
      24           2 :                 }
      25           2 :                 if err := emit(ik, s.End); err != nil {
      26           0 :                         return err
      27           0 :                 }
      28             :         }
      29           2 :         return nil
      30             : }
      31             : 
      32             : // Decode takes an internal key pair encoding a range deletion and returns a
      33             : // decoded keyspan containing the key. If keysDst is provided, the key will be
      34             : // appended to keysDst, avoiding an allocation.
      35           2 : func Decode(ik base.InternalKey, v []byte, keysDst []keyspan.Key) keyspan.Span {
      36           2 :         return keyspan.Span{
      37           2 :                 Start: ik.UserKey,
      38           2 :                 End:   v,
      39           2 :                 Keys: append(keysDst, keyspan.Key{
      40           2 :                         Trailer: ik.Trailer,
      41           2 :                 }),
      42           2 :         }
      43           2 : }

Generated by: LCOV version 1.14