arraymap

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayMap

type ArrayMap[K Ordered, V any] struct {
	// contains filtered or unexported fields
}

An ArrayMap is an ordered map. It balances CPU cache-efficiency and insert/update/delete performance by storing entries in contiguous chunked arrays.

func New

func New[K Ordered, V any](chunkSize int) *ArrayMap[K, V]

Create a new ArrayMap with a given chunk size. The chunk size is a tuning parameter to adjust the tradeoff between cache-efficiency and insert/delete performance.

func (*ArrayMap[K, V]) Delete

func (m *ArrayMap[K, V]) Delete(k K) bool

Delete an entry from the array map. Returns false if the key does not exist in the map.

func (*ArrayMap[K, V]) First

func (m *ArrayMap[K, V]) First() (Entry[K, V], bool)

First returns the first element in the array map. If the map is empty, it returns false in the bool flag.

func (*ArrayMap[K, V]) Get

func (m *ArrayMap[K, V]) Get(k K) (V, bool)

Get a value with a given key from the ArrayMap. If the key does not exist in the map, it returns the empty entry and false.

func (*ArrayMap[K, V]) Insert

func (m *ArrayMap[K, V]) Insert(k K, v V)

Insert or update an entry in the ArrayMap.

func (*ArrayMap[K, V]) Iter

func (m *ArrayMap[K, V]) Iter() *IterMap[K, V]

Iter returns an IterMap object which may be used iterate over the map in sorted order.

func (*ArrayMap[K, V]) Len

func (m *ArrayMap[K, V]) Len() int

Len returns the number of entries in the map.

type Entry

type Entry[K Ordered, V any] struct {
	Key   K
	Value V
}

Entry stores a key-value pair in an ArrayMap.

type IterMap

type IterMap[K Ordered, V any] struct {
	// contains filtered or unexported fields
}

func (*IterMap[K, V]) Collect

func (it *IterMap[K, V]) Collect() []Entry[K, V]

Collect exhausts the map iterator, collecting all entries in a slice.

func (*IterMap[K, V]) Next

func (it *IterMap[K, V]) Next() (Entry[K, V], bool)

Returns the next entry in the map iterator. Returns the empty entry and false if the iterator after it reaches the end of the map.

type Ordered

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64 |
		~string
}

Jump to

Keyboard shortcuts

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