Documentation ¶
Index ¶
- Variables
- func Any2Int(data interface{}) int
- func ContainsEnglish(str string) bool
- func ContainsEnglishAndNumber(str string) bool
- func DataDecoder(data []byte, obj interface{}) error
- func DataEncoder(obj interface{}) ([]byte, error)
- func FileExists(name string) bool
- func GzipCompress(src []byte) []byte
- func GzipDecompress(src []byte) ([]byte, error)
- func Mkdir(term string)
- func StrDuplicates(a []string) []string
- type Consistent
- func (c *Consistent) Add(elt string)
- func (c *Consistent) Get(name string) (string, error)
- func (c *Consistent) GetN(name string, n int) ([]string, error)
- func (c *Consistent) GetTwo(name string) (string, string, error)
- func (c *Consistent) Members() []string
- func (c *Consistent) Remove(elt string)
- func (c *Consistent) Set(elts []string)
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyCircle = fmt.Errorf("empty circle")
ErrEmptyCircle is the error returned when trying to get an element when nothing has been added to hash.
Functions ¶
func ContainsEnglish ¶
func DataEncoder ¶
DataEncoder 数据量大,使用 json 序列化+gzip压缩
func FileExists ¶
func StrDuplicates ¶
Types ¶
type Consistent ¶
type Consistent struct { NumberOfReplicas int UseFnv bool sync.RWMutex // contains filtered or unexported fields }
Consistent holds the information about the members of the consistent hash circle.
func NewConsistent ¶
func NewConsistent() *Consistent
NewConsistent creates a new Consistent object with a default setting of 20 replicas for each entry.
To change the number of replicas, set NumberOfReplicas before adding entries.
func (*Consistent) Add ¶
func (c *Consistent) Add(elt string)
Add inserts a string element in the consistent hash.
func (*Consistent) Get ¶
func (c *Consistent) Get(name string) (string, error)
Get returns an element close to where name hashes to in the circle.
func (*Consistent) GetN ¶
func (c *Consistent) GetN(name string, n int) ([]string, error)
GetN returns the N closest distinct elements to the name input in the circle.
func (*Consistent) GetTwo ¶
func (c *Consistent) GetTwo(name string) (string, string, error)
GetTwo returns the two closest distinct elements to the name input in the circle.
func (*Consistent) Members ¶
func (c *Consistent) Members() []string
func (*Consistent) Remove ¶
func (c *Consistent) Remove(elt string)
Remove removes an element from the hash.
func (*Consistent) Set ¶
func (c *Consistent) Set(elts []string)
Set sets all the elements in the hash. If there are existing elements not present in elts, they will be removed.