go_heap

package module
v0.0.0-...-d786ec8 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

go_heap

package main

import (
	"container/heap"
	"fmt"

	"github.com/sun-moon-star-star/go_heap"
)

func main() {
	h := go_heap.New(func(i, j interface{}) bool {
		return i.(int) > j.(int)
	})

	heap.Init(h)

	heap.Push(h, 3)
	heap.Push(h, 1)
	heap.Push(h, 2)
	heap.Push(h, 9)

	len := h.Len()

	element := heap.Pop(h)

	elementInt := element.(int)

	fmt.Println(len, elementInt) // 4, 9
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetGlobalDelayQueue

func SetGlobalDelayQueue(queue *DelayQueue) error

Types

type DelayQueue

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

func GlobalDelayQueue

func GlobalDelayQueue() *DelayQueue

func NewDelayQueue

func NewDelayQueue() *DelayQueue

func (*DelayQueue) Begin

func (queue *DelayQueue) Begin()

func (*DelayQueue) End

func (queue *DelayQueue) End()

func (*DelayQueue) EndNow

func (queue *DelayQueue) EndNow()

func (*DelayQueue) Join

func (queue *DelayQueue) Join()

func (*DelayQueue) Len

func (queue *DelayQueue) Len() int

func (*DelayQueue) Push

func (queue *DelayQueue) Push(item *Task)

func (*DelayQueue) PushPeriodTask

func (queue *DelayQueue) PushPeriodTask(item *Task, period string) error

func (*DelayQueue) Run

func (queue *DelayQueue) Run()

func (*DelayQueue) SetMaxLen

func (queue *DelayQueue) SetMaxLen(maxLen int)

func (*DelayQueue) Top

func (queue *DelayQueue) Top() (*Task, bool)

func (*DelayQueue) TryPush

func (queue *DelayQueue) TryPush(item *Task) bool

func (*DelayQueue) TryPushPeriodTask

func (queue *DelayQueue) TryPushPeriodTask(item *Task, period string) (error, bool)

type Heap

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

func New

func New(priority func(i, j interface{}) bool) *Heap

func (*Heap) Len

func (h *Heap) Len() int

func (*Heap) Pop

func (h *Heap) Pop() (interface{}, bool)

func (*Heap) Push

func (h *Heap) Push(v interface{})

func (*Heap) Top

func (h *Heap) Top() (interface{}, bool)

type HeapBase

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

func NewHeapBase

func NewHeapBase(priority func(i, j interface{}) bool) *HeapBase

func (*HeapBase) Len

func (heap *HeapBase) Len() int

func (*HeapBase) Less

func (heap *HeapBase) Less(i, j int) bool

func (*HeapBase) Pop

func (heap *HeapBase) Pop() (v interface{})

func (*HeapBase) Push

func (heap *HeapBase) Push(v interface{})

func (*HeapBase) Swap

func (heap *HeapBase) Swap(i, j int)

func (*HeapBase) Top

func (heap *HeapBase) Top() (interface{}, bool)

type PeriodTask

type PeriodTask struct {
	Queue    *DelayQueue
	Schedule cron.Schedule

	RawData     interface{}
	RawCallBack func(interface{})
	Period      string
}

func (*PeriodTask) GetNextRunUnixNano

func (t *PeriodTask) GetNextRunUnixNano() int64

type SyncHeap

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

func NewSyncHeap

func NewSyncHeap(priority func(i, j interface{}) bool) *SyncHeap

func (*SyncHeap) Join

func (syncHeap *SyncHeap) Join()

func (*SyncHeap) Len

func (syncHeap *SyncHeap) Len() int

func (*SyncHeap) Push

func (syncHeap *SyncHeap) Push(item interface{})

func (*SyncHeap) Remove

func (syncHeap *SyncHeap) Remove() (interface{}, bool)

func (*SyncHeap) SetMaxLen

func (syncHeap *SyncHeap) SetMaxLen(maxLen int)

func (*SyncHeap) TaskDone

func (syncHeap *SyncHeap) TaskDone()

func (*SyncHeap) Top

func (syncHeap *SyncHeap) Top() (interface{}, bool)

func (*SyncHeap) TryPush

func (syncHeap *SyncHeap) TryPush(item interface{}) bool

func (*SyncHeap) TryRemove

func (syncHeap *SyncHeap) TryRemove() (interface{}, bool)

type Task

type Task struct {
	RunUnixNano int64
	Data        interface{}
	CallBack    func(interface{})
}

func GetPeriodTask

func GetPeriodTask(queue *DelayQueue, period string, task *Task) (*Task, error)

Jump to

Keyboard shortcuts

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