Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RDict ¶
type RDict[K comparable, V any] struct { // contains filtered or unexported fields }
RDict is a data structure that behaves both as a map and as a ring. It is defined by a capacity, just as a ring. As more key-value pairs are added to it, it fills up until the capacity is reached. At that point, the first key in insertion order gets overwritten.
It is not goroutine-safe.
func New ¶
func New[K comparable, V any](capacity int) *RDict[K, V]
New is the constructor for the RDict. One needs to provide the capacity as sole input. Note that the type parameters for key and value must also be specified.
func (*RDict[K, V]) Del ¶
Del removes the key-value pair from the RDict. Returns true if the provided key was present in the RDict, false otherwise. Beware: it is O(N) in the worst case, being N the capacity of the RDict.
func (*RDict[K, V]) Do ¶
func (r *RDict[K, V]) Do(f func(K, V))
Do is the API to iterate over all the RDict elements. The provided input function receives, for each element stored in RDict, the key as first argument and the corresponding value as second.
type SafeRDict ¶
type SafeRDict[K comparable, V any] struct { // contains filtered or unexported fields }
SafeRDict is the goroutine-safe version of RDict.
func NewSafe ¶
func NewSafe[K comparable, V any](capacity int) *SafeRDict[K, V]
NewSafe is the constructor for the SafeRDict. One needs to provide the capacity as sole input. Note that the type parameters for key and value must also be specified.
func (*SafeRDict[K, V]) Del ¶
Del removes the key-value pair from the RDict. Returns true if the provided key was present in the RDict, false otherwise. Beware: it is O(N) in the worst case, being N the capacity of the SafeRDict. Locks RW.
func (*SafeRDict[K, V]) Do ¶
func (s *SafeRDict[K, V]) Do(f func(K, V))
Do is the API to iterate over all the RDict elements. The provided input function receives, for each element stored in RDict, the key as first argument and the corresponding value as second. Locks R.
func (*SafeRDict[K, V]) Len ¶
Len returns the number of elements contained by the SafeRDict. Locks R.