remap

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 6 Imported by: 1

README

remap用来对某些健值进行分组映射的工具函数包

在使用Map的时候,有时为了提高效率,会用一组Map来对外呈现出一个Map的行为。 举例来说,如果将用户的信息放置在一个Map中,这个Map往往会比较大,不论是在对Map本身操作,还是在涉及到操作锁相关的情况。 这种大的Map效率都不如将Map进行分组。假如我们将Map分成73组,那在进行Map操作的时候需要先对Key进行一次运算,让此Key 能够基于某种规则被映射成一个整数,再对此整数进行取模后,将其映射到对应的具体Map上。

remap

这个包的功能就是提供这样的映射工具函数,在syncx/semap包和cache包中都会用到这些函数。事实上,这些函数除了可以在对Map进行分组时使用, 也可以对别的资源进行分组时使用,例如如果有一组工作go routine专门处理一些事务,将一个具体的工作或事务分配到某一个工作go routine(工作线程)时, 也可以使用类似的分组方式。

特别说明

在对Map相关的分组测试后,对Map或Map为入口的并发控制,分组效率比不分组提升1倍以上。但由于本身Map操作和加解锁的过程耗时很低, 实际上对系统效率的提升不是太显著。不分组的Map耗时可能在500ns,分组的Map耗时在200ns左右,虽然效率提升,但因为基数低,也就是提示了 300ns左右的时间。在大部分时候,使用不分组和分组都行,如果要追求极致的高性能,分组是不错的选择。

Documentation

Index

Constants

View Source
const (
	//DefaultPrime 缺省使用73 -- 致敬谢耳朵最喜欢的素数
	DefaultPrime uint64 = 73
)

Variables

This section is empty.

Functions

func SearchUInt64s

func SearchUInt64s(a []uint64, x uint64) int

SearchUInt64s search uint64 array index

func ToBytes

func ToBytes(i interface{}) []byte

ToBytes : convert interface to []byte

func XXHash

func XXHash(i interface{}) uint64

XXHash : use xxhash hash interface

Types

type Bs

type Bs interface {
	//ToBytes convert self to bytes
	ToBytes() []byte
}

Bs an interface can convert self to bytes

type HitGroup

type HitGroup interface {
	//Hit convert self to a specific uint64 value
	Hit() uint64
}

HitGroup an interface can convert self to a fixed uint64 which can target a group id

type Option

type Option func(o *_Option)

Option : option function

func WithPrime

func WithPrime(prime uint64) Option

WithPrime : setup prime number

type ReMap

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

ReMap remap meta info

func NewReMap

func NewReMap(opts ...Option) *ReMap

NewReMap : new remap instance

func (*ReMap) Numbs

func (r *ReMap) Numbs() uint64

Numbs 获取切分份数

func (*ReMap) SearchIndex

func (r *ReMap) SearchIndex(x uint64) int

SearchIndex search uint64 index

func (*ReMap) SimpleIndex

func (r *ReMap) SimpleIndex(i interface{}) int

SimpleIndex figure simple index

func (*ReMap) XHashIndex

func (r *ReMap) XHashIndex(i interface{}) int

XHashIndex figure xhash index

Jump to

Keyboard shortcuts

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