MCPcopy Index your code
hub / github.com/RobinUS2/golang-moving-average

github.com/RobinUS2/golang-moving-average @v1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.0 ↗ · + Follow
30 symbols 109 edges 3 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

golang-moving-average

Moving average implementation for Go. View the documentation.

Usage

import "github.com/RobinUS2/golang-moving-average"

ma := movingaverage.New(5) // 5 is the window size
ma.Add(10)
ma.Add(15)
ma.Add(20)
ma.Add(1)
ma.Add(1)
ma.Add(5) // This one will effectively overwrite the first value (10 in this example)
avg := ma.Avg() // Will return 8.4

Concurrency

By default the library is not thread safe. It is however possible to wrap the object in a thread safe manner that can be used concurrently from many routines:

ma := movingaverage.Concurrent(movingaverage.New(5)) // concurrent safe version
ma.Add(10)
avg := ma.Avg() // Will return 10.0

Min/Max/Count

Basic operations are possible:

ma := movingaverage.New(5) // 5 is the window size
min, err := ma.Min() // min will return lowest value, error is set if there's no values yet
max, err := ma.Max() // max will return highest value, error is set if there's no values yet
count := ma.Count() // count will return number of filled slots

Partially used windows

In case you define a window of let's say 5 and only put in 2 values, the average will be based on those 2 values.

Window 5 - Values: 2, 2 - Average: 2 (not 0.8)

Core symbols most depended-on inside this repo

Shape

Method 17
Function 11
Struct 2

Languages

Go100%

Modules by API surface

ma.go12 symbols
ma_test.go9 symbols
ma_concurrent.go9 symbols

For agents

$ claude mcp add golang-moving-average \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page