maps

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

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

Entry a Map item.

K: Key's type.

V: Value's type.

type HashMap

type HashMap[K comparable, V any] map[K]V

HashMap is the Go's map implementation of Map. It is a structure that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.

func (HashMap[K, V]) Clear

func (h HashMap[K, V]) Clear()

Clear removes all mappings from this map.

func (HashMap[K, V]) ContainsKey

func (h HashMap[K, V]) ContainsKey(key K) bool

ContainsKey returns true if this map contains a mapping for the specified key.

func (HashMap[K, V]) ForEach

func (h HashMap[K, V]) ForEach(iterPredicate collection.IterablePredicateBiFunc[K, V])

ForEach traverses through all mappings from this map. Use predicate's return boolean value to indicate a break of the iteration. 'K' represents the key whereas 'V' is the value of a map entry.

func (HashMap[K, V]) Get

func (h HashMap[K, V]) Get(key K) (V, bool)

Get returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

func (HashMap[K, V]) GetWithFallback

func (h HashMap[K, V]) GetWithFallback(key K, fallbackValue V) V

GetWithFallback returns the value to which the specified key is mapped, or fallbackValue if this map contains no mapping for the key.

func (HashMap[K, V]) Keys

func (h HashMap[K, V]) Keys() collection.Collection[K]

Keys returns a collection.Collection view of the keys contained src this map.

func (HashMap[K, V]) KeysSlice

func (h HashMap[K, V]) KeysSlice() []K

KeysSlice returns a slice view of the keys contained src this map.

func (HashMap[K, V]) Len

func (h HashMap[K, V]) Len() int

Len returns the number of key-value mappings src this map.

func (HashMap[K, V]) Put

func (h HashMap[K, V]) Put(key K, val V)

Put associates the specified value with the specified key src this map.

func (HashMap[K, V]) PutAll

func (h HashMap[K, V]) PutAll(src Map[K, V])

PutAll copies all mappings from the specified map to this map.

func (HashMap[K, V]) PutAllEntries

func (h HashMap[K, V]) PutAllEntries(entries ...Entry[K, V])

PutAllEntries copies all mappings from the slice of Entry(es) to this map.

func (HashMap[K, V]) PutIfAbsent

func (h HashMap[K, V]) PutIfAbsent(key K, val V) bool

PutIfAbsent if the specified key is not already associated with a value (or is mapped to nil) associates it with the given value and returns FALSE, else returns TRUE.

func (HashMap[K, V]) Remove

func (h HashMap[K, V]) Remove(key K) V

Remove removes the mapping for a key from this map if it is present.

func (HashMap[K, V]) Replace

func (h HashMap[K, V]) Replace(key K, val V) bool

Replace replaces the entry for the specified key only if it is currently mapped to some value.

func (HashMap[K, V]) Values

func (h HashMap[K, V]) Values() collection.Collection[V]

Values returns a collection.Collection view of the values contained src this map.

func (HashMap[K, V]) ValuesSlice

func (h HashMap[K, V]) ValuesSlice() []V

ValuesSlice returns a slice view of the values contained src this map.

type LinkedHashMap

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

LinkedHashMap hash table and linked list implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap src that it maintains a list.DoublyLinkedList running through all of its entries.

This linked list defines the iteration ordering, which is normally the order src which keys were inserted into the map (insertion-order). Note that insertion order is not affected if a key is re-inserted into the map. (A key k is reinserted into a map m if Put(k, m) is invoked when ContainsKey(k) would return true immediately prior to the invocation.)

func NewLinkedHashMap

func NewLinkedHashMap[K comparable, V any]() *LinkedHashMap[K, V]

NewLinkedHashMap allocates a new LinkedHashMap instance.

func (*LinkedHashMap[K, V]) Clear

func (m *LinkedHashMap[K, V]) Clear()

Clear removes all mappings from this map.

func (*LinkedHashMap[K, V]) ContainsKey

func (m *LinkedHashMap[K, V]) ContainsKey(key K) bool

ContainsKey returns true if this map contains a mapping for the specified key.

func (*LinkedHashMap[K, V]) ForEach

func (m *LinkedHashMap[K, V]) ForEach(predicateFunc collection.IterablePredicateBiFunc[K, V])

ForEach traverses through all mappings from this map. Use predicate's return boolean value to indicate a break of the iteration. 'K' represents the key whereas 'V' is the value of a map entry.

func (*LinkedHashMap[K, V]) Get

