Documentation ¶
Overview ¶
Ranking is a pointer-identity-to-value map of updatable values traversable by rank. Ranking implements parl.Ranking[V comparable, R constraints.Ordered].
KeyOrderedMapAny is a mapping of uncomparable keys whose keys are ordered by a key-order function ¶
KeyOrderedMap is a mapping whose keys are provided in 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 parl.Ranking[V comparable, R constraints.Ordered].
Ranking is a pointer-identity-to-value map of updatable values traversable by rank. Ranking implements parl.Ranking[V comparable, R constraints.Ordered].
RWMap is a one-liner thread-safe mapping. RWMap implements parl.ThreadSafeMap[K comparable, V any].
Index ¶
- func NewAggregatePriority[V any, P constraints.Ordered](value *V, index int, aggregator parl.Aggregator[V, P]) (aggregatePriority parl.AggregatePriority[V, P])
- func NewAggregatingPriorityQueue[V any, P constraints.Ordered]() (priorityQueue parl.AggregatingPriorityQueue[V, P])
- func NewPriorityQueue[V any, P constraints.Ordered](priorityFunc func(value *V) (priority P)) (priorityQueue parl.PriorityQueue[V, P])
- func NewPriorityQueueThreadSafe[V any, P constraints.Ordered](ranker func(value *V) (rank P)) (o1 parl.PriorityQueue[V, P])
- func NewRWMap[K comparable, V any]() (rwMap parl.ThreadSafeMap[K, V])
- type AggregatePriority
- type AggregatingPriorityQueue
- func (pq *AggregatingPriorityQueue[V, P]) Clear()
- func (pq *AggregatingPriorityQueue[V, P]) Cmp(a, b parl.AggregatePriority[V, P]) (result int)
- func (pq *AggregatingPriorityQueue[V, P]) Get(valuep *V) (aggregator parl.Aggregator[V, P], ok bool)
- func (pq *AggregatingPriorityQueue[V, P]) List(n ...int) (aggregatorQueue []parl.AggregatePriority[V, P])
- func (pq *AggregatingPriorityQueue[V, P]) Put(valuep *V, aggregator parl.Aggregator[V, P])
- func (pq *AggregatingPriorityQueue[V, P]) Update(valuep *V)
- type AssignedPriority
- type KeyOrderedMap
- type KeyOrderedMapAny
- func (mp *KeyOrderedMapAny[K, O, V]) Clone() (clone *KeyOrderedMapAny[K, O, V])
- func (mp *KeyOrderedMapAny[K, O, V]) Cmp(a, b K) (result int)
- func (mp *KeyOrderedMapAny[K, O, V]) Delete(key K)
- func (mp *KeyOrderedMapAny[K, O, V]) Get(key K) (value V, ok bool)
- func (mp *KeyOrderedMapAny[K, O, V]) List(n ...int) (list []K)
- func (mp *KeyOrderedMapAny[K, O, V]) Put(key K, value V)
- type Map
- type OrderedMap
- type PriorityQueue
- type PriorityQueueThreadSafe
- type RWMap
- func (rw *RWMap[K, V]) Clear()
- func (rw *RWMap[K, V]) Clone() (clone parl.ThreadSafeMap[K, V])
- func (rw *RWMap[K, V]) Delete(key K)
- func (rw *RWMap[K, V]) Get(key K) (value V, ok bool)
- func (rw *RWMap[K, V]) GetOrCreate(key K, newV func() (value *V), makeV func() (value V)) (value V, ok bool)
- func (rw *RWMap[K, V]) Length() (length int)
- func (rw *RWMap[K, V]) List() (list []V)
- func (rw *RWMap[K, V]) Put(key K, value V)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAggregatePriority ¶ added in v0.4.30
func NewAggregatePriority[V any, P constraints.Ordered]( value *V, index int, aggregator parl.Aggregator[V, P], ) (aggregatePriority parl.AggregatePriority[V, P])
func NewAggregatingPriorityQueue ¶ added in v0.4.30
func NewAggregatingPriorityQueue[V any, P constraints.Ordered]() (priorityQueue parl.AggregatingPriorityQueue[V, P])
NewRanking 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 parl.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 parl.PriorityQueue[V, P])
NewRanking returns a thread-safe map of updatable values traversable by rank
func NewRWMap ¶
func NewRWMap[K comparable, V any]() (rwMap parl.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 }
func (*AggregatePriority[V, P]) Aggregator ¶ added in v0.4.30
func (ap *AggregatePriority[V, P]) Aggregator() (aggregator parl.Aggregator[V, P])
func (*AggregatePriority[V, P]) CachedPriority ¶ added in v0.4.30
func (ap *AggregatePriority[V, P]) CachedPriority() (priority P)
func (*AggregatePriority[V, P]) Cmp ¶ added in v0.4.30
func (a *AggregatePriority[V, P]) Cmp(b parl.AggregatePriority[V, P]) (result int)
func (*AggregatePriority[V, P]) Update ¶ added in v0.4.30
func (ap *AggregatePriority[V, P]) Update()
type AggregatingPriorityQueue ¶ added in v0.4.30
type AggregatingPriorityQueue[V any, P constraints.Ordered] struct { // contains filtered or unexported fields }
func (*AggregatingPriorityQueue[V, P]) Clear ¶ added in v0.4.30
func (pq *AggregatingPriorityQueue[V, P]) Clear()
Clear empties the priority queue. The hashmap is left intact.
func (*AggregatingPriorityQueue[V, P]) Cmp ¶ added in v0.4.30
func (pq *AggregatingPriorityQueue[V, P]) Cmp(a, b parl.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 sued with pslices and slices packages
- Cmp makes AggregatePriority ordered
func (*AggregatingPriorityQueue[V, P]) Get ¶ added in v0.4.30
func (pq *AggregatingPriorityQueue[V, P]) Get(valuep *V) (aggregator parl.Aggregator[V, P], ok bool)
Get retrieves a possible value container associated with valuep
func (*AggregatingPriorityQueue[V, P]) List ¶ added in v0.4.30
func (pq *AggregatingPriorityQueue[V, P]) List(n ...int) (aggregatorQueue []parl.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 (pq *AggregatingPriorityQueue[V, P]) Put(valuep *V, aggregator parl.Aggregator[V, P])
Put stores a new value container associated with valuep
- the valuep is asusmed to not have a node in the queue
func (*AggregatingPriorityQueue[V, P]) Update ¶ added in v0.4.30
func (pq *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 Index int Value *V }
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
- Index is insertion order, lowest-value first
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 KeyOrderedMap ¶ added in v0.4.32
type KeyOrderedMap[K constraints.Ordered, V any] struct { Map[K, V] // contains filtered or unexported fields }
KeyOrderedMap is a mapping whose keys are provided in order
func NewKeyOrderedMap ¶ added in v0.4.32
func NewKeyOrderedMap[K constraints.Ordered, V any]() (orderedMap *KeyOrderedMap[K, V])
func (*KeyOrderedMap[K, V]) Clone ¶ added in v0.4.32
func (mp *KeyOrderedMap[K, V]) Clone() (clone *KeyOrderedMap[K, V])
Clone returns a shallow clone of the map
func (*KeyOrderedMap[K, V]) Delete ¶ added in v0.4.32
func (mp *KeyOrderedMap[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 (*KeyOrderedMap[K, V]) List ¶ added in v0.4.32
func (mp *KeyOrderedMap[K, V]) List(n ...int) (list []K)
List provides the mapped values in order
- O(n)
func (*KeyOrderedMap[K, V]) Put ¶ added in v0.4.32
func (mp *KeyOrderedMap[K, V]) Put(key K, value V)
Put saves or replaces a mapping
type KeyOrderedMapAny ¶ added in v0.4.32
type KeyOrderedMapAny[K any, O constraints.Ordered, V any] struct { Map[O, V] // contains filtered or unexported fields }
KeyOrderedMapAny is a mapping of uncomparable keys whose keys are ordered by a key-order function
func NewKeyOrderedMapAny ¶ added in v0.4.32
func NewKeyOrderedMapAny[K any, O constraints.Ordered, V any]( keyOrderFunc func(key K) (order O), ) (orderedMap *KeyOrderedMapAny[K, O, V])
func (*KeyOrderedMapAny[K, O, V]) Clone ¶ added in v0.4.32
func (mp *KeyOrderedMapAny[K, O, V]) Clone() (clone *KeyOrderedMapAny[K, O, V])
Clone returns a shallow clone of the map
func (*KeyOrderedMapAny[K, O, V]) Cmp ¶ added in v0.4.32
func (mp *KeyOrderedMapAny[K, O, V]) Cmp(a, b K) (result int)
func (*KeyOrderedMapAny[K, O, V]) Delete ¶ added in v0.4.32
func (mp *KeyOrderedMapAny[K, O, V]) Delete(key K)
Delete removes mapping using key K.
- if key K is not mapped, the map is unchanged.
- O(log n)
func (*KeyOrderedMapAny[K, O, V]) Get ¶ added in v0.4.32
func (mp *KeyOrderedMapAny[K, O, 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 (*KeyOrderedMapAny[K, O, V]) List ¶ added in v0.4.32
func (mp *KeyOrderedMapAny[K, O, V]) List(n ...int) (list []K)
List provides the mapped values in order
- O(n)
func (*KeyOrderedMapAny[K, O, V]) Put ¶ added in v0.4.32
func (mp *KeyOrderedMapAny[K, O, 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 }
func NewMap ¶ added in v0.4.32
func NewMap[K comparable, V any]() (mp *Map[K, V])
func (*Map[K, V]) Delete ¶ added in v0.4.32
func (mp *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
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)
type OrderedMap ¶ added in v0.4.32
type OrderedMap[K comparable, V constraints.Ordered] struct { Map[K, V] // contains filtered or unexported fields }
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])
func (*OrderedMap[K, V]) Clone ¶ added in v0.4.32
func (mp *OrderedMap[K, V]) Clone() (clone *OrderedMap[K, V])
Clone returns a shallow clone of the map
func (*OrderedMap[K, V]) Delete ¶ added in v0.4.32
func (mp *OrderedMap[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 (*OrderedMap[K, V]) List ¶ added in v0.4.32
func (mp *OrderedMap[K, V]) List(n ...int) (list []V)
List provides the mapped values in order
- O(n)
func (*OrderedMap[K, V]) Put ¶ added in v0.4.32
func (mp *OrderedMap[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 parl.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 { parl.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 parl.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 { // contains filtered or unexported fields }
RWMap is a one-liner thread-safe mapping. RWMap implements parl.ThreadSafeMap[K comparable, V any].
- GetOrCreate method is a thread-safe atomic operation as opposed to Get-then-Put
- RWMap does not need to be initialized
- For using RWMap as periodically updated thread-safe mapping collection, use with parl.AtomicReference
- 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.
- Get methods are O(1)
func (*RWMap[K, V]) Clone ¶
func (rw *RWMap[K, V]) Clone() (clone parl.ThreadSafeMap[K, V])
Clone returns a shallow clone of the map
func (*RWMap[K, V]) Delete ¶
func (rw *RWMap[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 (*RWMap[K, V]) Get ¶
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 (*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.
- GetOrCreate adds to thread-safety by making the get-put operations atomic
- 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
- value insert is O(log n)