Documentation
¶
Index ¶
- func ComparableKeyX[T comparable](key T) T
- type HMap
- func (hmap *HMap[T, K, V]) Clear()
- func (hmap *HMap[T, K, V]) Clone() Map[K, V]
- func (hmap *HMap[T, K, V]) Copy(src Map[K, V])
- func (hmap *HMap[T, K, V]) Get(k K) (_ V, _ bool)
- func (hmap *HMap[T, K, V]) Keys() []K
- func (hmap *HMap[T, K, V]) Remove(k K)
- func (hmap *HMap[T, K, V]) Set(k K, v V)
- func (hmap *HMap[T, K, V]) Size() int
- func (hmap *HMap[T, K, V]) String() string
- func (hmap *HMap[T, K, V]) Values() []V
- type KeyX
- type Map
- type SMap
- func (hmap *SMap[K, V]) Clear()
- func (hmap *SMap[K, V]) Clone() Map[K, V]
- func (hmap *SMap[K, V]) Copy(src Map[K, V])
- func (hmap *SMap[K, V]) Get(k K) (V, bool)
- func (hmap *SMap[K, V]) Keys() []K
- func (hmap *SMap[K, V]) Remove(k K)
- func (hmap *SMap[K, V]) Set(k K, v V)
- func (hmap *SMap[K, V]) Size() int
- func (hmap *SMap[K, V]) String() string
- func (hmap *SMap[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HMap ¶
type HMap[T comparable, K any, V any] struct { // contains filtered or unexported fields }
HMap is implemented by native go map. due to go map key unsupported generic type, so we need to use two go map to implement it, keysmap store the key, valuesmap store the value, and use a comparable key to related above two maps. In this way, the genericization of key is indirectly achieved, but it requires more memory to maintain one more go map at runtime.
type KeyX ¶
type KeyX[T comparable, K any] func(key K) T
KeyX returns the unique flag of the given key whose type must be comparable
type Map ¶
type Map[K any, V any] interface { // Get returns the value corresponding to the given key Get(k K) (V, bool) // Set sets replace the value corresponding to the given key Set(k K, v V) // Remove removes the key-value pair from the map Remove(k K) // Clone returns a clone of the map Clone() Map[K, V] // Copy copies the src map into the destination map Copy(src Map[K, V]) // Keys returns the all keys of the map Keys() []K containers.Container[V] }
Map is the base interface of all maps implementations
type SMap ¶
type SMap[K comparable, V any] struct { // contains filtered or unexported fields }
SMap is simple hmap, implemented by the native go map, just a simple encapsulation
func NewSimpleMap ¶
func NewSimpleMap[K comparable, V any](capacity int) *SMap[K, V]
Click to show internal directories.
Click to hide internal directories.