1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
Files
go-mixed/ketama/ketama.go
2023-08-25 15:31:00 +08:00

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
}