Documentation
¶
Index ¶
- type MapIndexes
- type MapList
- func (m *MapList[V]) Append(value V) int
- func (m *MapList[V]) InsertToEmpty(value V) int
- func (m *MapList[V]) Remove(index int)
- func (m *MapList[V]) Set(index int, value V) (oldValue V, present bool)
- func (m *MapList[V]) UnmarshalJSON(bytes []byte) error
- func (m *MapList[V]) UnmarshalYAML(value *yaml.Node) error
- type SortMap
- func (s *SortMap[K, V]) Clear()
- func (s *SortMap[K, V]) Contains(key K) (present bool)
- func (s *SortMap[K, V]) Get(key K) (value V, present bool)
- func (s *SortMap[K, V]) Indexes() iter.Seq[int]
- func (s *SortMap[K, V]) Keys() iter.Seq[K]
- func (s *SortMap[K, V]) Len() int
- func (s SortMap[K, V]) MarshalJSON() ([]byte, error)
- func (s SortMap[K, V]) MarshalYAML() (interface{}, error)
- func (s *SortMap[K, V]) Range() iter.Seq2[K, V]
- func (s *SortMap[K, V]) RangeWithIndex() iter.Seq2[int, V]
- func (s *SortMap[K, V]) RemoveByKey(key K)
- func (s *SortMap[K, V]) Set(key K, value V) (oldValue V, present bool)
- func (s *SortMap[K, V]) UnmarshalJSON(bytes []byte) error
- func (s *SortMap[K, V]) UnmarshalYAML(value *yaml.Node) error
- func (s *SortMap[K, V]) Values() iter.Seq[V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MapIndexes ¶
type MapIndexes[K cmp.Ordered] interface { Insert(key K) GetKey(idx int) K IndexOf(key K) int Contains(key K) (present bool) Remove(key K) Len() int Keys() iter.Seq[int] Range() iter.Seq2[int, K] }
func NewMapIndexes ¶
func NewMapIndexes[K cmp.Ordered]() MapIndexes[K]
type MapList ¶ added in v1.0.11
MapList is the exported concrete sparse list type. Like SortMap it is exported so that business structs can use it (or a pointer to it) directly as a field type, which is the only way yaml.v3 can dispatch UnmarshalYAML for nested struct fields.
Get/Contains/Len/Clear/Range/Indexes and the value-receiver MarshalJSON/MarshalYAML are inherited from the embedded SortMap; the value receivers are what allow the yaml.v3/json encoders to find the Marshaler on non-addressable value-typed struct fields.
The zero value of MapList is an empty, ready-to-use list; when starting from a zero value, the list must be initialized (write or decode) before it is accessed concurrently.
func (*MapList[V]) InsertToEmpty ¶ added in v1.0.11
func (*MapList[V]) UnmarshalJSON ¶ added in v1.0.15
func (*MapList[V]) UnmarshalYAML ¶ added in v1.0.15
UnmarshalYAML decodes a YAML mapping node (index -> value) or a YAML sequence node (expanded to indexes 0..n-1) into the list. Null/empty nodes reset it to an empty list. The node is decoded exactly once and validated before the container is replaced.
type SortMap ¶
SortMap is the exported concrete ordered-map type. Business structs should use it (or a pointer to it) directly as a field type: yaml.v3 only dispatches UnmarshalYAML on addressable concrete values and never through interface-typed fields, so wrapping these containers behind an interface field cannot work with yaml.v3 (see docs/guide/zh-CN/libs/sort_map.md for details and migration notes).
The zero value of SortMap is an empty, ready-to-use container: its internal state is lazily initialized on the first write or decode. When starting from a zero value, the container must be initialized (write or decode) before it is accessed concurrently.
func (SortMap[K, V]) MarshalJSON ¶ added in v1.0.15
func (SortMap[K, V]) MarshalYAML ¶ added in v1.0.15
MarshalYAML uses a value receiver on purpose: the yaml.v3 encoder does not fall back to Addr() when probing the Marshaler interface, so a pointer-receiver MarshalYAML would be silently skipped for non-addressable value-typed struct fields (rendered as an empty mapping instead). mu is a pointer, so copying the receiver does not copy the lock.
func (*SortMap[K, V]) RemoveByKey ¶
func (s *SortMap[K, V]) RemoveByKey(key K)