-
Notifications
You must be signed in to change notification settings - Fork 4
/
stats.go
29 lines (24 loc) · 1.01 KB
/
stats.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
package deepdiff
// Stats holds statistical metadata about a diff
type Stats struct {
Left int `json:"leftNodes"` // count of nodes in the left tree
Right int `json:"rightNodes"` // count of nodes in the right tree
LeftWeight int `json:"leftWeight"` // byte-ish count of left tree
RightWeight int `json:"rightWeight"` // byte-ish count of right tree
Inserts int `json:"inserts,omitempty"` // number of nodes inserted
Updates int `json:"updates,omitempty"` // number of nodes updated
Deletes int `json:"deletes,omitempty"` // number of nodes deleted
}
// NodeChange returns a count of the shift between left & right trees
func (s Stats) NodeChange() int {
return s.Right - s.Left
}
// PctWeightChange returns a value from -1.0 to max(float64) representing the size shift
// between left & right trees
func (s Stats) PctWeightChange() float64 {
if s.RightWeight == 0 {
// TODO (b5): better handle this unlikely scenario that may arise from misuse
return 0
}
return float64(s.LeftWeight) / float64(s.RightWeight)
}