-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.go
49 lines (39 loc) · 1.06 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package ghord
import (
"bytes"
"math/rand"
)
// calculate offset, id + 2^(exp-1) mod 2^m
//func powerOffset(id []byte, exp int) int {
//}
// Calculate a random number between n, and m
func randRange(min, max int64) int64 {
return rand.Int63n(max-min) + min
}
// Checks if key is between id1 and id2 exclusivly
func between(id1, id2, key NodeID) bool {
return bytes.Compare(key, id1) == 1 &&
bytes.Compare(key, id2) == -1
}
// Checks if key E (id1, id2]
func betweenRightInc(id1, id2, key NodeID) bool {
return (bytes.Compare(key, id1) == 1 &&
bytes.Compare(key, id2) == -1) ||
bytes.Equal(key, id2)
}
// Checks if key E [id1, id2)
func betweenLeftInc(id1, id2, key NodeID) bool {
return (bytes.Compare(key, id1) == 1 &&
bytes.Compare(key, id2) == -1) ||
bytes.Equal(key, id1)
}
// Cluster logging //
func (c *Cluster) debug(format string, v ...interface{}) {
c.log.Debug(format, v...)
}
func (c *Cluster) warn(format string, v ...interface{}) {
c.log.Warning(format, v...)
}
func (c *Cluster) err(format string, v ...interface{}) {
c.log.Error(format, v...)
}