omap

package
v0.0.0-...-ff4d34b Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package omap implements an efficient key-ordered map.

Keys and values may be of any type, but all keys must be comparable using the less than function that is passed in to the omap.New() function, or the less than function provided by the omap.New*() construction functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

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

Map is a key-ordered map. The zero value is an invalid map! Use one of the construction functions (e.g., New()), to create a map for a specific key type.

func New

func New(less func(interface{}, interface{}) bool) *Map

New returns an empty Map that uses the given less than function to compare keys. For example:

type Point { X, Y int }
pointMap := omap.New(func(a, b interface{}) bool {
        α, β := a.(Point), b.(Point)
        if α.X != β.X {
            return α.X < β.X
        }
        return α.Y < β.Y
    })

func NewCaseFoldedKeyed

func NewCaseFoldedKeyed() *Map

NewCaseFoldedKeyed returns an empty Map that accepts case-insensitive string keys.

func NewFloat64Keyed

func NewFloat64Keyed() *Map

NewFloat64Keyed returns an empty Map that accepts float64 keys.

func NewIntKeyed

func NewIntKeyed() *Map

NewIntKeyed returns an empty Map that accepts int keys.

func NewStringKeyed

func NewStringKeyed() *Map

NewStringKeyed returns an empty Map that accepts case-sensitive string keys.

func (*Map) Delete

func (m *Map) Delete(key interface{}) (deleted bool)

Delete deletes the key-value with the given key from the Map and returns true, or does nothing and returns false if there is no key-value with the given key. For example:

deleted := myMap.Delete(key).

func (*Map) Do

func (m *Map) Do(function func(interface{}, interface{}))

Do calls the given function on every key-value in the Map in order.

func (*Map) Find

func (m *Map) Find(key interface{}) (value interface{}, found bool)

Find returns the value and true if the key is in the Map or nil and false otherwise. For example:

value, found := myMap.Find(key).

func (*Map) Insert

func (m *Map) Insert(key, value interface{}) (inserted bool)

Insert inserts a new key-value into the Map and returns true; or replaces an existing key-value pair's value if the keys are equal and returns false. For example:

inserted := myMap.Insert(key, value).

func (*Map) Len

func (m *Map) Len() int

Len returns the number of key-value pairs in the map.

Jump to

Keyboard shortcuts

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