counts

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2021 License: MIT Imports: 2 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Binary = Humaner{
	// contains filtered or unexported fields
}

Binary is a Humaner representing power-of-1024 based prefixes, typically used for bytes.

View Source
var Metric = Humaner{
	// contains filtered or unexported fields
}

Metric is a Humaner representing metric prefixes.

Functions

This section is empty.

Types

type Count32

type Count32 uint32

Count32 is a count of something, capped at math.MaxUint32.

func NewCount32

func NewCount32(n uint64) Count32

NewCount32 initializes a Count32 from a uint64, capped at math.MaxUint32.

func (*Count32) AdjustMaxIfNecessary

func (n1 *Count32) AdjustMaxIfNecessary(n2 Count32) bool

AdjustMaxIfNecessary adjusts `*n1` to be `max(*n1, n2)`. Return true iff `n2` was greater than `*n1`.

func (*Count32) AdjustMaxIfPossible

func (n1 *Count32) AdjustMaxIfPossible(n2 Count32) bool

AdjustMaxIfPossible adjusts `*n1` to be `max(*n1, n2)`. Return true iff `n2` was greater than or equal to `*n1`.

func (*Count32) Increment

func (n1 *Count32) Increment(n2 Count32)

Increment increases `*n1` by `n2`, capped at math.MaxUint32.

func (Count32) Plus

func (n1 Count32) Plus(n2 Count32) Count32

Plus returns the sum of two Count32s, capped at math.MaxUint32.

func (Count32) ToUint64

func (n Count32) ToUint64() (uint64, bool)

ToUint64 returns the value of `n` as a `uint64`. If the value has overflowed, it returns `(math.MaxUint32, true)`.

type Count64

type Count64 uint64

Count64 is a count of something, capped at math.MaxUint64.

func NewCount64

func NewCount64(n uint64) Count64

NewCount64 initializes a Count64 from a uint64.

func (*Count64) AdjustMaxIfNecessary

func (n1 *Count64) AdjustMaxIfNecessary(n2 Count64) bool

AdjustMaxIfNecessary adjusts `*n1` to be `max(*n1, n2)`. Return true iff `n2` was greater than `*n1`.

func (*Count64) AdjustMaxIfPossible

func (n1 *Count64) AdjustMaxIfPossible(n2 Count64) bool

AdjustMaxIfPossible adjusts `*n1` to be `max(*n1, n2)`. Return true iff `n2` was greater than or equal to `*n1`.

func (*Count64) Increment

func (n1 *Count64) Increment(n2 Count64)

Increment increases `*n1` by `n2`, capped at math.MaxUint64.

func (Count64) Plus

func (n1 Count64) Plus(n2 Count64) Count64

Plus returns the sum of two Count64s, capped at math.MaxUint64.

func (Count64) ToUint64

func (n Count64) ToUint64() (uint64, bool)

ToUint64 returns the value of `n` as a `uint64`. If the value has overflowed, it returns `(math.MaxUint64, true)`.

type Humanable added in v1.3.0

type Humanable interface {
	// ToUint64 returns the value as a uint64, and a boolean telling
	// whether it overflowed.
	ToUint64() (uint64, bool)
}

Humanable is a quantity that can be made human-readable using `Humaner.Format()`.

type Humaner

type Humaner struct {
	// contains filtered or unexported fields
}

Humaner is an object that can format a Humanable in human-readable format.

func (*Humaner) Format added in v1.3.0

func (h *Humaner) Format(value Humanable, unit string) (numeral string, unitString string)

Format formats values, aligned, in `len(unit) + 10` or fewer characters (except for extremely large numbers). It returns strings representing the numeral and the unit string.

func (*Humaner) FormatNumber added in v1.3.0

func (h *Humaner) FormatNumber(n uint64, unit string) (numeral string, unitString string)

FormatNumber formats n, aligned, in `len(unit) + 10` or fewer characters (except for extremely large numbers). It returns strings representing the numeral and the unit string.

func (*Humaner) Name added in v1.3.0

func (h *Humaner) Name() string

Name returns the name of `h` ("metric" or "binary").

type Prefix

type Prefix struct {
	Name       string
	Multiplier uint64
}

Prefix is a metric-like prefix that implies a scaling factor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL