-
Notifications
You must be signed in to change notification settings - Fork 4
/
union.go
51 lines (45 loc) · 1.1 KB
/
union.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
50
51
// Copyright © 2019 Platina Systems, Inc. All rights reserved.
// Use of this source code is governed by the GPL-2 license described in the
// LICENSE file.
package xeth
type DevJoin struct{ Lower, Upper Xid }
type DevQuit struct{ Lower, Upper Xid }
func (lower Xid) join(upper Xid) *DevJoin {
lowerl := LinkOf(lower)
upperl := LinkOf(upper)
if lowerl == nil || upperl == nil {
return nil
}
lowerl.Uppers(upper.List(lowerl.Uppers()))
upperl.Lowers(lower.List(upperl.Lowers()))
return &DevJoin{lower, upper}
}
func (lower Xid) quit(upper Xid) *DevQuit {
lowerl := LinkOf(lower)
upperl := LinkOf(upper)
if lowerl == nil || upperl == nil {
return nil
}
lowerl.Uppers(upper.Delist(lowerl.Uppers()))
upperl.Lowers(lower.Delist(upperl.Lowers()))
return &DevQuit{lower, upper}
}
func (xid Xid) List(xids []Xid) []Xid {
for _, entry := range xids {
if entry == xid {
return xids
}
}
return append(xids, xid)
}
func (xid Xid) Delist(xids []Xid) []Xid {
for i, entry := range xids {
if entry == xid {
n := len(xids) - 1
copy(xids[i:], xids[i+1:])
xids = xids[:n]
break
}
}
return xids
}