github.com/insolar/vanilla@v0.0.0-20201023172447-248fdf805322/capacity/capacity.go (about)

     1  // Copyright 2020 Insolar Network Ltd.
     2  // All rights reserved.
     3  // This material is licensed under the Insolar License version 1.0,
     4  // available at https://github.com/insolar/assured-ledger/blob/master/LICENSE.md.
     5  
     6  package capacity
     7  
     8  type Level uint8
     9  
    10  const (
    11  	LevelZero Level = iota
    12  	LevelMinimal
    13  	LevelReduced
    14  	LevelNormal
    15  	LevelMax
    16  
    17  	LevelCount = iota
    18  )
    19  
    20  type IntLevels [LevelCount]int
    21  type UintLevels [LevelCount]uint
    22  type Uint8Levels [LevelCount]uint8
    23  type Uint32Levels [LevelCount]uint32
    24  type Float32Levels [LevelCount]float32
    25  
    26  func (v Level) DefaultPercent() int {
    27  	return v.ChooseInt([...]int{0, 20, 60, 80, 100})
    28  }
    29  
    30  func (v Level) ChooseInt(levels IntLevels) int {
    31  	return levels[v]
    32  }
    33  
    34  func (v Level) ChooseUint(levels UintLevels) uint {
    35  	return levels[v]
    36  }
    37  
    38  func (v Level) ChooseUint32(levels Uint32Levels) uint32 {
    39  	return levels[v]
    40  }
    41  
    42  func (v Level) ChooseUint8(levels Uint8Levels) uint8 {
    43  	return levels[v]
    44  }
    45  
    46  func (v Level) ChooseFloat32(levels Float32Levels) float32 {
    47  	return levels[v]
    48  }