fifo

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 2 Imported by: 1

README

fifo

Go Reference CI Coverage Go Report Card

Thread safe GoLang fixed size FIFO with O(1) Get.

Example

import (
	"fmt"

	"github.com/floatdrop/fifo"
)

func main() {
	cache := fifo.New[string, int](256)

	cache.Push("Hello", 5)

	if e := cache.Get("Hello"); e != nil {
		fmt.Println(*e)
		// Output: 5
	}
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Evicted

type Evicted[K comparable, V any] struct {
	Key   K
	Value V
}

type FIFO

type FIFO[K comparable, V any] struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"

	"github.com/floatdrop/fifo"
)

func main() {
	queue := fifo.New[string, int](256)

	queue.Push("Hello", 5)

	if e := queue.Get("Hello"); e != nil {
		fmt.Println(*e)

	}
}
Output:
5

func New

func New[K comparable, V any](size int) *FIFO[K, V]

func (*FIFO[K, V]) Get

func (L *FIFO[K, V]) Get(key K) *V

func (*FIFO[K, V]) Len

func (L *FIFO[K, V]) Len() int

func (*FIFO[K, V]) Push

func (L *FIFO[K, V]) Push(key K, value V) *Evicted[K, V]

func (*FIFO[K, V]) Remove

func (L *FIFO[K, V]) Remove(key K) *V

func (*FIFO[K, V]) Victim added in v0.2.0

func (L *FIFO[K, V]) Victim() *K

Jump to

Keyboard shortcuts

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