Documentation ¶
Index ¶
- type Option
- type Options
- type ShrinkingMap
- func (s *ShrinkingMap[K, V]) AsMap() (asMap map[K]V)
- func (s *ShrinkingMap[K, V]) Delete(key K) (deleted bool)
- func (s *ShrinkingMap[K, V]) ForEach(callback func(K, V) bool)
- func (s *ShrinkingMap[K, V]) ForEachKey(callback func(K) bool)
- func (s *ShrinkingMap[K, V]) Get(key K) (value V, exists bool)
- func (s *ShrinkingMap[K, V]) Has(key K) (has bool)
- func (s *ShrinkingMap[K, V]) IsEmpty() (empty bool)
- func (s *ShrinkingMap[K, V]) Pop() (key K, value V, exists bool)
- func (s *ShrinkingMap[K, V]) Set(key K, value V) (wasCreated bool)
- func (s *ShrinkingMap[K, V]) Shrink()
- func (s *ShrinkingMap[K, V]) Size() (size int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(opts *Options)
Option is a function setting an Options option.
func WithShrinkingThresholdCount ¶
WithShrinkingThresholdCount defines the count of deletions that triggers shrinking of the map.
func WithShrinkingThresholdRatio ¶
WithShrinkingThresholdRatio defines the ratio between the amount of deleted keys and the current map's size before shrinking is triggered.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options define options for a ShrinkingMap.
type ShrinkingMap ¶
type ShrinkingMap[K comparable, V any] struct { // contains filtered or unexported fields }
ShrinkingMap provides a non concurrent-safe map that shrinks if certain conditions are met (AND condition). Default values are: - ShrinkingThresholdRatio: 10.0 (set to 0.0 to disable) - ShrinkingThresholdCount: 100 (set to 0 to disable).
func New ¶
func New[K comparable, V any](opts ...Option) *ShrinkingMap[K, V]
New returns a new ShrinkingMap.
func (*ShrinkingMap[K, V]) AsMap ¶
func (s *ShrinkingMap[K, V]) AsMap() (asMap map[K]V)
AsMap returns the shrinking map as a regular map.
func (*ShrinkingMap[K, V]) Delete ¶
func (s *ShrinkingMap[K, V]) Delete(key K) (deleted bool)
Delete removes the entry with the given key, and possibly shrinks the map if the shrinking conditions have been reached.
func (*ShrinkingMap[K, V]) ForEach ¶
func (s *ShrinkingMap[K, V]) ForEach(callback func(K, V) bool)
ForEach iterates through the map and calls the consumer for every element. Returning false from this function indicates to abort the iteration.
func (*ShrinkingMap[K, V]) ForEachKey ¶
func (s *ShrinkingMap[K, V]) ForEachKey(callback func(K) bool)
ForEachKey iterates through the map and calls the consumer for every element. Returning false from this function indicates to abort the iteration.
func (*ShrinkingMap[K, V]) Get ¶
func (s *ShrinkingMap[K, V]) Get(key K) (value V, exists bool)
Get returns the value mapped to the given key, and the boolean flag that indicated if the key exists.
func (*ShrinkingMap[K, V]) Has ¶
func (s *ShrinkingMap[K, V]) Has(key K) (has bool)
Has returns if an entry with the given key exists.
func (*ShrinkingMap[K, V]) IsEmpty ¶
func (s *ShrinkingMap[K, V]) IsEmpty() (empty bool)
IsEmpty returns if the map is empty.
func (*ShrinkingMap[K, V]) Pop ¶
func (s *ShrinkingMap[K, V]) Pop() (key K, value V, exists bool)
Pop removes the first element from the map and returns it.
func (*ShrinkingMap[K, V]) Set ¶
func (s *ShrinkingMap[K, V]) Set(key K, value V) (wasCreated bool)
Set adds a key-value pair to the map. It returns true if the key was created.
func (*ShrinkingMap[K, V]) Size ¶
func (s *ShrinkingMap[K, V]) Size() (size int)
Size returns the number of entries in the map.