counter

package
v1.0.50 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Number2Bytes

func Number2Bytes[T constraints.Integer | constraints.Float](num T) []byte

Types

type Counter

type Counter[T comparable] struct {
	// contains filtered or unexported fields
}

Counter 计数器.

func NewCounter

func NewCounter[T comparable]() *Counter[T]

NewCounter 新建计数器.

func (*Counter[T]) Add

func (p *Counter[T]) Add(key T, num int64) int64

Add 增加key的值num.

func (*Counter[T]) Clean

func (p *Counter[T]) Clean()

Clean 清空.

func (*Counter[T]) Dec

func (p *Counter[T]) Dec(key T) int64

Dec 自减key.

func (*Counter[T]) Get

func (p *Counter[T]) Get(key T) int64

Get 获取key的计数.

func (*Counter[T]) Inc

func (p *Counter[T]) Inc(key T) int64

Inc 自增key.

func (*Counter[T]) Keys

func (p *Counter[T]) Keys() []T

Keys 键值.

func (*Counter[T]) Size

func (p *Counter[T]) Size() int

Size 键值数量.

func (*Counter[T]) Sum

func (p *Counter[T]) Sum() int64

Sum 计数总量.

type NumHLLPP

type NumHLLPP[T constraints.Integer | constraints.Float] struct {
	Hllpp *hllpp.HLLPP
}
Example
package main

import (
	"fmt"

	"github.com/xuender/kit/counter"
)

func main() {
	hll := counter.NewNumHLLPP[int]()
	hll.Add(3)
	hll.Add(3)
	hll.Add(1)
	hll.Add(3)

	fmt.Println(hll.Count())

}
Output:

2

func NewNumHLLPP

func NewNumHLLPP[T constraints.Integer | constraints.Float]() *NumHLLPP[T]

func Unmarshal

func Unmarshal[T constraints.Integer | constraints.Float](data []byte) (*NumHLLPP[T], error)

nolint

func (*NumHLLPP[T]) Add

func (p *NumHLLPP[T]) Add(num T)

func (*NumHLLPP[T]) Count

func (p *NumHLLPP[T]) Count() uint64

func (*NumHLLPP[T]) Marshal

func (p *NumHLLPP[T]) Marshal() []byte

Jump to

Keyboard shortcuts

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