Documentation ¶
Index ¶
- Variables
- func RemoveAllGroup()
- func RemoveGroup(groupName string)
- func Restore(data []byte) error
- func Serialize() ([]byte, error)
- type CHash
- func (c *CHash) CreateGroup(groupName string, replicas int) (*Group, error)
- func (c *CHash) Delete(groupName string, key string) error
- func (c *CHash) GetGroup(groupName string) (*Group, error)
- func (c *CHash) Insert(groupName string, key string, payload []byte) error
- func (c *CHash) Match(groupName string, key string) (string, []byte, error)
- func (c *CHash) RemoveAllGroup()
- func (c *CHash) RemoveGroup(groupName string)
- func (c *CHash) Restore(data []byte) error
- func (c *CHash) Serialize() ([]byte, error)
- type Circle
- type Element
- type Group
Constants ¶
This section is empty.
Variables ¶
var ( ErrGroupNotFound = err{Code: 10000, Msg: "group not found"} ErrGroupExisted = err{Code: 10001, Msg: "group already existed"} ErrNoResultMatched = err{Code: 10002, Msg: "no result matched"} ErrKeyExisted = err{Code: 10003, Msg: "key already existed"} )
Several global variables that represent common errors that may be returned by the CHash functions.
Functions ¶
func RemoveAllGroup ¶ added in v1.0.8
func RemoveAllGroup()
RemoveAllGroup removes all groups from the CHash instance.
func RemoveGroup ¶ added in v1.0.3
func RemoveGroup(groupName string)
RemoveGroup removes the specified group from the CHash instance.
Types ¶
type CHash ¶
CHash a warpper of Consistent hashing
func (*CHash) CreateGroup ¶ added in v1.0.3
CreateGroup creates a new group with the given name and the number of replicas
func (*CHash) RemoveAllGroup ¶ added in v1.0.7
func (c *CHash) RemoveAllGroup()
RemoveAllGroup removes all groups
func (*CHash) RemoveGroup ¶ added in v1.0.3
RemoveGroup removes a group by name
type Circle ¶ added in v1.0.4
type Circle []uint32
func (Circle) Less ¶ added in v1.0.4
Less compares the elements at positions i and j in the slice and returns true if the element at position i is less than the element at position j.
func (Circle) Match ¶ added in v1.0.4
Match returns the index of the element in the slice that is closest to target. If target is greater than all elements in the slice, it returns the last index; if target is less than all elements in the slice, it returns the last index.
func (Circle) Search ¶ added in v1.0.4
Search searches for the index of target in the sorted slice. It returns the index and true if target is found, or 0 and false otherwise.
type Group ¶ added in v1.0.3
type Group struct { sync.RWMutex Name string `json:"name"` NumberOfReplicas int `json:"numberOfReplicas"` Elements map[string]*Element `json:"elements"` // contains filtered or unexported fields }
Group represents a group of elements to be stored in the cache
func CreateGroup ¶ added in v1.0.3
CreateGroup creates a new group in the CHash instance and returns a pointer to the Group object. If the group already exists, it returns an error.
func NewGroup ¶ added in v1.0.3
NewGroup creates a new cache group with the given name and number of replicas
func (*Group) GetElements ¶ added in v1.0.5
GetElements get all elements from the group
func (*Group) Init ¶ added in v1.0.3
func (b *Group) Init()
Init initializes the group's elements, circle, and rows maps