Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/caneroj1/median-stream
Haskell data structure for constant-time queries for the median of a stream of numeric data
https://github.com/caneroj1/median-stream
data-structures heap max-heap numeric-data stream
Last synced: 29 days ago
JSON representation
Haskell data structure for constant-time queries for the median of a stream of numeric data
- Host: GitHub
- URL: https://github.com/caneroj1/median-stream
- Owner: caneroj1
- License: bsd-3-clause
- Created: 2016-10-21T00:59:45.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-04-18T13:08:05.000Z (over 3 years ago)
- Last Synced: 2024-04-25T16:02:52.282Z (9 months ago)
- Topics: data-structures, heap, max-heap, numeric-data, stream
- Language: Haskell
- Size: 15.6 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# median-stream
Hackage
[![Build Status](https://travis-ci.org/caneroj1/median-stream.svg?branch=master)](https://travis-ci.org/caneroj1/median-stream)
Haskell data structure for constant-time queries for the median of a stream of numeric data, where insertion into the stream occurs in O(nlgn). ```median-stream``` uses two heaps (a max-heap and a min-heap) to enable constant time access to the median. If there is an even number of elements in the stream, then the median is the average of the head of the two heaps. If there is an odd number, the median is the head of the max heap.## Usage
```haskell
Data.MedianStream> let medianStream = empty +> 1 +> 3 +> 4 +> 2
Data.MedianStream> median medianStream
Just 2.5
Data.MedianStream> let medianStream2 = medianStream +> 0 +> (-1) +> 10
Data.MedianStream> median medianStream2
Just 2.0
```