MCPcopy
hub / github.com/prometheus/prometheus / addH

Function addH

storage/buffer.go:659–701  ·  view source on GitHub ↗

addH adds an hSample to a (specialized) hSample buffer.

(s hSample, buf []hSample, r *sampleRing)

Source from the content-addressed store, hash-verified

657
658// addH adds an hSample to a (specialized) hSample buffer.
659func addH(s hSample, buf []hSample, r *sampleRing) []hSample {
660 l := len(buf)
661 // Grow the ring buffer if it fits no more elements.
662 if l == 0 {
663 buf = make([]hSample, 16)
664 l = 16
665 }
666 if l == r.l {
667 newBuf := make([]hSample, 2*l)
668 copy(newBuf[l+r.f:], buf[r.f:])
669 copy(newBuf, buf[:r.f])
670
671 buf = newBuf
672 r.i = r.f
673 r.f += l
674 l = 2 * l
675 } else {
676 r.i++
677 if r.i >= l {
678 r.i -= l
679 }
680 }
681
682 buf[r.i].t = s.t
683 buf[r.i].st = s.st
684 if buf[r.i].h == nil {
685 buf[r.i].h = s.h.Copy()
686 } else {
687 s.h.CopyTo(buf[r.i].h)
688 }
689 r.l++
690
691 // Free head of the buffer of samples that just fell out of the range.
692 tmin := s.T() - r.delta
693 for buf[r.f].T() < tmin {
694 r.f++
695 if r.f >= l {
696 r.f -= l
697 }
698 r.l--
699 }
700 return buf
701}
702
703// addFH adds an fhSample to a (specialized) fhSample buffer.
704func addFH(s fhSample, buf []fhSample, r *sampleRing) []fhSample {

Callers 2

addMethod · 0.85
addHMethod · 0.85

Calls 3

CopyMethod · 0.65
TMethod · 0.65
CopyToMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…