expiry

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

type Heap struct {
	Data []*Node
	// contains filtered or unexported fields
}

@Min Heap

func Init

func Init() *Heap

func (*Heap) Extract

func (h *Heap) Extract() (*Node, error)

Extract function retrives the root node by swapping root node with the last node and removing it from the last index Last node is then heapifyed Down

func (*Heap) Insert

func (h *Heap) Insert(key string, expiry int64) *Node

Takes a key and expiry > 0, Node is added in the last index MinheapifyUp func is runned to swap the child node to parent node if the exoiry is less than the parent node

func (*Heap) Remove

func (h *Heap) Remove(nindex, lindex int)

Remove takes node Index(index of the node to be removed) and the last index in the heap, changes the node.Index value then swaps them. Finally minHeapifyDown is called to make it a valid MinHeap

type Node

type Node struct {
	Index  int
	Key    string
	Expiry int64
}

Jump to

Keyboard shortcuts

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