omap

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package omap implements a very simple ordered map with just the absolute minimum features for our purpose. It's not very performant of whatever, but it's nice to use and easy to maintain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OrderedMap

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

func New

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

New returns a new ordered map with space for size elements.

func (*OrderedMap[K, V]) Add

func (om *OrderedMap[K, V]) Add(k K, v V) bool

Add returns false if the key exists already, without adding the value.

func (*OrderedMap[K, V]) All

func (om *OrderedMap[K, V]) All() iter.Seq2[K, V]

All returns an iterator that can be used to iterate like over normal maps (with a for range loop).

func (*OrderedMap[K, V]) Build

func (om *OrderedMap[K, V]) Build(k K, v V) *OrderedMap[K, V]

Build adds key k and value v to the ordered map and returns the map itself. This allows elegant building of maps. But no feedback is given when the addition wasn't successful. So this shouldn't be used in production but rather for building test data.

func (*OrderedMap[K, V]) Exists

func (om *OrderedMap[K, V]) Exists(k K) bool

func (*OrderedMap[K, V]) Get

func (om *OrderedMap[K, V]) Get(k K) (V, bool)

func (*OrderedMap[K, V]) Len

func (om *OrderedMap[K, V]) Len() int

Jump to

Keyboard shortcuts

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