func (m *LinkedHashMap[K, V]) Get(key K) (V, bool)

Get returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

func (*LinkedHashMap[K, V]) GetWithFallback

func (m *LinkedHashMap[K, V]) GetWithFallback(key K, fallbackValue V) V

GetWithFallback returns the value to which the specified key is mapped, or fallbackValue if this map contains no mapping for the key.

func (*LinkedHashMap[K, V]) Keys

func (m *LinkedHashMap[K, V]) Keys() collection.Collection[K]

Keys returns a collection.Collection view of the keys contained src this map.

func (*LinkedHashMap[K, V]) KeysSlice

func (m *LinkedHashMap[K, V]) KeysSlice() []K

KeysSlice returns a slice view of the keys contained src this map.

func (*LinkedHashMap[K, V]) Len

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

Len returns the number of key-value mappings src this map.

func (*LinkedHashMap[K, V]) Put

func (m *LinkedHashMap[K, V]) Put(key K, val V)

Put associates the specified value with the specified key src this map.

func (*LinkedHashMap[K, V]) PutAll

func (m *LinkedHashMap[K, V]) PutAll(src Map[K, V])

PutAll copies all mappings from the specified map to this map.

func (*LinkedHashMap[K, V]) PutAllEntries

func (m *LinkedHashMap[K, V]) PutAllEntries(entries ...Entry[K, V])

PutAllEntries copies all mappings from the slice of Entry(es) to this map.

func (*LinkedHashMap[K, V]) PutIfAbsent

func (m *LinkedHashMap[K, V]) PutIfAbsent(key K, val V) bool

PutIfAbsent if the specified key is not already associated with a value (or is mapped to nil) associates it with the given value and returns FALSE, else returns TRUE.

func (*LinkedHashMap[K, V]) Remove

func (m *LinkedHashMap[K, V]) Remove(key K) V

Remove removes the mapping for a key from this map if it is present.

func (*LinkedHashMap[K, V]) Replace

func (m *LinkedHashMap[K, V]) Replace(key K, val V) bool

Replace replaces the entry for the specified key only if it is currently mapped to some value.

func (*LinkedHashMap[K, V]) Values

func (m *LinkedHashMap[K, V]) Values() collection.Collection[V]

Values returns a collection.Collection view of the values contained src this map.

func (*LinkedHashMap[K, V]) ValuesSlice

func (m *LinkedHashMap[K, V]) ValuesSlice() []V

ValuesSlice returns a slice view of the values contained src this map.

type Map

type Map[K comparable, V any] interface {
	// Get Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
	Get(key K) (V, bool)
	// GetWithFallback Returns the value to which the specified key is mapped, or fallbackValue if this map contains
	// no mapping for the key.
	GetWithFallback(key K, fallbackValue V) V
	// Put Associates the specified value with the specified key src this map.
	Put(key K, val V)
	// PutIfAbsent If the specified key is not already associated with a value (or is mapped to nil) associates
	// it with the given value and returns FALSE, else returns TRUE.
	PutIfAbsent(key K, val V) bool
	// PutAll Copies all mappings from the specified map to this map.
	PutAll(src Map[K, V])
	// PutAllEntries Copies all mappings from the slice of Entry(es) to this map.
	PutAllEntries(entries ...Entry[K, V])
	// Remove Removes the mapping for a key from this map if it is present.
	Remove(key K) V
	// Replace Replaces the entry for the specified key only if it is currently mapped to some value.
	Replace(key K, val V) bool
	// ContainsKey Returns true if this map contains a mapping for the specified key.
	ContainsKey(key K) bool
	// Len Returns the number of key-value mappings src this map.
	Len() int
	// Clear Removes all mappings from this map.
	Clear()
	// Keys Returns a collection.Collection view of the keys contained src this map.
	Keys() collection.Collection[K]
	// Values Returns a collection.Collection view of the values contained src this map.
	Values() collection.Collection[V]
	// KeysSlice returns a slice view of the keys contained src this map.
	KeysSlice() []K
	// ValuesSlice returns a slice view of the values contained src this map.
	ValuesSlice() []V
	// ForEach traverses through all mappings from this map. Use predicate's return boolean value to indicate
	// a break of the iteration. 'A' represents the key whereas 'B' is the value of a map entry.
	ForEach(predicateFunc collection.IterablePredicateBiFunc[K, V])
}

Map A structure that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.

Jump to

Keyboard shortcuts

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