Documentation ¶
Index ¶
- type ErrKeyNotFound
- type ModifyValueFunc
- type SortedMap
- func (s *SortedMap[K, V]) AddEntry(key K, value V)
- func (s *SortedMap[K, V]) Copy() uc.Copier
- func (s *SortedMap[K, V]) Delete(key K)
- func (s *SortedMap[K, V]) GetEntries() []*cdp.Pair[K, V]
- func (s *SortedMap[K, V]) GetEntry(key K) (V, error)
- func (s *SortedMap[K, V]) Keys() []K
- func (s *SortedMap[K, V]) ModifyValueFunc(key K, f ModifyValueFunc[V]) error
- func (s *SortedMap[K, V]) Size() int
- func (s *SortedMap[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrKeyNotFound ¶
type ErrKeyNotFound struct { // The key that was not found. Key string }
ErrKeyNotFound is an error type that represents a key not found error.
func NewErrKeyNotFound ¶
func NewErrKeyNotFound[K comparable](key K) *ErrKeyNotFound
NewErrKeyNotFound creates a new ErrKeyNotFound with the provided key.
Parameters:
- key: The key that was not found.
Returns:
- *ErrKeyNotFound: A pointer to the new ErrKeyNotFound.
func (*ErrKeyNotFound) Error ¶
func (e *ErrKeyNotFound) Error() string
Error returns the error message: "key %q not found".
Returns:
- string: The error message.
type ModifyValueFunc ¶
ModifyValueFunc is a function that modifies a value.
Parameters:
- V: The value to modify.
Returns:
- V: The modified value.
type SortedMap ¶
type SortedMap[K comparable, V any] struct { // contains filtered or unexported fields }
SortedMap is a generic data structure that represents a sorted map.
func NewSortedMap ¶
func NewSortedMap[K comparable, V any]() *SortedMap[K, V]
NewSortedMap creates a new sorted map.
Returns:
- *SortedMap[K, V]: A pointer to the newly created sorted map.
func (*SortedMap[K, V]) AddEntry ¶
func (s *SortedMap[K, V]) AddEntry(key K, value V)
AddEntry adds an entry to the sorted map.
Parameters:
- key: The key of the entry.
- value: The value of the entry.
Behaviors:
- If the key already exists, the value is updated.
func (*SortedMap[K, V]) Copy ¶
Copy creates a deep copy of the sorted map.
Returns:
- uc.Copier: A deep copy of the sorted map.
func (*SortedMap[K, V]) Delete ¶
func (s *SortedMap[K, V]) Delete(key K)
Delete deletes the entry with the provided key from the sorted map.
Parameters:
- key: The key of the entry to delete.
Behaviors:
- If the key does not exist, nothing happens.
func (*SortedMap[K, V]) GetEntries ¶
GetEntries returns the entries in the sorted map.
Returns:
- []*cdp.Pair[K, V]: The entries in the sorted map.
Behaviors:
- The entries are returned in the order of the keys.
- There are no nil pairs in the returned slice.
func (*SortedMap[K, V]) GetEntry ¶
GetEntry gets the value of the entry with the provided key.
Parameters:
- key: The key of the entry.
Returns:
- V: The value of the entry.
- error: An error of type *ErrKeyNotFound if the key does not exist.
func (*SortedMap[K, V]) Keys ¶
func (s *SortedMap[K, V]) Keys() []K
Keys returns the keys of the entries in the sorted map.
Returns:
- []K: The keys of the entries in the sorted map.
func (*SortedMap[K, V]) ModifyValueFunc ¶
func (s *SortedMap[K, V]) ModifyValueFunc(key K, f ModifyValueFunc[V]) error
ModifyValueFunc is a method that modifies a value of the sorted map.
Parameters:
- key: The key of the value to modify.
- f: The function that modifies the value.
Returns:
- error: An error if the change fails.
Errors:
- *ErrKeyNotFound: The key does not exist in the sorted map.
- Any error returned by the function 'f'.