https://github.com/gorros/medianonstream
Calculates median on stream with limited memory.
https://github.com/gorros/medianonstream
Last synced: about 2 months ago
JSON representation
Calculates median on stream with limited memory.
- Host: GitHub
- URL: https://github.com/gorros/medianonstream
- Owner: gorros
- Created: 2016-11-14T13:28:34.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-14T14:13:35.000Z (over 9 years ago)
- Last Synced: 2025-01-18T16:57:04.074Z (over 1 year ago)
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Median on stream
Calculates median on stream with limited memory.
Default buffer size is 1000. It should be at least twice large than
standard deviation of the sequence.
## Example
```golang
a := []float64{1,2,5.6,6,10,12,35,45,2,5,7,4.6,0}
mos := medianonstream.NewMedianOnStream(30)
for i := 0; i < len(a); i++ {
mos.Insert(a[i])
fmt.Printf("Added %6.3f, current median is %3.3f\n", a[i], mos.GetMedian())
}
```
Output
```
Added 1.000, current median is 1.000
Added 2.000, current median is 1.500
Added 5.600, current median is 2.000
Added 6.000, current median is 3.800
Added 10.000, current median is 5.600
Added 12.000, current median is 5.800
Added 35.000, current median is 6.000
Added 45.000, current median is 8.000
Added 2.000, current median is 6.000
Added 5.000, current median is 5.800
Added 7.000, current median is 6.000
Added 4.600, current median is 5.800
Added 0.000, current median is 5.600
```
###Notice
The original version was written in Java by @shunanya