Documentation ¶
Index ¶
- type ErrKeyNotFound
- type ModifyValueFunc
- type OrderedMap
- func (s *OrderedMap[K, V]) AddEntry(key K, value V)
- func (s *OrderedMap[K, V]) Copy() uc.Copier
- func (s *OrderedMap[K, V]) Delete(key K)
- func (s *OrderedMap[K, V]) DoFunc(f func(K, V) error) error
- func (s *OrderedMap[K, V]) GetEntries() []*cdp.Pair[K, V]
- func (s *OrderedMap[K, V]) GetEntry(key K) (V, bool)
- func (s *OrderedMap[K, V]) Iterator() ll.Iterater[*cdp.Pair[K, V]]
- func (s *OrderedMap[K, V]) Keys() []K
- func (s *OrderedMap[K, V]) ModifyValueFunc(key K, f ModifyValueFunc[V]) error
- func (s *OrderedMap[K, V]) Size() int
- func (s *OrderedMap[K, V]) SortKeys(less func(K, K) int)
- func (s *OrderedMap[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 OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap is a generic data structure that represents a sorted map.
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]
NewOrderedMap creates a new sorted map.
Returns:
- *SortedMap[K, V]: A pointer to the newly created sorted map.
func (*OrderedMap[K, V]) AddEntry ¶
func (s *OrderedMap[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 (*OrderedMap[K, V]) Copy ¶
func (s *OrderedMap[K, V]) Copy() uc.Copier
Copy creates a deep copy of the sorted map.
Returns:
- uc.Copier: A deep copy of the sorted map.
func (*OrderedMap[K, V]) Delete ¶
func (s *OrderedMap[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 (*OrderedMap[K, V]) DoFunc ¶
func (s *OrderedMap[K, V]) DoFunc(f func(K, V) error) error
DoFunc performs a function on each entry in the sorted map.
Parameters:
- f: The function to perform on each entry.
Returns:
- error: An error if the function fails.
Behaviors:
- The function 'f' is called for each entry in the sorted map.
- If the function 'f' returns an error, the iteration stops.
func (*OrderedMap[K, V]) GetEntries ¶
func (s *OrderedMap[K, V]) GetEntries() []*cdp.Pair[K, V]
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.
- Prefer using Iterator() method for iterating over the entries instead of this method.
func (*OrderedMap[K, V]) GetEntry ¶
func (s *OrderedMap[K, V]) GetEntry(key K) (V, bool)
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.
- bool: A boolean indicating if the key exists in the sorted map.
Errors:
- One can use the error *ErrKeyNotFound from the package when the key does not exist.
func (*OrderedMap[K, V]) Iterator ¶
func (s *OrderedMap[K, V]) Iterator() ll.Iterater[*cdp.Pair[K, V]]
Iterator returns an iterator for the sorted map.
Returns:
- ll.Iterater[*cdp.Pair[K, V]]: An iterator for the sorted map.
Behaviors:
- The iterator returns the entries in the order of the keys as pairs.
func (*OrderedMap[K, V]) Keys ¶
func (s *OrderedMap[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 (*OrderedMap[K, V]) ModifyValueFunc ¶
func (s *OrderedMap[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'.
func (*OrderedMap[K, V]) Size ¶
func (s *OrderedMap[K, V]) Size() int
Size returns the number of entries in the sorted map.
Returns:
- int: The number of entries in the sorted map.
func (*OrderedMap[K, V]) SortKeys ¶
func (s *OrderedMap[K, V]) SortKeys(less func(K, K) int)
SortKeys sorts the keys of the sorted map.
Parameters:
- less: The function that defines the sorting order.
Behaviors:
- The keys are sorted in place using the slice.SortFunc function.
- The function 'less' should return < 0 if the first key is less than the second key.
- The function 'less' should return > 0 if the first key is greater than the second key.
- The function 'less' should return 0 if the first key is equal to the second key.
func (*OrderedMap[K, V]) Values ¶
func (s *OrderedMap[K, V]) Values() []V
Values returns the values of the entries in the sorted map.
Returns:
- []V: The values of the entries in the sorted map.