SortedMap

package
v0.2.42 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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

type ModifyValueFunc[V any] func(V) (V, error)

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

func (s *SortedMap[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 (*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

func (s *SortedMap[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.

func (*SortedMap[K, V]) GetEntry

func (s *SortedMap[K, V]) GetEntry(key K) (V, error)

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'.

func (*SortedMap[K, V]) Size

func (s *SortedMap[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 (*SortedMap[K, V]) Values

func (s *SortedMap[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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL