-
Notifications
You must be signed in to change notification settings - Fork 47
/
types.go
65 lines (55 loc) · 1.47 KB
/
types.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package types
import (
"fmt"
sdkmath "cosmossdk.io/math"
)
type (
Int = sdkmath.Int
Uint = sdkmath.Uint
)
func (f *GlobalVirtualGroupFamily) AppendGVG(gvgID uint32) {
f.GlobalVirtualGroupIds = append(f.GlobalVirtualGroupIds, gvgID)
}
func (f *GlobalVirtualGroupFamily) Contains(gvgID uint32) bool {
for _, id := range f.GlobalVirtualGroupIds {
if id == gvgID {
return true
}
}
return false
}
func (f *GlobalVirtualGroupFamily) RemoveGVG(gvgID uint32) error {
for i, id := range f.GlobalVirtualGroupIds {
if id == gvgID {
f.GlobalVirtualGroupIds = append(f.GlobalVirtualGroupIds[:i], f.GlobalVirtualGroupIds[i+1:]...)
return nil
}
}
return ErrGVGNotExist
}
func (f *GlobalVirtualGroupFamily) MustRemoveGVG(gvgID uint32) {
err := f.RemoveGVG(gvgID)
if err != nil {
panic(fmt.Sprintf("remove gvg from family failed. err: %s", err))
}
}
func (g *GlobalVirtualGroupsBindingOnBucket) AppendGVGAndLVG(gvgID, lvgID uint32) {
g.GlobalVirtualGroupIds = append(g.GlobalVirtualGroupIds, gvgID)
g.LocalVirtualGroupIds = append(g.LocalVirtualGroupIds, lvgID)
}
func (g *GlobalVirtualGroupsBindingOnBucket) GetLVGIDByGVGID(gvgID uint32) uint32 {
for i, gID := range g.GlobalVirtualGroupIds {
if gID == gvgID {
return g.LocalVirtualGroupIds[i]
}
}
return 0
}
func (g *GlobalVirtualGroupsBindingOnBucket) GetGVGIDByLVGID(lvgID uint32) uint32 {
for i, lID := range g.LocalVirtualGroupIds {
if lID == lvgID {
return g.GlobalVirtualGroupIds[i]
}
}
return 0
}