MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Sum

Method Sum

internal/utils/counters/item.go:87–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

85}
86
87func (this *Item[T]) Sum() (result T) {
88 if this.lastUpdateTime == 0 {
89 return 0
90 }
91
92 var currentTime = fasttime.Now().Unix()
93 var currentSpanIndex = this.calculateSpanIndex(currentTime)
94
95 if currentTime-this.lastUpdateTime > this.lifeSeconds {
96 return 0
97 } else {
98 var lastSpanIndex = this.calculateSpanIndex(this.lastUpdateTime)
99 var countSpans = len(this.spans)
100 for index := currentSpanIndex + 1; ; index++ {
101 var realIndex = index % countSpans
102 result += this.spans[realIndex]
103 if realIndex == lastSpanIndex {
104 break
105 }
106 }
107 }
108
109 return result
110}
111
112func (this *Item[T]) Reset() {
113 for index := range this.spans {

Callers 4

GetMethod · 0.45
TestItem_IncreaseFunction · 0.45
TestItem_Increase2Function · 0.45
BenchmarkItem_IncreaseFunction · 0.45

Calls 3

calculateSpanIndexMethod · 0.95
NowFunction · 0.92
UnixMethod · 0.80

Tested by 3

TestItem_IncreaseFunction · 0.36
TestItem_Increase2Function · 0.36
BenchmarkItem_IncreaseFunction · 0.36