immutable

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: ISC Imports: 3 Imported by: 0

README

Immutable datastructures for Golang

DOCS

Documentation

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 an immutable hash map with copy-on-write semantics. Adding to or deleting from the map returns a new map instance. Since the map is immutable, it is safe to use from multiple concurrent threads without locks or other synchronization.

Copying the map is cheap, but since it is a struct, it is not done atomically. To get atomic copying, use atomic.Value.

Map is different from Go map and sync.Map since it safe to copy and is copied by value.

The zero Map is empty and ready for use.

func (Map) Delete

func (m Map) Delete(key interface{}) Map

Delete returns a map without entries matching the key. If no entry matches, the original map is returned.

func (Map) Get

func (m Map) Get(key interface{}) (interface{}, bool)

Get retrieves a value from the map.

func (*Map) Range

func (m *Map) Range(visitor func(key, value interface{}) bool)

Range calls visitor for each element in the map. If visitor returns false, the iteration stops. Since the map is immutable, it will not change during iteration.

func (Map) Set

func (m Map) Set(key, value interface{}) Map

Set adds an entry to a map and returns the updated map.

func (*Map) Size added in v0.0.2

func (m *Map) Size() uint32

Size returns the number of elements in the map.

Jump to

Keyboard shortcuts

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