hashs

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package hashs 多种哈希.

包括 SipHash32, SipHash64, SipHash128. HyperLogLog++.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SipHash128

func SipHash128(data []byte) (uint64, uint64)

SipHash128 哈希.

Example
package main

import (
	"fmt"

	"github.com/xuender/oils/hashs"
)

func main() {
	fmt.Println(hashs.SipHash128([]byte("123")))

}
Output:

8693645449139915215 11618447955228391416

func SipHash32

func SipHash32(data []byte) uint32

SipHash32 32位哈希.

func SipHash64

func SipHash64(data []byte) uint64

SipHash64 哈希,和Google Guava的sipHash24相同.

Example
package main

import (
	"fmt"

	"github.com/xuender/oils/hashs"
)

func main() {
	fmt.Println(hashs.SipHash64([]byte("123")))

}
Output:

9379172312344772015

func SipHashHex

func SipHashHex(data []byte) string

SipHashHex 字符串.

Example
package main

import (
	"fmt"

	"github.com/xuender/oils/hashs"
)

func main() {
	fmt.Println(hashs.SipHashHex([]byte("123")))
}
Output:

822983866c7d3daf

func SipHashNumber

func SipHashNumber(data []byte) uint64

SipHashNumber 兼容JS, 53位长度.

Example
package main

import (
	"fmt"

	"github.com/xuender/oils/hashs"
)

func main() {
	fmt.Println(hashs.SipHashNumber([]byte("123")))
}
Output:

2677888159399343

Types

type NumHLLPP

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

import (
	"fmt"

	"github.com/xuender/oils/hashs"
)

func main() {
	hll := hashs.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