LCOV - code coverage report
Current view: top level - pebble/internal/manifest - level.go (source / functions) Hit Total Coverage
Test: 2024-01-21 08:16Z 5b092519 - tests only.lcov Lines: 16 17 94.1 %
Date: 2024-01-21 08:16:45 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2020 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 manifest
       6             : 
       7             : import "fmt"
       8             : 
       9             : const (
      10             :         // 3 bits are necessary to represent level values from 0-6.
      11             :         levelBits = 3
      12             :         levelMask = (1 << levelBits) - 1
      13             :         // invalidSublevel denotes an invalid or non-applicable sublevel.
      14             :         invalidSublevel = -1
      15             : )
      16             : 
      17             : // Level encodes a level and optional sublevel for use in log and error
      18             : // messages. The encoding has the property that Level(0) ==
      19             : // L0Sublevel(invalidSublevel).
      20             : type Level uint32
      21             : 
      22           1 : func makeLevel(level, sublevel int) Level {
      23           1 :         return Level(((sublevel + 1) << levelBits) | level)
      24           1 : }
      25             : 
      26             : // LevelToInt returns the int representation of a Level
      27           1 : func LevelToInt(l Level) int {
      28           1 :         return int(l) & levelMask
      29           1 : }
      30             : 
      31             : // L0Sublevel returns a Level representing the specified L0 sublevel.
      32           1 : func L0Sublevel(sublevel int) Level {
      33           1 :         if sublevel < 0 {
      34           0 :                 panic(fmt.Sprintf("invalid L0 sublevel: %d", sublevel))
      35             :         }
      36           1 :         return makeLevel(0, sublevel)
      37             : }
      38             : 
      39           1 : func (l Level) String() string {
      40           1 :         level := int(l) & levelMask
      41           1 :         sublevel := (int(l) >> levelBits) - 1
      42           1 :         if sublevel != invalidSublevel {
      43           1 :                 return fmt.Sprintf("L%d.%d", level, sublevel)
      44           1 :         }
      45           1 :         return fmt.Sprintf("L%d", level)
      46             : }

Generated by: LCOV version 1.14