util

package
v0.0.0-...-96e313d Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TangCachePrefix = "TangCache"
)

Variables

View Source
var ErrCacheLoadFailed = errors.New("cache hit, but load value error")
View Source
var ErrCacheUnmarshal = errors.New("cache hit, but unmarshal error")
View Source
var PrimaryCacheHit = errors.New("primary cache hit")
View Source
var SearchCacheHit = errors.New("search cache hit")

Functions

func ContainString

func ContainString(target string, slice []string) bool

func EstimateParameters

func EstimateParameters(n uint, p float64) (int64, int64)

EstimateParameters 根据单位个数和错误率估算所需内存和哈希函数数量 Input: n: number of items, p: the err_rate Output: m: the total Size(bit), k: the hash function number. https://krisives.github.io/bloom-calculator/

func GenInstanceId

func GenInstanceId() string

func GenPrimaryCacheKey

func GenPrimaryCacheKey(instanceId string, tableName string, primaryKey string) string

func GenPrimaryCachePrefix

func GenPrimaryCachePrefix(instanceId string, tableName string) string

func GenSearchCacheKey

func GenSearchCacheKey(instanceId string, tableName string, sql string, values ...interface{}) string

func GenSearchCachePrefix

func GenSearchCachePrefix(instanceId string, tableName string) string

func RandFloat64

func RandFloat64() float64

RandFloat64 生成一个0.95到1.05的数字

func Set

func Set(offset []int64) error

func ShouldCache

func ShouldCache(tableName string, tables []string) bool

Types

type BitSetProvider

type BitSetProvider interface {
	Set([]int64) error
	Test([]int64) (bool, error)
}

type BloomFilter

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

func New

func New(m int64, k int64, bitSet BitSetProvider) *BloomFilter

func (*BloomFilter) Add

func (f *BloomFilter) Add(data []byte) error

func (*BloomFilter) Exists

func (f *BloomFilter) Exists(data []byte) (bool, error)

type Pair

type Pair struct {
	Key   string
	Value interface{}
}

Jump to

Keyboard shortcuts

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