forked from go-distributed/epaxos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependencies.go
47 lines (41 loc) · 816 Bytes
/
dependencies.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
package message
type Dependencies []uint64
// union unions the deps into the receiver
// return true if deps are changed
func (d Dependencies) Union(other Dependencies) bool {
if d == nil || other == nil {
panic("Union: dependencis should not be nil")
}
if len(d) != len(other) {
panic("Union: size different!")
}
same := true
for i := range d {
if d[i] != other[i] {
same = false
if d[i] < other[i] {
d[i] = other[i]
}
}
}
return same
}
func (d Dependencies) Clone() Dependencies {
if d == nil {
return nil
}
deps := make(Dependencies, len(d))
copy(deps, d)
return deps
}
func (d Dependencies) SameAs(other Dependencies) bool {
if len(d) != len(other) {
panic("Same: different size!")
}
for i := range d {
if d[i] != other[i] {
return false
}
}
return true
}