-
Notifications
You must be signed in to change notification settings - Fork 0
/
clearZero.go
76 lines (65 loc) · 1.58 KB
/
clearZero.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
66
67
68
69
70
71
72
73
74
75
76
package pkg
import (
"fmt"
)
// Deleting zero value from plane
func clearZeroValue(plane map[string][][]int32) (clearPlane map[string][][]int32, err error) {
var (
tmp map[string]map[int]map[int32]int32
)
fmt.Println("Clearing plane from zero value")
tmp, err = makeMapFromPlane(plane)
if err != nil {
return nil, err
}
// fmt.Println(tmp)
clearPlane = make(map[string][][]int32)
for t, p := range tmp {
if len(clearPlane[t]) == 0 {
clearPlane[t] = make([][]int32, len(p))
}
for partition, brokers := range p {
// fmt.Printf("\nTopic: %s - partition: %d\n", t, partition)
if len(clearPlane[t][partition]) == 0 {
clearPlane[t][partition] = make([]int32, len(brokers))
}
for k, b := range brokers {
if b != 0 {
clearPlane[t][partition][k] = b
}
}
}
}
return clearPlane, nil
}
func makeMapFromPlane(plane map[string][][]int32) (mapWithoutThero map[string]map[int]map[int32]int32, err error) {
var (
c int32
)
if len(plane) == 0 {
return nil, fmt.Errorf("plane without values")
}
mapWithoutThero = make(map[string]map[int]map[int32]int32)
for t, p := range plane {
if len(mapWithoutThero[t]) == 0 {
mapWithoutThero[t] = make(map[int]map[int32]int32)
}
if len(p) != 0 {
for partition, brokers := range p {
if len(brokers) != 0 {
c = 0
if len(mapWithoutThero[t][partition]) == 0 {
mapWithoutThero[t][partition] = make(map[int32]int32)
}
for _, b := range brokers {
if b != 0 {
mapWithoutThero[t][partition][c] = b
c++
}
}
}
}
}
}
return mapWithoutThero, nil
}