initial import

This commit is contained in:
kevin
2020-07-26 17:09:05 +08:00
commit 7e3a369a8f
647 changed files with 54754 additions and 0 deletions

39
rq/hashchange.go Normal file
View File

@@ -0,0 +1,39 @@
package rq
import (
"math/rand"
"zero/core/hash"
)
type HashChange struct {
id int64
oldHash *hash.ConsistentHash
newHash *hash.ConsistentHash
}
func NewHashChange(oldHash, newHash *hash.ConsistentHash) HashChange {
return HashChange{
id: rand.Int63(),
oldHash: oldHash,
newHash: newHash,
}
}
func (hc HashChange) GetId() int64 {
return hc.id
}
func (hc HashChange) ShallEvict(key interface{}) bool {
oldTarget, oldOk := hc.oldHash.Get(key)
if !oldOk {
return false
}
newTarget, newOk := hc.newHash.Get(key)
if !newOk {
return false
}
return oldTarget != newTarget
}