time-sorted-list: github.com/go-zen-chu/time-sorted-list Index | Files

package timesortedlist

import "github.com/go-zen-chu/time-sorted-list"

Package timesortedlist is a package of a data structure storing time series data. It's goal is to store data such as logs, sequence, ... that should be ordered.

Feature

- in memory time series data store
- any data sorted in time series
- query data using from or until in unixtime

Usage

Here is a simple usage.

Add item

When you add item, this list will automatically sort.

tsl.AddItem(unixTime, timeItem)

Searching data through unixtime

Since this data structure intented to store time series data, it has abilty to search item via unix time.

timeItems := tsl.GetItemsFrom(unixTime)
timeItems := tsl.GetItemsUntil(unixTime)

Index

Package Files

list.go

type ITimeSortedList Uses

type ITimeSortedList interface {
    Len() int
    Cap() int
    AddItem(unixTime int64, item interface{})
    AddTimeItem(item *TimeItem)
    Filled() bool
    GetItem(idx int) *TimeItem
    GetItemsFrom(fromUnixTime int64) []TimeItem
    GetItemsUntil(untilUnixTime int64) []TimeItem
    GetItemsFromUntil(fromUnixTime, untilUnixTime int64) []TimeItem
}

ITimeSortedList is a interface of TimeSortedList. Use for mocking in your test.

func NewTimeSortedList Uses

func NewTimeSortedList(capacity int) ITimeSortedList

NewTimeSortedList initializes TimeSortedList. capacity is the max size of internal slice for not using more memory.

type TimeItem Uses

type TimeItem struct {
    UnixTime int64
    Item     interface{}
}

TimeItem is a struct for storing item with time infomation.

type TimeSortedList Uses

type TimeSortedList struct {
    // contains filtered or unexported fields
}

TimeSortedList holds time series items which are sorted. Inserted items can be obtained by specifying unix time.

func (*TimeSortedList) AddItem Uses

func (tsl *TimeSortedList) AddItem(unixTime int64, item interface{})

AddItem adds any structure with specified time.

func (*TimeSortedList) AddTimeItem Uses

func (tsl *TimeSortedList) AddTimeItem(item *TimeItem)

AddTimeItem adds TimeItem with time ordered.

func (*TimeSortedList) Cap Uses

func (tsl *TimeSortedList) Cap() int

Cap gets initialized capacity. If length of list is same as Cap then the list is filled.

func (*TimeSortedList) Filled Uses

func (tsl *TimeSortedList) Filled() bool

Filled checks if the list is filled.

func (*TimeSortedList) GetItem Uses

func (tsl *TimeSortedList) GetItem(idx int) *TimeItem

GetItem gets item with specified index.

func (*TimeSortedList) GetItemsFrom Uses

func (tsl *TimeSortedList) GetItemsFrom(fromUnixTime int64) []TimeItem

GetItemsFrom gets item from specified time

func (*TimeSortedList) GetItemsFromUntil Uses

func (tsl *TimeSortedList) GetItemsFromUntil(fromUnixTime, untilUnixTime int64) []TimeItem

GetItemsFromUntil get items with specified time range

func (*TimeSortedList) GetItemsUntil Uses

func (tsl *TimeSortedList) GetItemsUntil(untilUnixTime int64) []TimeItem

GetItemsUntil gets item until specified time

func (*TimeSortedList) Len Uses

func (tsl *TimeSortedList) Len() int

Len gets actual length of list.

Package timesortedlist imports 1 packages (graph). Updated 2019-03-23. Refresh now. Tools for package owners.