Documentation ¶
Index ¶
- type EnhancedMap
- func (m *EnhancedMap) Clear()
- func (m *EnhancedMap[K, V]) ContainsKey(k K) bool
- func (m *EnhancedMap[K, V]) ContainsValue(value V) bool
- func (m *EnhancedMap[K, V]) ForEach(f func(K, V))
- func (m *EnhancedMap[K, V]) FromJSON(data []byte) error
- func (m *EnhancedMap[K, V]) Get(k K) (v V, ok bool)
- func (m *EnhancedMap[K, V]) GetOrDefault(k K, defaultValue V) (v V)
- func (m *EnhancedMap) IsEmpty() bool
- func (m *EnhancedMap[K, V]) KeySet() []K
- func (m *EnhancedMap[K, V]) MarshalJSON() ([]byte, error)
- func (m *EnhancedMap[K, V]) MustGet(k K) (v V)
- func (m *EnhancedMap[K, V]) Put(k K, v V)
- func (m *EnhancedMap[K, V]) PutAll(pairs []*Pair[K, V])
- func (m *EnhancedMap[K, V]) Remove(k K)
- func (m *EnhancedMap[K, V]) Size() int
- func (m *EnhancedMap[K, V]) ToJSON() ([]byte, error)
- func (m *EnhancedMap[K, V]) UnmarshalJSON(bytes []byte) error
- func (m *EnhancedMap[K, V]) Values() []V
- type HashMap
- type IMap
- func NewConcurrentHashMap[K comparable, V any]() IMap[K, V]
- func NewConcurrentHashMapWithExpectedSize[K comparable, V any](expectedSize int) IMap[K, V]
- func NewConcurrentLinkedHashMap[K comparable, V any]() IMap[K, V]
- func NewConcurrentLinkedHashMapWithExpectedSize[K comparable, V any](expectedSize int) IMap[K, V]
- func NewEnhancedMap[K comparable, V any]() IMap[K, V]
- func NewEnhancedMapWithExpectedSize[K comparable, V any](expectedSize int) IMap[K, V]
- func NewHashMap[K comparable, V any]() IMap[K, V]
- func NewHashMapWithExpectedSize[K comparable, V any](expectedSize int) IMap[K, V]
- func NewLinkedHashMap[K comparable, V any]() IMap[K, V]
- func NewLinkedHashMapWithExpectedSize[K comparable, V any](expectedSize int) IMap[K, V]
- func NewSynchronizedMap[K comparable, V any](rawMap IMap[K, V]) IMap[K, V]
- func NewTreeMap[K comparable, V any]() IMap[K, V]
- func NewTreeMapWithComparator[K comparable, V any](comparator collection.CompareFunc[K]) IMap[K, V]
- type LinkedHashMap
- func (m *LinkedHashMap[K, V]) Clear()
- func (m *LinkedHashMap) ContainsKey(k K) bool
- func (m *LinkedHashMap) ContainsValue(value V) bool
- func (m *LinkedHashMap[K, V]) ForEach(f func(K, V))
- func (m *LinkedHashMap[K, V]) FromJSON(data []byte) error
- func (m *LinkedHashMap) Get(k K) (v V, ok bool)
- func (m *LinkedHashMap[K, V]) GetOrDefault(k K, defaultValue V) (v V)
- func (m *LinkedHashMap) IsEmpty() bool
- func (m *LinkedHashMap[K, V]) KeySet() []K
- func (m *LinkedHashMap[K, V]) MarshalJSON() ([]byte, error)
- func (m *LinkedHashMap) MustGet(k K) (v V)
- func (m *LinkedHashMap[K, V]) Put(k K, v V)
- func (m *LinkedHashMap[K, V]) PutAll(pairs []*Pair[K, V])
- func (m *LinkedHashMap[K, V]) Remove(k K)
- func (m *LinkedHashMap) Size() int
- func (m *LinkedHashMap[K, V]) ToJSON() ([]byte, error)
- func (m *LinkedHashMap[K, V]) UnmarshalJSON(bytes []byte) error
- func (m *LinkedHashMap[K, V]) Values() []V
- type Pair
- type SynchronizedMap
- func (s *SynchronizedMap[K, V]) Clear()
- func (s *SynchronizedMap[K, V]) ContainsKey(k K) bool
- func (s *SynchronizedMap[K, V]) ContainsValue(value V) bool
- func (s *SynchronizedMap[K, V]) ForEach(f func(k K, v V))
- func (s *SynchronizedMap[K, V]) FromJSON(data []byte) (err error)
- func (s *SynchronizedMap[K, V]) Get(k K) (v V, ok bool)
- func (s *SynchronizedMap[K, V]) GetOrDefault(k K, defaultValue V) (v V)
- func (s *SynchronizedMap[K, V]) IsEmpty() bool
- func (s *SynchronizedMap[K, V]) KeySet() []K
- func (s *SynchronizedMap[K, V]) MarshalJSON() ([]byte, error)
- func (s *SynchronizedMap[K, V]) MustGet(k K) (v V)
- func (s *SynchronizedMap[K, V]) Put(k K, v V)
- func (s *SynchronizedMap[K, V]) PutAll(pairs []*Pair[K, V])
- func (s *SynchronizedMap[K, V]) Remove(k K)
- func (s *SynchronizedMap[K, V]) Size() int
- func (s *SynchronizedMap[K, V]) ToJSON() ([]byte, error)
- func (s *SynchronizedMap[K, V]) UnmarshalJSON(bytes []byte) error
- func (s *SynchronizedMap[K, V]) Values() []V
- type TreeMap
- func (t TreeMap[K, V]) Clear()
- func (t TreeMap[K, V]) ContainsKey(k K) bool
- func (t TreeMap[K, V]) ContainsValue(value V) bool
- func (t TreeMap[K, V]) ForEach(f func(K, V))
- func (t *TreeMap[K, V]) FromJSON(bytes []byte) error
- func (t TreeMap[K, V]) Get(k K) (v V, ok bool)
- func (t TreeMap[K, V]) GetOrDefault(k K, defaultValue V) (v V)
- func (t TreeMap[K, V]) IsEmpty() bool
- func (t TreeMap[K, V]) KeySet() []K
- func (t *TreeMap[K, V]) MarshalJSON() ([]byte, error)
- func (t TreeMap[K, V]) MustGet(k K) (v V)
- func (t TreeMap[K, V]) Put(k K, v V)
- func (t TreeMap[K, V]) PutAll(pairs []*Pair[K, V])
- func (t TreeMap[K, V]) Remove(k K)
- func (t TreeMap[K, V]) Size() int
- func (t *TreeMap[K, V]) ToJSON() ([]byte, error)
- func (t *TreeMap[K, V]) UnmarshalJSON(bytes []byte) error
- func (t TreeMap[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EnhancedMap ¶
type EnhancedMap[K comparable, V any] struct { // contains filtered or unexported fields }
EnhancedMap is a map implementation that satisfies the IMap interface.
func (*EnhancedMap[K, V]) ContainsKey ¶
func (m *EnhancedMap[K, V]) ContainsKey(k K) bool
ContainsKey checks if the map contains the specified key. It returns true if the key is found; otherwise, it returns false.
func (*EnhancedMap[K, V]) ContainsValue ¶
func (m *EnhancedMap[K, V]) ContainsValue(value V) bool
ContainsValue checks if the map contains the specified value. It returns true if the value is found; otherwise, it returns false.
func (*EnhancedMap[K, V]) ForEach ¶
func (m *EnhancedMap[K, V]) ForEach(f func(K, V))
ForEach applies the specified function to each key-value pair in the map.
func (*EnhancedMap[K, V]) FromJSON ¶ added in v0.1.2
func (m *EnhancedMap[K, V]) FromJSON(data []byte) error
FromJSON populates the map from the input JSON representation.
func (*EnhancedMap[K, V]) Get ¶
func (m *EnhancedMap[K, V]) Get(k K) (v V, ok bool)
Get retrieves the value associated with the specified key from the map. It returns the value and true if the key is found; otherwise, it returns the zero value of V and false.
func (*EnhancedMap[K, V]) GetOrDefault ¶
func (m *EnhancedMap[K, V]) GetOrDefault(k K, defaultValue V) (v V)
GetOrDefault retrieves the value associated with the specified key from the map. It returns the value if the key is found; otherwise, it returns the defaultValue.
func (*EnhancedMap[K, V]) KeySet ¶
func (m *EnhancedMap[K, V]) KeySet() []K
KeySet returns a slice containing all the keys in the map.
func (*EnhancedMap[K, V]) MarshalJSON ¶ added in v0.1.2
func (m *EnhancedMap[K, V]) MarshalJSON() ([]byte, error)
MarshalJSON @implements json.Marshaler
func (*EnhancedMap[K, V]) MustGet ¶
func (m *EnhancedMap[K, V]) MustGet(k K) (v V)
MustGet retrieves the value associated with the specified key from the map. It returns the value if the key is found; otherwise, it panics.
func (*EnhancedMap[K, V]) Put ¶
func (m *EnhancedMap[K, V]) Put(k K, v V)
Put inserts a key-value pair into the map.
func (*EnhancedMap[K, V]) PutAll ¶
func (m *EnhancedMap[K, V]) PutAll(pairs []*Pair[K, V])
PutAll put by raw map
func (*EnhancedMap[K, V]) Remove ¶
func (m *EnhancedMap[K, V]) Remove(k K)
Remove removes the key-value pair associated with the specified key from the map.
func (*EnhancedMap[K, V]) Size ¶
func (m *EnhancedMap[K, V]) Size() int
Size returns the number of key-value pairs in the map.
func (*EnhancedMap[K, V]) ToJSON ¶ added in v0.1.2
func (m *EnhancedMap[K, V]) ToJSON() ([]byte, error)
ToJSON outputs the JSON representation of the map.
func (*EnhancedMap[K, V]) UnmarshalJSON ¶ added in v0.1.2
func (m *EnhancedMap[K, V]) UnmarshalJSON(bytes []byte) error
UnmarshalJSON @implements json.Unmarshaler
func (*EnhancedMap[K, V]) Values ¶
func (m *EnhancedMap[K, V]) Values() []V
Values returns a slice containing all the values in the map.
type HashMap ¶
HashMap Based on red and black trees The key of a hashMap is based on a red-black tree at the underlying level and must be comparable. If the key is a primitive type, it will be compared according to the primitive type. If it is a struct and implements the collection.Comparable[K] interface, it will be compared according to the rules of the interface. If it does not implement the interface but a CompareFunc is provided, the comparison will follow this function. If neither is implemented, the struct's memory address or MD5 value will be used for sorting.
type IMap ¶
type IMap[K comparable, V any] interface { collection.JSONSerializer collection.JSONDeserializer // Put inserts a key-value pair into the map. Put(k K, v V) PutAll(pairs []*Pair[K, V]) // Get retrieves the value associated with the specified key from the map. // It returns the value and true if the key is found; otherwise, it returns the zero value of V and false. Get(k K) (v V, ok bool) // MustGet retrieves the value associated with the specified key from the map. // It returns the value if the key is found; otherwise, it panics. MustGet(k K) (v V) // GetOrDefault retrieves the value associated with the specified key from the map. // It returns the value if the key is found; otherwise, it returns the defaultValue. GetOrDefault(k K, defaultValue V) (v V) // Remove removes the key-value pair associated with the specified key from the map. Remove(k K) // KeySet returns a slice containing all the keys in the map. KeySet() []K // Values returns a slice containing all the values in the map. Values() []V // Size returns the number of key-value pairs in the map. Size() int IsEmpty() bool // ForEach applies the specified function to each key-value pair in the map. ForEach(f func(k K, v V)) // ContainsKey checks if the map contains the specified key. // It returns true if the key is found; otherwise, it returns false. ContainsKey(k K) bool // ContainsValue checks if the map contains the specified value. // It returns true if the value is found; otherwise, it returns false. ContainsValue(value V) bool // Clear removes all elements from the map. Clear() }
IMap represents a generic map interface with keys of type K and values of type V. @see TreeMap @see EnhancedMap enhance golang map @see LinkedHashMap @see SynchronizedMap thread-safe map @since v1.0.0 @author eureka
func NewConcurrentHashMap ¶ added in v0.1.3
func NewConcurrentHashMap[K comparable, V any]() IMap[K, V]
NewConcurrentHashMap creates a new thread-safe hash map. It returns an implementation of the IMap interface using a SynchronizedMap that wraps a NewEnhancedMap.
func NewConcurrentHashMapWithExpectedSize ¶ added in v0.1.3
func NewConcurrentHashMapWithExpectedSize[K comparable, V any](expectedSize int) IMap[K, V]
NewConcurrentHashMapWithExpectedSize creates a new thread-safe hash map with an expected size. It returns an implementation of the IMap interface using a SynchronizedMap that wraps a NewEnhancedMapWithExpectedSize.
func NewConcurrentLinkedHashMap ¶ added in v0.1.3
func NewConcurrentLinkedHashMap[K comparable, V any]() IMap[K, V]
NewConcurrentLinkedHashMap creates a new thread-safe linked hash map. It returns an implementation of the IMap interface using a SynchronizedMap that wraps a NewLinkedHashMap.
func NewConcurrentLinkedHashMapWithExpectedSize ¶ added in v0.1.3
func NewConcurrentLinkedHashMapWithExpectedSize[K comparable, V any](expectedSize int) IMap[K, V]
NewConcurrentLinkedHashMapWithExpectedSize creates a new thread-safe linked hash map with an expected size. It returns an implementation of the IMap interface using a SynchronizedMap that wraps a NewLinkedHashMapWithExpectedSize.
func NewEnhancedMap ¶
func NewEnhancedMap[K comparable, V any]() IMap[K, V]
NewEnhancedMap creates and returns a new instance of the EnhancedMap.
func NewEnhancedMapWithExpectedSize ¶ added in v0.1.2
func NewEnhancedMapWithExpectedSize[K comparable, V any](expectedSize int) IMap[K, V]
NewEnhancedMapWithExpectedSize creates and returns a new instance of the EnhancedMap.
func NewHashMap ¶ added in v0.1.3
func NewHashMap[K comparable, V any]() IMap[K, V]
NewHashMap creates a new instance of a basic hash map. It returns an implementation of the IMap interface using NewEnhancedMap.
func NewHashMapWithExpectedSize ¶ added in v0.1.3
func NewHashMapWithExpectedSize[K comparable, V any](expectedSize int) IMap[K, V]
NewHashMapWithExpectedSize creates a new instance of a hash map with an expected size. It returns an implementation of the IMap interface using NewEnhancedMapWithExpectedSize.
func NewLinkedHashMap ¶
func NewLinkedHashMap[K comparable, V any]() IMap[K, V]
func NewLinkedHashMapWithExpectedSize ¶ added in v0.1.3
func NewLinkedHashMapWithExpectedSize[K comparable, V any](expectedSize int) IMap[K, V]
func NewSynchronizedMap ¶ added in v0.1.3
func NewSynchronizedMap[K comparable, V any](rawMap IMap[K, V]) IMap[K, V]
NewSynchronizedMap creates a new SynchronizedMap
func NewTreeMap ¶
func NewTreeMap[K comparable, V any]() IMap[K, V]
func NewTreeMapWithComparator ¶
func NewTreeMapWithComparator[K comparable, V any](comparator collection.CompareFunc[K]) IMap[K, V]
type LinkedHashMap ¶
type LinkedHashMap[K comparable, V any] struct { // contains filtered or unexported fields }
func (*LinkedHashMap[K, V]) Clear ¶ added in v0.1.2
func (m *LinkedHashMap[K, V]) Clear()
func (*LinkedHashMap) ContainsKey ¶
func (m *LinkedHashMap) ContainsKey(k K) bool
func (*LinkedHashMap) ContainsValue ¶
func (m *LinkedHashMap) ContainsValue(value V) bool
func (*LinkedHashMap[K, V]) ForEach ¶
func (m *LinkedHashMap[K, V]) ForEach(f func(K, V))
func (*LinkedHashMap[K, V]) FromJSON ¶ added in v0.1.2
func (m *LinkedHashMap[K, V]) FromJSON(data []byte) error
func (*LinkedHashMap[K, V]) GetOrDefault ¶
func (m *LinkedHashMap[K, V]) GetOrDefault(k K, defaultValue V) (v V)
func (*LinkedHashMap[K, V]) KeySet ¶
func (m *LinkedHashMap[K, V]) KeySet() []K
func (*LinkedHashMap[K, V]) MarshalJSON ¶ added in v0.1.2
func (m *LinkedHashMap[K, V]) MarshalJSON() ([]byte, error)
func (*LinkedHashMap[K, V]) Put ¶
func (m *LinkedHashMap[K, V]) Put(k K, v V)
func (*LinkedHashMap[K, V]) PutAll ¶
func (m *LinkedHashMap[K, V]) PutAll(pairs []*Pair[K, V])
func (*LinkedHashMap[K, V]) ToJSON ¶ added in v0.1.2
func (m *LinkedHashMap[K, V]) ToJSON() ([]byte, error)
ToJSON outputs the JSON representation of map.
func (*LinkedHashMap[K, V]) UnmarshalJSON ¶ added in v0.1.2
func (m *LinkedHashMap[K, V]) UnmarshalJSON(bytes []byte) error
UnmarshalJSON @implements json.Unmarshaler
func (*LinkedHashMap[K, V]) Values ¶
func (m *LinkedHashMap[K, V]) Values() []V
type SynchronizedMap ¶ added in v0.1.3
type SynchronizedMap[K comparable, V any] struct { // contains filtered or unexported fields }
SynchronizedMap is a thread-safe map
func (*SynchronizedMap[K, V]) Clear ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) Clear()
Clear removes all key-value pairs from the map
func (*SynchronizedMap[K, V]) ContainsKey ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) ContainsKey(k K) bool
ContainsKey checks if the map contains the given key
func (*SynchronizedMap[K, V]) ContainsValue ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) ContainsValue(value V) bool
ContainsValue checks if the map contains the given value
func (*SynchronizedMap[K, V]) ForEach ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) ForEach(f func(k K, v V))
ForEach applies a function to each key-value pair in the map
func (*SynchronizedMap[K, V]) FromJSON ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) FromJSON(data []byte) (err error)
FromJSON populates the map from the input JSON representation.
func (*SynchronizedMap[K, V]) Get ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) Get(k K) (v V, ok bool)
Get retrieves the value associated with the key
func (*SynchronizedMap[K, V]) GetOrDefault ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) GetOrDefault(k K, defaultValue V) (v V)
GetOrDefault retrieves the value associated with the key, or returns defaultValue if not found
func (*SynchronizedMap[K, V]) IsEmpty ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) IsEmpty() bool
IsEmpty checks if the map is empty
func (*SynchronizedMap[K, V]) KeySet ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) KeySet() []K
KeySet returns a slice of all keys in the map
func (*SynchronizedMap[K, V]) MarshalJSON ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) MarshalJSON() ([]byte, error)
MarshalJSON @implements json.Marshaler
func (*SynchronizedMap[K, V]) MustGet ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) MustGet(k K) (v V)
MustGet retrieves the value associated with the key, panics if not found
func (*SynchronizedMap[K, V]) Put ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) Put(k K, v V)
Put adds a key-value pair to the map
func (*SynchronizedMap[K, V]) PutAll ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) PutAll(pairs []*Pair[K, V])
PutAll adds multiple key-value pairs to the map
func (*SynchronizedMap[K, V]) Remove ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) Remove(k K)
Remove removes the key-value pair from the map
func (*SynchronizedMap[K, V]) Size ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) Size() int
Size returns the number of key-value pairs in the map
func (*SynchronizedMap[K, V]) ToJSON ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) ToJSON() ([]byte, error)
ToJSON outputs the JSON representation of the map.
func (*SynchronizedMap[K, V]) UnmarshalJSON ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) UnmarshalJSON(bytes []byte) error
UnmarshalJSON @implements json.Unmarshaler
func (*SynchronizedMap[K, V]) Values ¶ added in v0.1.3
func (s *SynchronizedMap[K, V]) Values() []V
Values returns a slice of all values in the map
type TreeMap ¶
type TreeMap[K comparable, V any] struct { // contains filtered or unexported fields }
TreeMap A Red-Black tree based NavigableMap implementation. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.
func (TreeMap[K, V]) ContainsKey ¶
func (TreeMap[K, V]) ContainsValue ¶
func (TreeMap[K, V]) GetOrDefault ¶
func (t TreeMap[K, V]) GetOrDefault(k K, defaultValue V) (v V)