newSampleRing creates a new sampleRing. If you do not know the preferred value type yet, use a size of 0 (in which case the provided typ doesn't matter). On the first add, a buffer of size 16 will be allocated with the preferred type being the type of the first added sample.
(delta int64, size int, typ chunkenc.ValueType)
| 305 | // matter). On the first add, a buffer of size 16 will be allocated with the |
| 306 | // preferred type being the type of the first added sample. |
| 307 | func newSampleRing(delta int64, size int, typ chunkenc.ValueType) *sampleRing { |
| 308 | r := &sampleRing{delta: delta} |
| 309 | r.reset() |
| 310 | if size <= 0 { |
| 311 | // Will initialize on first add. |
| 312 | return r |
| 313 | } |
| 314 | switch typ { |
| 315 | case chunkenc.ValFloat: |
| 316 | r.fBuf = make([]fSample, size) |
| 317 | case chunkenc.ValHistogram: |
| 318 | r.hBuf = make([]hSample, size) |
| 319 | case chunkenc.ValFloatHistogram: |
| 320 | r.fhBuf = make([]fhSample, size) |
| 321 | default: |
| 322 | // Do not initialize anything because the 1st sample will be |
| 323 | // added to one of the other bufs anyway. |
| 324 | } |
| 325 | return r |
| 326 | } |
| 327 | |
| 328 | func (r *sampleRing) reset() { |
| 329 | r.l = 0 |
searching dependent graphs…