Skip to content

sharat910/timeheap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timeheap

A golang package to store and retrieve sorted timestamped objects.

Example usage: cmd/example

It exposes the following public APIs

// New creates a timeheap with the initial capacity
func New(capacity int) *TimeHeap

// Peek returns a copy of oldest element (in Time)
// If the heap is empty, returns ErrHeapEmpty
// Time complexity: O(1)
func (h *TimeHeap) Peek() (Timestamped, error) 

// Pop extracts and returns oldest element (in Time)
// If the heap is empty, returns ErrHeapEmpty
// Time complexity: O(log(n))
func (h *TimeHeap) Pop() (Timestamped, error)

// Push inserts a new element into the heap
// Time complexity: O(log(n)) in the worst case,
//                  O(1) (amortized) if objects are generally moving forward in Time
func (h *TimeHeap) Push(item Timestamped)

About

Keeps timestamped elements sorted in Golang

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages