pmaps

package
v0.4.104 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: ISC Imports: 11 Imported by: 1

Documentation

Overview

Ranking is a pointer-identity-to-value map of updatable values traversable by rank. Ranking implements parli.Ranking[V comparable, R constraints.Ordered].

KeyInsOrderedMap is a mapping whose keys are provided in insertion order.

KeyByValueMap is a mapping whose keys are provided in value order.

KeyInsOrderedMap is a mapping whose keys are provided in insertion order.

KeyOrderedMapFunc is a mapping whose keys are provided in custom order.

KeyOrderedMap is a mapping whose keys are provided in order.

OrderedMapFunc is a mapping whose values are provided in custom order.

OrderedMap is a mapping whose values are provided in order.

RankingThreadSafe is a thread-safe pointer-identity-to-value map of updatable values traversable by rank. RankingThreadSafe implements parli.Ranking[V comparable, R constraints.Ordered].

Ranking is a pointer-identity-to-value map of updatable values traversable by rank. Ranking implements parli.Ranking[V comparable, R constraints.Ordered].

RWMap is a one-liner thread-safe mapping. RWMap implements parli.ThreadSafeMap[K comparable, V any].

ThreadSafeKeyOrderedByValueMap is a mapping whose keys can be provided in value order. Thread-safe.

RWMap is a one-liner thread-safe mapping. RWMap implements parli.ThreadSafeMap[K comparable, V any].

ThreadSafeOrderedMapFunc is a mapping whose values are provided in custom order. Thread-safe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoMapSize added in v0.4.75

func GoMapSize[K comparable, V any](m map[K]V) (size uint64)

GoMapSize returns the current size of the bucket array of Go map m

  • size is 0 for a nil map
  • size is 1 for an unallocated hash-table — rare case
  • otherwise size is a power of 2

About Go map:

  • Go map is a hash map
  • a hash table is a space-time trade-off compared to array access
  • size is how many slots m’s hash table currently has
  • size may grow or shrink as m is modified
  • a mapping of the hash value-space is used for hash-table array access
  • each map slot contains a linked list of key-value pairs
  • more slots is faster closing in on O(1) complexity, fewer slots saves memory
  • Load factor is number of hash-table entries including collisions divided by hash table size

Source code:

  • the map source code part of the runtime package is available online:
  • https://go.googlesource.com/go/+/refs/heads/master/src/runtime/map.go
  • runtime source is typically installed on a computer that has go:
  • — module directory: …libexec/src, package directory: runtime
  • — on macOS homebrew similar to: …/homebrew/Cellar/go/1.20.2/libexec/src

func NewAggregatePriority added in v0.4.30

func NewAggregatePriority[V any, P constraints.Ordered](
	value *V,
	index int,
	aggregator parli.Aggregator[V, P],
) (aggregatePriority parli.AggregatePriority[V, P])

NewAggregatePriority returns an object providing cached priority values and order function

func NewAggregatingPriorityQueue added in v0.4.30

func NewAggregatingPriorityQueue[V any, P constraints.Ordered](
	maxQueueLength ...int,
) (priorityQueue parli.AggregatingPriorityQueue[V, P])

NewAggregatingPriorityQueue returns a map of updatable values traversable by rank

func NewPriorityQueue added in v0.4.30

func NewPriorityQueue[V any, P constraints.Ordered](
	priorityFunc func(value *V) (priority P),
) (priorityQueue parli.PriorityQueue[V, P])

NewPriorityQueue returns a map of updatable values traversable by rank

func NewPriorityQueueThreadSafe added in v0.4.30

func NewPriorityQueueThreadSafe[V any, P constraints.Ordered](
	ranker func(value *V) (rank P),
) (o1 parli.PriorityQueue[V, P])

NewRanking returns a thread-safe map of updatable values traversable by rank

func NewRWMap

func NewRWMap[K comparable, V any]() (rwMap parli.ThreadSafeMap[K, V])

NewRWMap returns a thread-safe map implementation

Types

type AggregatePriority added in v0.4.30

type AggregatePriority[V any, P constraints.Ordered] struct {
	// contains filtered or unexported fields
}

AggregatePriority provides cached priority values and order function

func (*AggregatePriority[V, P]) Aggregator added in v0.4.30

func (a *AggregatePriority[V, P]) Aggregator() (aggregator parli.Aggregator[V, P])

Aggregator returns the object calculating values

func (*AggregatePriority[V, P]) CachedPriority added in v0.4.30

func (a *AggregatePriority[V, P]) CachedPriority() (priority P)

Priority returns the effective cached priority

func (*AggregatePriority[V, P]) Cmp added in v0.4.30

func (x *AggregatePriority[V, P]) Cmp(a, b parli.AggregatePriority[V, P]) (result int)

Cmp returns a comparison of two AggregatePriority objects that represents value elements.

  • Cmp is a custom comparison function to be used with pslices and slices packages
  • Cmp makes AggregatePriority ordered
  • the Priority used is uncached value

func (*AggregatePriority[V, P]) Index added in v0.4.94

func (a *AggregatePriority[V, P]) Index() (index int)

Priority returns the effective cached priority

func (*AggregatePriority[V, P]) Update added in v0.4.30

func (a *AggregatePriority[V, P]) Update()

Update caches the current priority from the aggregator

type AggregatingPriorityQueue added in v0.4.30

type AggregatingPriorityQueue[V any, P constraints.Ordered] struct {
	// contains filtered or unexported fields
}

AggregatingPriorityQueue implements a priority queue using cached priorities from aggregators

  • identity is the pointer value to each aggregator of type V
  • P is the type used for priority, ordered highest first
  • insertion order is used for equal priorities, order lowest/earliest first

func (*AggregatingPriorityQueue[V, P]) Clear added in v0.4.30

func (a *AggregatingPriorityQueue[V, P]) Clear()

Clear empties the priority queue. The hashmap is left intact.

func (*AggregatingPriorityQueue[V, P]) Get added in v0.4.30

func (a *AggregatingPriorityQueue[V, P]) Get(valuep *V) (aggregator parli.Aggregator[V, P], ok bool)

Get retrieves a the value container with running totals associated with the identity valuep

func (*AggregatingPriorityQueue[V, P]) List added in v0.4.30

func (a *AggregatingPriorityQueue[V, P]) List(n ...int) (aggregatorQueue []parli.AggregatePriority[V, P])

List returns the first n or default all values by pirority

func (*AggregatingPriorityQueue[V, P]) Put added in v0.4.30

func (a *AggregatingPriorityQueue[V, P]) Put(valuep *V, aggregator parli.Aggregator[V, P])

Put stores a new value container associated with valuep

  • the valuep is assumed to not have a node in the queue

func (*AggregatingPriorityQueue[V, P]) Update added in v0.4.30

func (a *AggregatingPriorityQueue[V, P]) Update(valuep *V)

Update re-prioritizes a value

type AssignedPriority added in v0.4.30

type AssignedPriority[V any, P constraints.Ordered] struct {
	Priority P   // the main sort value, ordered high to low
	Index    int // insertion order: lowest/earliest value first: distinguishes between equal priorities
	Value    *V  // the pointer provides identity for this priority
}

AssignedPriority contains the assigned priority for a priority-queue element

  • V is the element value type whose pointer-value provides identity
  • P is the priority, a descending-ordered type
  • SetPriority updates the priority
  • Cmp makes AssignedPriority ordered

func NewAssignedPriority added in v0.4.30

func NewAssignedPriority[V any, P constraints.Ordered](priority P, index int, value *V) (assignedPriority *AssignedPriority[V, P])

func (*AssignedPriority[V, P]) Cmp added in v0.4.30

func (a *AssignedPriority[V, P]) Cmp(b *AssignedPriority[V, P]) (result int)

Cmp sorts descending: -1 results appears first

func (*AssignedPriority[V, P]) SetPriority added in v0.4.30

func (ap *AssignedPriority[V, P]) SetPriority(priority P)

type InsOrderedMap added in v0.4.83

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

InsOrderedMap is a mapping whose values are provided in insertion order.

func NewInsOrderedMap added in v0.4.83

func NewInsOrderedMap[K comparable, V any]() (orderedMap *InsOrderedMap[K, V])

NewInsOrderedMap is a mapping whose keys are provided in insertion order.

func (*InsOrderedMap[K, V]) Clone added in v0.4.83

func (mp *InsOrderedMap[K, V]) Clone() (clone *InsOrderedMap[K, V])

Clone returns a shallow clone of the map

func (*InsOrderedMap[K, V]) Delete added in v0.4.83

func (mp *InsOrderedMap[K, V]) Delete(key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*InsOrderedMap[K, V]) Dump added in v0.4.85

func (mp *InsOrderedMap[K, V]) Dump() (s string)

func (*InsOrderedMap[K, V]) List added in v0.4.83

func (mp *InsOrderedMap[K, V]) List(n ...int) (list []V)

List provides the mapped values in order

  • O(n)

func (*InsOrderedMap[K, V]) Put added in v0.4.83

func (mp *InsOrderedMap[K, V]) Put(key K, value V)

Put saves or replaces a mapping

type KeyByValueMap added in v0.4.60

type KeyByValueMap[K comparable, V constraints.Ordered] struct {
	Map[K, V]
	// contains filtered or unexported fields
}

KeyByValueMap is a mapping whose keys are provided in value order.

func NewKeyByValueMap added in v0.4.60

func NewKeyByValueMap[K comparable, V constraints.Ordered]() (m *KeyByValueMap[K, V])

NewKeyByValueMap returns a mapping whose keys are provided in value order.

func (*KeyByValueMap[K, V]) Clone added in v0.4.60

func (mp *KeyByValueMap[K, V]) Clone() (clone *KeyByValueMap[K, V])

Clone returns a shallow clone of the map

func (*KeyByValueMap[K, V]) Delete added in v0.4.60

func (mp *KeyByValueMap[K, V]) Delete(key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*KeyByValueMap[K, V]) List added in v0.4.60

func (mp *KeyByValueMap[K, V]) List(n ...int) (list []K)

List provides the mapped values in order

  • O(n)

func (*KeyByValueMap[K, V]) Put added in v0.4.60

func (mp *KeyByValueMap[K, V]) Put(key K, value V)

Put saves or replaces a mapping

type KeyInsOrderedMap added in v0.4.39

type KeyInsOrderedMap[K constraints.Ordered, V any] struct {
	Map[K, V]
	// contains filtered or unexported fields
}

KeyInsOrderedMap is a mapping whose keys are provided in insertion order.

func NewKeyInsOrderedMap added in v0.4.39

func NewKeyInsOrderedMap[K constraints.Ordered, V any]() (orderedMap *KeyInsOrderedMap[K, V])

NewKeyInsOrderedMap is a mapping whose keys are provided in insertion order.

func (*KeyInsOrderedMap[K, V]) Clone added in v0.4.39

func (mp *KeyInsOrderedMap[K, V]) Clone() (clone *KeyInsOrderedMap[K, V])

Clone returns a shallow clone of the map

func (*KeyInsOrderedMap[K, V]) Delete added in v0.4.39

func (mp *KeyInsOrderedMap[K, V]) Delete(key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*KeyInsOrderedMap[K, V]) List added in v0.4.39

func (mp *KeyInsOrderedMap[K, V]) List(n ...int) (list []K)

List provides the mapped values in order

  • O(n)

func (*KeyInsOrderedMap[K, V]) Put added in v0.4.39

func (mp *KeyInsOrderedMap[K, V]) Put(key K, value V)

Put saves or replaces a mapping

type KeyOrderedMap added in v0.4.32

type KeyOrderedMap[K constraints.Ordered, V any] struct {
	KeyOrderedMapFunc[K, V]
}

KeyOrderedMap is a mapping whose keys are provided in order.

  • key is ordered type

func NewKeyOrderedMap added in v0.4.32

func NewKeyOrderedMap[K constraints.Ordered, V any]() (orderedMap *KeyOrderedMap[K, V])

NewKeyOrderedMap returns a mapping whose keys are provided in order.

func (*KeyOrderedMap[K, V]) Clone added in v0.4.32

func (m *KeyOrderedMap[K, V]) Clone() (clone *KeyOrderedMap[K, V])

Clone returns a shallow clone of the map

type KeyOrderedMapFunc added in v0.4.60

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

KeyOrderedMapFunc is a mapping whose keys are provided in custom order.

func NewKeyOrderedMapFunc added in v0.4.60

func NewKeyOrderedMapFunc[K comparable, V any](
	cmp func(a, b K) (result int),
) (orderedMap *KeyOrderedMapFunc[K, V])

NewKeyOrderedMapFunc returns a mapping whose keys are provided in custom order.

func NewKeyOrderedMapFunc2 added in v0.4.94

func NewKeyOrderedMapFunc2[K constraints.Ordered, V any](
	list parli.Ordered[K],
) (orderedMap *KeyOrderedMapFunc[K, V])

NewKeyOrderedMapFunc2 returns a mapping whose keys are provided in order.

func (*KeyOrderedMapFunc[K, V]) Clear added in v0.4.94

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

Clone returns a shallow clone of the map

func (*KeyOrderedMapFunc[K, V]) Clone added in v0.4.94

func (m *KeyOrderedMapFunc[K, V]) Clone() (clone *KeyOrderedMapFunc[K, V])

Clone returns a shallow clone of the map

func (*KeyOrderedMapFunc[K, V]) Delete added in v0.4.94

func (m *KeyOrderedMapFunc[K, V]) Delete(key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*KeyOrderedMapFunc[K, V]) List added in v0.4.94

func (m *KeyOrderedMapFunc[K, V]) List(n ...int) (list []K)

List provides keys in order

  • O(n)

func (*KeyOrderedMapFunc[K, V]) Put added in v0.4.94

func (m *KeyOrderedMapFunc[K, V]) Put(key K, value V)

Put saves or replaces a mapping

type Map added in v0.4.32

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

Map is a Go Map that is reusable

  • native functions: Get Put Delete Length Range
  • convenience functions: Clear Clone (need access to the Go map)

func NewMap added in v0.4.32

func NewMap[K comparable, V any]() (mp *Map[K, V])

NewMap returns a resusable Go Map

func (*Map[K, V]) Clear added in v0.4.32

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

Clear empties the map

func (*Map[K, V]) Clone added in v0.4.32

func (m *Map[K, V]) Clone() (clone *Map[K, V])

Clone returns a shallow clone of the map

func (*Map[K, V]) Delete added in v0.4.32

func (m *Map[K, V]) Delete(key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*Map[K, V]) Get added in v0.4.32

func (m *Map[K, V]) Get(key K) (value V, ok bool)

Get returns the value mapped by key or the V zero-value otherwise.

  • the ok return value is true if a mapping was found.
  • O(1)

func (*Map[K, V]) Length added in v0.4.32

func (m *Map[K, V]) Length() (length int)

Length returns the number of mappings

func (*Map[K, V]) Put added in v0.4.32

func (m *Map[K, V]) Put(key K, value V)

Put saves or replaces a mapping

func (*Map[K, V]) Range added in v0.4.94

func (m *Map[K, V]) Range(rangeFunc func(key K, value V) (keepGoing bool))

Range traverses map bindings

  • iterates over map until rangeFunc returns false
  • similar to: func (*sync.Map).Range(f func(key any, value any) bool)

type OrderedMap added in v0.4.32

type OrderedMap[K comparable, V constraints.Ordered] struct {
	OrderedMapFunc[K, V] // reusable map with values provided in order
}

OrderedMap is a mapping whose values are provided in order.

func NewOrderedMap added in v0.4.32

func NewOrderedMap[K comparable, V constraints.Ordered]() (orderedMap *OrderedMap[K, V])

NewOrderedMap returns a mapping whose values are provided in order.

func (*OrderedMap[K, V]) Clone added in v0.4.32

func (m *OrderedMap[K, V]) Clone() (clone *OrderedMap[K, V])

Clone returns a shallow clone of the map

type OrderedMapFunc added in v0.4.60

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

OrderedMapFunc is a mapping whose values are provided in custom order.

func NewOrderedMapFunc added in v0.4.60

func NewOrderedMapFunc[K comparable, V any](
	cmp func(a, b V) (result int),
) (orderedMap *OrderedMapFunc[K, V])

NewOrderedMapFunc returns a mapping whose values are provided in custom order.

  • cmp(a, b) returns:
  • — a negative number if a should be before b
  • — 0 if a == b
  • — a positive number if a should be after b

func NewOrderedMapFunc2 added in v0.4.94

func NewOrderedMapFunc2[K comparable, V any](
	list parli.Ordered[V],
) (orderedMap *OrderedMapFunc[K, V])

NewOrderedMapFunc2 returns a mapping whose values are provided in custom order.

func (*OrderedMapFunc[K, V]) Clone added in v0.4.60

func (m *OrderedMapFunc[K, V]) Clone() (clone *OrderedMapFunc[K, V])

Clone returns a shallow clone of the map

func (*OrderedMapFunc[K, V]) Delete added in v0.4.60

func (m *OrderedMapFunc[K, V]) Delete(key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*OrderedMapFunc[K, V]) List added in v0.4.60

func (m *OrderedMapFunc[K, V]) List(n ...int) (list []V)

List provides the mapped values in order

  • O(n)

func (*OrderedMapFunc[K, V]) Put added in v0.4.60

func (m *OrderedMapFunc[K, V]) Put(key K, value V)

Put saves or replaces a mapping

type PriorityQueue added in v0.4.30

type PriorityQueue[V any, P constraints.Ordered] struct {
	// contains filtered or unexported fields
}

PriorityQueue is a pointer-identity-to-value map of updatable values traversable by rank. PriorityQueue implements parli.PriorityQueue[V comparable, R constraints.Ordered].

  • V is a value reference composite type that is comparable, ie. not slice map function. Preferrably, V is interface or pointer to struct type.
  • R is an ordered type such as int floating-point string, used to rank the V values
  • values are added or updated using AddOrUpdate method distinguished by (computer science) identity
  • if the same comparable value V is added again, that value is re-ranked
  • rank R is computed from a value V using the ranker function. The ranker function may be examining field values of a struct
  • values can have the same rank. If they do, equal rank is provided in insertion order

func (*PriorityQueue[V, P]) AddOrUpdate added in v0.4.30

func (pq *PriorityQueue[V, P]) AddOrUpdate(valuep *V)

AddOrUpdate adds a new value to the ranking or updates the ranking of a value that has changed.

func (*PriorityQueue[V, P]) List added in v0.4.30

func (pq *PriorityQueue[V, P]) List(n ...int) (valueQueue []*V)

List returns the first n or default all values by rank

type PriorityQueueThreadSafe added in v0.4.30

type PriorityQueueThreadSafe[V any, P constraints.Ordered] struct {
	parli.PriorityQueue[V, P]
	// contains filtered or unexported fields
}

PriorityQueueThreadSafe is a thread-safe pointer-identity-to-value map of updatable values traversable by rank. PriorityQueueThreadSafe implements parli.Ranking[V comparable, R constraints.Ordered].

  • V is a value reference composite type that is comparable, ie. not slice map function. Preferrably, V is interface or pointer to struct type.
  • P is an ordered type such as int floating-point string, used to rank the V values
  • values are added or updated using AddOrUpdate method distinguished by (computer science) identity
  • if the same comparable value V is added again, that value is re-ranked
  • rank R is computed from a value V using the ranker function. The ranker function may be examining field values of a struct
  • values can have the same rank. If they do, equal rank is provided in insertion order

func (*PriorityQueueThreadSafe[V, P]) AddOrUpdate added in v0.4.30

func (mp *PriorityQueueThreadSafe[V, P]) AddOrUpdate(value *V)

AddOrUpdate adds a new value to the ranking or updates the ranking of a value that has changed.

func (*PriorityQueueThreadSafe[V, P]) List added in v0.4.30

func (mp *PriorityQueueThreadSafe[V, P]) List(n ...int) (list []*V)

List returns the first n or default all values by rank

type RWMap

type RWMap[K comparable, V any] struct {
	ThreadSafeMap[K, V]
}

RWMap is a one-liner thread-safe mapping. RWMap implements parli.ThreadSafeMap[K comparable, V any].

  • GetOrCreate method is an atomic, thread-safe operation as opposed to Get-then-Put
  • Swap and PutIf are atomic, thread-safe operations
  • V is copied so if size of V is large or V contains locks, use pointer
  • RWMap uses reader/writer mutual exclusion lock for slightly higher performance.
  • RWMap must be in same package as PMap
  • Get methods are O(1)

func NewRWMap2 added in v0.4.34

func NewRWMap2[K comparable, V any]() (rwMap *RWMap[K, V])

NewRWMap2 returns a thread-safe map implementation

func (*RWMap[K, V]) Clone

func (rw *RWMap[K, V]) Clone() (clone parli.ThreadSafeMap[K, V])

Clone returns a shallow clone of the map

func (*RWMap[K, V]) Clone2 added in v0.4.47

func (rw *RWMap[K, V]) Clone2() (clone *RWMap[K, V])

Clone returns a shallow clone of the map

func (*RWMap[K, V]) GetOrCreate

func (rw *RWMap[K, V]) GetOrCreate(
	key K,
	newV func() (value *V),
	makeV func() (value V),
) (value V, ok bool)

GetOrCreate returns an item from the map if it exists otherwise creates it.

  • newV or makeV are invoked in the critical section, ie. these functions may not access the map or deadlock
  • if a key is mapped, its value is returned
  • otherwise, if newV and makeV are both nil, nil is returned.
  • otherwise, if newV is present, it is invoked to return a pointer ot a value. A nil return value from newV causes panic. A new mapping is created using the value pointed to by the newV return value.
  • otherwise, a mapping is created using whatever makeV returns
  • newV and makeV may not access the map. The map’s write lock is held during their execution
  • GetOrCreate is an atomic, thread-safe operation
  • value insert is O(log n)

func (*RWMap[K, V]) Keys added in v0.4.47

func (rw *RWMap[K, V]) Keys(n ...int) (list []K)

List provides keys, undefined ordering

  • O(n)

func (*RWMap[K, V]) List

func (rw *RWMap[K, V]) List() (list []V)

List provides the mapped values, undefined ordering

  • O(n)

func (*RWMap[K, V]) PutIf added in v0.4.39

func (rw *RWMap[K, V]) PutIf(key K, value V, putIf func(value V) (doPut bool)) (wasNewKey bool)

Putif is conditional Put depending on the return value from the putIf function.

  • if key does not exist in the map, the put is carried out and wasNewKey is true
  • if key exists and putIf is nil or returns true, the put is carried out and wasNewKey is false
  • if key exists and putIf returns false, the put is not carried out and wasNewKey is false
  • during PutIf, the map cannot be accessed and the map’s write-lock is held
  • PutIf is an atomic, thread-safe operation

func (*RWMap[K, V]) Swap added in v0.4.39

func (rw *RWMap[K, V]) Swap(otherMap parli.ThreadSafeMap[K, V]) (previousMap parli.ThreadSafeMap[K, V])

Swap replaces the map with otherMap and returns the current map in previousMap

  • if otherMap is not RWMap, no swap takes place and previousMap is nil
  • Swap is an atomic, thread-safe operation

type ThreadSafeInsOrderedMap added in v0.4.83

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

ThreadSafeInsOrderedMap is a mapping whose values are provided in insertion order. Thread-safe.

func NewThreadSafeInsOrderedMap added in v0.4.83

func NewThreadSafeInsOrderedMap[K comparable, V any]() (orderedMap *ThreadSafeInsOrderedMap[K, V])

func (*ThreadSafeInsOrderedMap[K, V]) Clear added in v0.4.83

func (mp *ThreadSafeInsOrderedMap[K, V]) Clear()

Clear empties the map

func (*ThreadSafeInsOrderedMap[K, V]) Clone added in v0.4.83

func (mp *ThreadSafeInsOrderedMap[K, V]) Clone() (clone *ThreadSafeInsOrderedMap[K, V])

Clone returns a shallow clone of the map

func (*ThreadSafeInsOrderedMap[K, V]) Delete added in v0.4.83

func (mp *ThreadSafeInsOrderedMap[K, V]) Delete(key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*ThreadSafeInsOrderedMap[K, V]) Get added in v0.4.83

func (mp *ThreadSafeInsOrderedMap[K, V]) Get(key K) (value V, ok bool)

func (*ThreadSafeInsOrderedMap[K, V]) Length added in v0.4.83

func (mp *ThreadSafeInsOrderedMap[K, V]) Length() (length int)

func (*ThreadSafeInsOrderedMap[K, V]) List added in v0.4.83

func (mp *ThreadSafeInsOrderedMap[K, V]) List(n ...int) (list []V)

List provides the mapped values in order

  • O(n)

func (*ThreadSafeInsOrderedMap[K, V]) Put added in v0.4.83

func (mp *ThreadSafeInsOrderedMap[K, V]) Put(key K, value V)

Put saves or replaces a mapping

func (*ThreadSafeInsOrderedMap[K, V]) PutIf added in v0.4.83

func (mp *ThreadSafeInsOrderedMap[K, V]) PutIf(key K, value V, putIf func(value V) (doPut bool)) (wasNewKey bool)

Put saves or replaces a mapping

type ThreadSafeKeyOrderedByValueMap added in v0.4.47

type ThreadSafeKeyOrderedByValueMap[K comparable, V constraints.Ordered] struct {
	KeyByValueMap[K, V]
	// contains filtered or unexported fields
}

ThreadSafeKeyOrderedByValueMap is a mapping whose keys can be provided in value order. Thread-safe.

func NewThreadSafeKeyOrderedByValueMap added in v0.4.47

func NewThreadSafeKeyOrderedByValueMap[K comparable, V constraints.Ordered]() (m *ThreadSafeKeyOrderedByValueMap[K, V])

func (*ThreadSafeKeyOrderedByValueMap[K, V]) Clear added in v0.4.47

func (mp *ThreadSafeKeyOrderedByValueMap[K, V]) Clear()

Clear empties the map

func (*ThreadSafeKeyOrderedByValueMap[K, V]) Clone added in v0.4.47

func (mp *ThreadSafeKeyOrderedByValueMap[K, V]) Clone() (clone *ThreadSafeKeyOrderedByValueMap[K, V])

Clone returns a shallow clone of the map

func (*ThreadSafeKeyOrderedByValueMap[K, V]) Delete added in v0.4.47

func (mp *ThreadSafeKeyOrderedByValueMap[K, V]) Delete(key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*ThreadSafeKeyOrderedByValueMap[K, V]) DeleteFirst added in v0.4.47

func (mp *ThreadSafeKeyOrderedByValueMap[K, V]) DeleteFirst() (key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*ThreadSafeKeyOrderedByValueMap[K, V]) Get added in v0.4.47

func (mp *ThreadSafeKeyOrderedByValueMap[K, V]) Get(key K) (value V, ok bool)

func (*ThreadSafeKeyOrderedByValueMap[K, V]) Length added in v0.4.47

func (mp *ThreadSafeKeyOrderedByValueMap[K, V]) Length() (length int)

func (*ThreadSafeKeyOrderedByValueMap[K, V]) List added in v0.4.47

func (mp *ThreadSafeKeyOrderedByValueMap[K, V]) List(n ...int) (list []K)

List provides the mapped values in order

  • O(n)

func (*ThreadSafeKeyOrderedByValueMap[K, V]) Put added in v0.4.47

func (mp *ThreadSafeKeyOrderedByValueMap[K, V]) Put(key K, value V)

Put saves or replaces a mapping

func (*ThreadSafeKeyOrderedByValueMap[K, V]) PutIf added in v0.4.47

func (mp *ThreadSafeKeyOrderedByValueMap[K, V]) PutIf(key K, value V, putIf func(value V) (doPut bool)) (wasNewKey bool)

Put saves or replaces a mapping

type ThreadSafeKeyOrderedMap added in v0.4.43

type ThreadSafeKeyOrderedMap[K constraints.Ordered, V any] struct {
	ThreadSafeMap[K, V]
	// contains filtered or unexported fields
}

func NewThreadSafeKeyOrderedMap added in v0.4.43

func NewThreadSafeKeyOrderedMap[K constraints.Ordered, V any]() (orderedMap *ThreadSafeKeyOrderedMap[K, V])

NewThreadSafeKeyOrderedMap returns a mapping whose keys are provided in custom order.

func (*ThreadSafeKeyOrderedMap[K, V]) Clear added in v0.4.43

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

Clone returns a shallow clone of the map

func (*ThreadSafeKeyOrderedMap[K, V]) Clone added in v0.4.43

func (m *ThreadSafeKeyOrderedMap[K, V]) Clone() (clone *ThreadSafeKeyOrderedMap[K, V])

Clone returns a shallow clone of the map

func (*ThreadSafeKeyOrderedMap[K, V]) Delete added in v0.4.43

func (m *ThreadSafeKeyOrderedMap[K, V]) Delete(key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*ThreadSafeKeyOrderedMap[K, V]) List added in v0.4.43

func (m *ThreadSafeKeyOrderedMap[K, V]) List(n ...int) (list []K)

List provides keys in order

  • O(n)

func (*ThreadSafeKeyOrderedMap[K, V]) Put added in v0.4.43

func (m *ThreadSafeKeyOrderedMap[K, V]) Put(key K, value V)

Put saves or replaces a mapping

type ThreadSafeMap added in v0.4.94

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

ThreadSafeMap is a thread-safe mapping that is reusable

  • ThreadSafeMap uses reader/writer mutual exclusion lock to attain thread-safety
  • native functions: Get Put Delete Length Range
  • convenience functions: Clear Clone (need access to the Go map)

func NewThreadSafeMap added in v0.4.94

func NewThreadSafeMap[K comparable, V any]() (pMap *ThreadSafeMap[K, V])

NewThreadSafeMap returns a thread-safe Go map

func (*ThreadSafeMap[K, V]) Clear added in v0.4.94

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

Clear empties the map

func (*ThreadSafeMap[K, V]) Clone added in v0.4.94

func (m *ThreadSafeMap[K, V]) Clone() (clone *ThreadSafeMap[K, V])

Clone returns a shallow clone of the map

func (*ThreadSafeMap[K, V]) Delete added in v0.4.94

func (m *ThreadSafeMap[K, V]) Delete(key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*ThreadSafeMap[K, V]) Get added in v0.4.94

func (m *ThreadSafeMap[K, V]) Get(key K) (value V, ok bool)

Get returns the value mapped by key or the V zero-value otherwise.

  • the ok return value is true if a mapping was found.
  • O(1)

func (*ThreadSafeMap[K, V]) Length added in v0.4.94

func (m *ThreadSafeMap[K, V]) Length() (length int)

Length returns the number of mappings

func (*ThreadSafeMap[K, V]) Put added in v0.4.96

func (m *ThreadSafeMap[K, V]) Put(key K, value V)

Put saves or replaces a mapping

func (*ThreadSafeMap[K, V]) Range added in v0.4.94

func (m *ThreadSafeMap[K, V]) Range(rangeFunc func(key K, value V) (keepGoing bool))

Range traverses map bindings

  • iterates over map until rangeFunc returns false
  • similar to: func (*sync.Map).Range(f func(key any, value any) bool)

type ThreadSafeOrderedMap added in v0.4.41

type ThreadSafeOrderedMap[K comparable, V constraints.Ordered] struct {
	ThreadSafeOrderedMapFunc[K, V]
}

ThreadSafeOrderedMap is a mapping whose values are provided in order. Thread-safe.

func NewThreadSafeOrderedMap added in v0.4.41

func NewThreadSafeOrderedMap[K comparable, V constraints.Ordered]() (orderedMap *ThreadSafeOrderedMap[K, V])

func (*ThreadSafeOrderedMap[K, V]) Clone added in v0.4.41

func (m *ThreadSafeOrderedMap[K, V]) Clone() (clone *ThreadSafeOrderedMap[K, V])

Clone returns a shallow clone of the map

type ThreadSafeOrderedMapFunc added in v0.4.60

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

ThreadSafeOrderedMapFunc is a mapping whose values are provided in custom order. Thread-safe.

func NewThreadSafeOrderedMapFunc added in v0.4.60

func NewThreadSafeOrderedMapFunc[K comparable, V any](
	cmp func(a, b V) (result int),
) (orderedMap *ThreadSafeOrderedMapFunc[K, V])

func NewThreadSafeOrderedMapFunc2 added in v0.4.94

func NewThreadSafeOrderedMapFunc2[K comparable, V constraints.Ordered](
	list parli.Ordered[V],
) (orderedMap *ThreadSafeOrderedMapFunc[K, V])

NewThreadSafeOrderedMapFunc2 returns a mapping whose values are provided in custom order.

func (*ThreadSafeOrderedMapFunc[K, V]) Clear added in v0.4.60

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

Clear empties the map

func (*ThreadSafeOrderedMapFunc[K, V]) Clone added in v0.4.60

func (m *ThreadSafeOrderedMapFunc[K, V]) Clone() (clone *ThreadSafeOrderedMapFunc[K, V])

Clone returns a shallow clone of the map

func (*ThreadSafeOrderedMapFunc[K, V]) Delete added in v0.4.60

func (m *ThreadSafeOrderedMapFunc[K, V]) Delete(key K)

Delete removes mapping using key K.

  • if key K is not mapped, the map is unchanged.
  • O(log n)

func (*ThreadSafeOrderedMapFunc[K, V]) GetOrCreate added in v0.4.60

func (m *ThreadSafeOrderedMapFunc[K, V]) GetOrCreate(
	key K,
	newV func() (value *V),
	makeV func() (value V),
) (value V, ok bool)

GetOrCreate returns an item from the map if it exists otherwise creates it.

  • newV or makeV are invoked in the critical section, ie. these functions may not access the map or deadlock
  • if a key is mapped, its value is returned
  • otherwise, if newV and makeV are both nil, nil is returned.
  • otherwise, if newV is present, it is invoked to return a pointer ot a value. A nil return value from newV causes panic. A new mapping is created using the value pointed to by the newV return value.
  • otherwise, a mapping is created using whatever makeV returns
  • newV and makeV may not access the map. The map’s write lock is held during their execution
  • GetOrCreate is an atomic, thread-safe operation
  • value insert is O(log n)

func (*ThreadSafeOrderedMapFunc[K, V]) List added in v0.4.60

func (m *ThreadSafeOrderedMapFunc[K, V]) List(n ...int) (list []V)

List provides the mapped values in order

  • O(n)

func (*ThreadSafeOrderedMapFunc[K, V]) Put added in v0.4.60

func (m *ThreadSafeOrderedMapFunc[K, V]) Put(key K, value V)

Put saves or replaces a mapping

func (*ThreadSafeOrderedMapFunc[K, V]) PutIf added in v0.4.60

func (m *ThreadSafeOrderedMapFunc[K, V]) PutIf(key K, value V, putIf func(value V) (doPut bool)) (wasNewKey bool)

Put saves or replaces a mapping

  • if mapping exists and poutif i non-nil, puIf function is invoked
  • put is only carried out if mapping is new or putIf is non-nil and returns true

Jump to

Keyboard shortcuts

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