mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-17 16:12:42 +08:00
39 lines
571 B
Go
39 lines
571 B
Go
package ketama
|
|
|
|
import (
|
|
"github.com/charlienet/go-mixed/locker"
|
|
"github.com/charlienet/go-mixed/maps"
|
|
)
|
|
|
|
type Ketama struct {
|
|
mu locker.WithRWLocker
|
|
replicas int
|
|
m maps.Map[uint64, string]
|
|
}
|
|
|
|
func New() *Ketama {
|
|
return &Ketama{
|
|
m: maps.NewHashMap[uint64, string](),
|
|
}
|
|
}
|
|
|
|
func (k *Ketama) Synchronize() {
|
|
k.mu.Synchronize()
|
|
}
|
|
|
|
func (k *Ketama) Add(nodes ...string) {
|
|
k.mu.Lock()
|
|
defer k.mu.Unlock()
|
|
|
|
for _, node := range nodes {
|
|
_ = node
|
|
}
|
|
}
|
|
|
|
func (k *Ketama) IsEmpty() bool {
|
|
k.mu.RLock()
|
|
defer k.mu.RUnlock()
|
|
|
|
return k.m.Count() == 0
|
|
}
|