fixedmap

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2021 License: MIT Imports: 1 Imported by: 1

README

go-fixedmap

This package provides a simple fixed-size hash map in Go. It simply wraps a Go map in a struct that also tracks elements adding by use of a linked list. THIS IS NOT THREADSAFE, wrap in a mutex if you need to, and note that all Get/Put/Remove operations can involve writes.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	Key   interface{}
	Value interface{}
}

Element defines a key-value pair in the FixedMap

type FixedMap

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

FixedMap is map of fixed size, useful as an LRU cache

func New

func New(size int) FixedMap

New returns a newly initialized FixedMap instance

func (*FixedMap) Cap

func (fm *FixedMap) Cap() int

Cap returns the capacity of the FixedMap

func (*FixedMap) Get

func (fm *FixedMap) Get(key interface{}) (interface{}, bool)

Get attempts to fetch a value for given key from the map

func (*FixedMap) Has

func (fm *FixedMap) Has(key interface{}) bool

Has checks if the FixedMap contains supplied key

func (*FixedMap) Iterator

func (fm *FixedMap) Iterator() *Iterator

Iterator returns a new prepared Iterator for this map

func (*FixedMap) Len

func (fm *FixedMap) Len() int

Len returns the length of the FixedMap

func (*FixedMap) PopBack

func (fm *FixedMap) PopBack() *Element

PopBack pops the last element from the map

func (*FixedMap) PopFront

func (fm *FixedMap) PopFront() *Element

PopFront pops the elment at the front of the map

func (*FixedMap) Put

func (fm *FixedMap) Put(key, value interface{}) *Element

Put places a key-value pair in the map, returning an Element if the map size was reached and the LRU pair had to be evicted

func (*FixedMap) Remove

func (fm *FixedMap) Remove(key interface{})

Remove will remove an element from the map with given key

type Iterator

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

Iterator provides an ordered iterator over the Elements in a FixedMap

func (*Iterator) Element

func (i *Iterator) Element() *Element

Element returns the stored next Element from the FixedMap

func (*Iterator) Next

func (i *Iterator) Next() bool

Next attempts to prep the next value in the FixedMap for access returning success as to whether there is another value

Jump to

Keyboard shortcuts

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