sort_map

package
v1.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

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

type MapList[V any] struct {
	SortMap[int, V]
}

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 List added in v1.0.11

func List[V any]() MapList[V]

func (*MapList[V]) Append added in v1.0.11

func (m *MapList[V]) Append(value V) int

func (*MapList[V]) InsertToEmpty added in v1.0.11

func (m *MapList[V]) InsertToEmpty(value V) int

func (*MapList[V]) Remove added in v1.0.12

func (m *MapList[V]) Remove(index int)

func (*MapList[V]) Set added in v1.0.11

func (m *MapList[V]) Set(index int, value V) (oldValue V, present bool)

func (*MapList[V]) UnmarshalJSON added in v1.0.15

func (m *MapList[V]) UnmarshalJSON(bytes []byte) error

func (*MapList[V]) UnmarshalYAML added in v1.0.15

func (m *MapList[V]) UnmarshalYAML(value *yaml.Node) error

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

type SortMap[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

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 Map

func Map[K cmp.Ordered, V any]() SortMap[K, V]

func (*SortMap[K, V]) Clear added in v1.0.12

func (s *SortMap[K, V]) Clear()

func (*SortMap[K, V]) Contains added in v1.0.12

func (s *SortMap[K, V]) Contains(key K) (present bool)

func (*SortMap[K, V]) Get added in v1.0.11

func (s *SortMap[K, V]) Get(key K) (value V, present bool)

func (*SortMap[K, V]) Indexes

func (s *SortMap[K, V]) Indexes() iter.Seq[int]

func (*SortMap[K, V]) Keys

func (s *SortMap[K, V]) Keys() iter.Seq[K]

func (*SortMap[K, V]) Len added in v1.0.12

func (s *SortMap[K, V]) Len() int

func (SortMap[K, V]) MarshalJSON added in v1.0.15

func (s SortMap[K, V]) MarshalJSON() ([]byte, error)

func (SortMap[K, V]) MarshalYAML added in v1.0.15

func (s SortMap[K, V]) MarshalYAML() (interface{}, error)

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]) Range

func (s *SortMap[K, V]) Range() iter.Seq2[K, V]

func (*SortMap[K, V]) RangeWithIndex

func (s *SortMap[K, V]) RangeWithIndex() iter.Seq2[int, V]

func (*SortMap[K, V]) RemoveByKey

func (s *SortMap[K, V]) RemoveByKey(key K)

func (*SortMap[K, V]) Set added in v1.0.11

func (s *SortMap[K, V]) Set(key K, value V) (oldValue V, present bool)

func (*SortMap[K, V]) UnmarshalJSON added in v1.0.15

func (s *SortMap[K, V]) UnmarshalJSON(bytes []byte) error

func (*SortMap[K, V]) UnmarshalYAML added in v1.0.15

func (s *SortMap[K, V]) UnmarshalYAML(value *yaml.Node) error

func (*SortMap[K, V]) Values added in v1.0.12

func (s *SortMap[K, V]) Values() iter.Seq[V]

Jump to

Keyboard shortcuts

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