bounded

package
v1.5.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item interface {
	// Key is used for map index operations.
	Key() string
	// Less is used for heap sorting operations.
	Less(Item) bool
	// SetIndex is called by heap implementations to set the Item heap index.
	SetIndex(int)
	// Index returns the index of this Item.
	Index() int
}

Item describes a type accepted by the mapped heap implementation.

type MappedHeap

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

MappedHeap is a combination of map and heap structures which allows for efficient sorting, uniqueness guarantees, and constant time lookups. Implements heap.Interface.

func NewMappedHeap

func NewMappedHeap() *MappedHeap

func (MappedHeap) Contains

func (mh MappedHeap) Contains(key string) (int, bool)

func (MappedHeap) Len

func (mh MappedHeap) Len() int

func (MappedHeap) Less

func (mh MappedHeap) Less(i, j int) bool

func (*MappedHeap) Pop

func (mh *MappedHeap) Pop() interface{}

func (*MappedHeap) Push

func (mh *MappedHeap) Push(x interface{})

func (*MappedHeap) Swap

func (mh *MappedHeap) Swap(i, j int)

type TimedItem

type TimedItem struct {
	Name string
	Time time.Time
	// contains filtered or unexported fields
}

TimedItem implements Item for a string: time.Time tuple.

func (*TimedItem) Index

func (t *TimedItem) Index() int

func (*TimedItem) Key

func (t *TimedItem) Key() string

func (*TimedItem) Less

func (t *TimedItem) Less(o Item) bool

func (*TimedItem) SetIndex

func (t *TimedItem) SetIndex(i int)

type TimedSet

type TimedSet struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewTimedSet

func NewTimedSet(c int) *TimedSet

func (*TimedSet) Pop

func (ts *TimedSet) Pop(key string) time.Duration

Pop returns the elapsed duration since the passed key was first registered, or -1 if it is not found.

func (*TimedSet) Push

func (ts *TimedSet) Push(key string)

Push registers the passed key and saves the timestamp it is first registered. If the key is already registered, does not overwrite the saved timestamp.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL