Add data structure

This commit is contained in:
Ivan Danyliuk 2017-12-16 12:54:21 +01:00
parent 851c8fa426
commit c7c7d29ebe
No known key found for this signature in database
GPG Key ID: 97ED33CE024E1DBF
1 changed files with 26 additions and 0 deletions

26
data.go Normal file
View File

@ -0,0 +1,26 @@
package main
// Should be enough for wide-screen terminals
const HistoryLimit = 1024
// Data holds actual data values, being a buffer for
// UI widges and responsible for flushing/updating/deleting
// old values.
type Data struct {
cpu *CircularBuffer
}
// NewData inits new data object.
func NewData() *Data {
return &Data{
cpu: NewCircularBuffer(HistoryLimit),
}
}
func (d *Data) AddCPUValue(value float64) {
d.cpu.Add(value)
}
func (d *Data) CPU(n int) []float64 {
return d.cpu.Data()
}