gmap

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

Contains functions for sorting generic map[K]V by keys or by values, or using function. It returns []MapItem[K, V].

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone[M ~map[K]V, K comparable, V any](m M) (M, error)

func Copy

func Copy[M ~map[K]V, K comparable, V any](m M) M

func EqualJson

func EqualJson[M1 ~map[K]V, M2 ~map[K]V, K comparable, V comparable](m1 M1, m2 M2) (bool, error)

func From

func From[K comparable, V any](value any) (res map[K]V, err error)

func FromSlice

func FromSlice[T any, K comparable, V any](s []T, f func(i int) (K, V)) (res map[K]V)

func Get

func Get[R any](m any, key string) (R, error)

func GetAny

func GetAny(m any, key string) (any, bool)

func GetAnyOrDefault

func GetAnyOrDefault(m any, key string, default_ any) any

func GetAnyOrDefaultWithSep

func GetAnyOrDefaultWithSep(m any, key string, sep string, default_ any) any

func GetAnyWithSep

func GetAnyWithSep(m any, key string, sep string) (res any, ok bool)

func GetOrDefault

func GetOrDefault[R any](m any, key string, default_ R) R

func GetOrDefaultWithSep

func GetOrDefaultWithSep[R any](m any, key string, sep string, default_ R) R

func GetWithSep

func GetWithSep[R any](m any, key string, sep string) (res R, err error)

func Keys

func Keys[M ~map[K]V, K comparable, V any](m M) []K

func Make

func Make[M ~map[K]V, K comparable, V any](m M, args ...int) M

func MustGet

func MustGet[R any](m any, key string) R

func Print

func Print[M ~map[K]V, K comparable, V any](m M, opts ...PrintOpts) error

func Set

func Set(m any, key string, value any) (nm any, err error)

func SetFloat32

func SetFloat32(m any, key string, value float32) (nm any, err error)

func SetFloat64

func SetFloat64(m any, key string, value float64) (nm any, err error)

func SetInt

func SetInt(m any, key string, value int) (nm any, err error)

func SetInt8

func SetInt8(m any, key string, value int8) (nm any, err error)

func SetInt16

func SetInt16(m any, key string, value int16) (nm any, err error)

func SetInt32

func SetInt32(m any, key string, value int32) (nm any, err error)

func SetInt64

func SetInt64(m any, key string, value int64) (nm any, err error)

func SetString

func SetString(m any, key string, value string) (nm any, err error)

func SetUint

func SetUint(m any, key string, value uint) (nm any, err error)

func SetUint8

func SetUint8(m any, key string, value uint8) (nm any, err error)

func SetUint16

func SetUint16(m any, key string, value uint16) (nm any, err error)

func SetUint32

func SetUint32(m any, key string, value uint32) (nm any, err error)

func SetUint64

func SetUint64(m any, key string, value uint64) (nm any, err error)

func SetWithSep

func SetWithSep(m any, key string, value any, sep string) (nm any, err error)

func Size

func Size[M ~map[K]V, K comparable, V any](m M) (int64, error)

func Sort

func Sort[M ~map[K]V, K comparable, V any](
	m M,
) []gtypes.MapItem[K, V]

Sort function sorts a map by keys

func SortByFunc

func SortByFunc[M ~map[K]V, K comparable, V any](
	m M,
	f func(p1, p2 gtypes.MapItem[K, V]) bool,
) []gtypes.MapItem[K, V]

SortByFunc function sorts a map using a function

func SortByFuncReverse

func SortByFuncReverse[M ~map[K]V, K comparable, V any](
	m M,
	f func(p1, p2 gtypes.MapItem[K, V]) bool,
) []gtypes.MapItem[K, V]

SortByFuncReverse function sorts a map using a function (reverse order)

func SortByKey

func SortByKey[M ~map[K]V, K comparable, V any](
	m M,
) []gtypes.MapItem[K, V]

SortByKey function sorts a map by keys

func SortByKeyReverse

func SortByKeyReverse[M ~map[K]V, K comparable, V any](
	m M,
) []gtypes.MapItem[K, V]

SortByKeyReverse function sorts a map by keys (reverse order)

func SortByValue

func SortByValue[M ~map[K]V, K comparable, V any](
	m M,
) []gtypes.MapItem[K, V]

SortByValue function sorts a map by values

func SortByValueReverse

func SortByValueReverse[M ~map[K]V, K comparable, V any](
	m M,
) []gtypes.MapItem[K, V]

SortByValue function sorts a map by values (reverse order)

func SortReverse

func SortReverse[M ~map[K]V, K comparable, V any](
	m M,
) []gtypes.MapItem[K, V]

SortReverse function sort a map by keys (reverse order)

func Sprint

func Sprint[M ~map[K]V, K comparable, V any](m M, opts ...PrintOpts) string

func TrySprint

func TrySprint[M ~map[K]V, K comparable, V any](m M, opts ...PrintOpts) (string, error)

func Unroll

func Unroll[M ~map[K]V, K comparable, V any](m M) []gtypes.MapItem[string, any]

func Unroll3

func Unroll3[M ~map[K]V, K comparable, V any](m M) []gtypes.MapItem[string, any]

func Values

func Values[M ~map[K]V, K comparable, V any](m M) []V

func Visit

func Visit[M ~map[K]V, K comparable, V any](m M, f func(v any, keys []string))

Types

type PrintOpts

type PrintOpts struct {
	Indent *string
	Prefix *string
}

type SafeMap

type SafeMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*SafeMap[K, V]) Clear

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

func (*SafeMap[K, V]) CompareAndDelete

func (s *SafeMap[K, V]) CompareAndDelete(k K, old V) (deleted bool)

func (*SafeMap[K, V]) CompareAndSwap

func (s *SafeMap[K, V]) CompareAndSwap(k K, old V, new V) (swapped bool)

func (*SafeMap[K, V]) Delete

func (s *SafeMap[K, V]) Delete(k K)

func (*SafeMap[K, V]) Load

func (s *SafeMap[K, V]) Load(k K) (v V, ok bool)

func (*SafeMap[K, V]) LoadAndDelete

func (s *SafeMap[K, V]) LoadAndDelete(k K) (v V, loaded bool)

func (*SafeMap[K, V]) LoadOrStore

func (s *SafeMap[K, V]) LoadOrStore(k K, v V) (r V, loaded bool)

func (*SafeMap[K, V]) Store

func (s *SafeMap[K, V]) Store(k K, v V)

func (*SafeMap[K, V]) Swap

func (s *SafeMap[K, V]) Swap(k K, v V) (old V, loaded bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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