xmap

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNilComparator = errors.New("[jit] comparator can not be nil")

Functions

func Keys

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

Keys return a slice of the keys in the map.

func Merge

func Merge[K comparable, V any](maps ...map[K]V) map[K]V

func MergeFunc

func MergeFunc[K comparable, V any](mergeFunc func(_ V, second V) V, maps ...map[K]V) map[K]V

func ToMap

func ToMap[K comparable, V any](keys []K, vals []V) (map[K]V, error)

ToMap converts a slice of keys and a slice of values to a map.

func Vals

func Vals[K comparable, V any](m map[K]V) []V

Vals returns a slice of the values in the map.

Types

type HashMap

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

func NewHashMap

func NewHashMap[K Hashable, V any](size int) *HashMap[K, V]

func (*HashMap[K, V]) Del

func (h *HashMap[K, V]) Del(key K) (V, bool)

func (*HashMap[K, V]) Get

func (h *HashMap[K, V]) Get(key K) (V, bool)

func (*HashMap[K, V]) Iter

func (h *HashMap[K, V]) Iter(visitFunc func(key K, val V) bool)

func (*HashMap[K, V]) Keys

func (h *HashMap[K, V]) Keys() []K

func (*HashMap[K, V]) Put

func (h *HashMap[K, V]) Put(key K, val V) error

func (*HashMap[K, V]) Size

func (h *HashMap[K, V]) Size() int64

func (*HashMap[K, V]) Vals

func (h *HashMap[K, V]) Vals() []V

type Hashable

type Hashable interface {
	Hash() uint64
	Equals(key any) bool
}

type MapKV

type MapKV[K comparable, V any] struct {
	Key K
	Val V
}

MapKV is a key-value pair of a map.

func KeysVals

func KeysVals[K comparable, V any](m map[K]V) []MapKV[K, V]

KeysVals returns a slice of the key-value pairs in the map.

type MultiMap

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

func NewMultiHashMap

func NewMultiHashMap[K Hashable, V any](size int) (*MultiMap[K, V], error)

func NewMultiTreeMap

func NewMultiTreeMap[K comparable, V any](cmp jit.Comparator[K]) (*MultiMap[K, V], error)

func (*MultiMap[K, V]) Del

func (m *MultiMap[K, V]) Del(key K) ([]V, bool)

func (*MultiMap[K, V]) Get

func (m *MultiMap[K, V]) Get(key K) ([]V, bool)

func (*MultiMap[K, V]) Iter

func (m *MultiMap[K, V]) Iter(visitFunc func(key K, val V) bool)

func (*MultiMap[K, V]) Keys

func (m *MultiMap[K, V]) Keys() []K

func (*MultiMap[K, V]) Put

func (m *MultiMap[K, V]) Put(key K, val V) error

func (*MultiMap[K, V]) PuyMany

func (m *MultiMap[K, V]) PuyMany(key K, vals ...V) error

func (*MultiMap[K, V]) Size

func (m *MultiMap[K, V]) Size() int64

func (*MultiMap[K, V]) Vals

func (m *MultiMap[K, V]) Vals() [][]V

type TreeMap

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

TreeMap is a map implemented using a red-black tree.

func NewTreeMap

func NewTreeMap[K any, V any](cmp jit.Comparator[K]) (*TreeMap[K, V], error)

func NewTreeMapWithMap

func NewTreeMapWithMap[K comparable, V any](cmp jit.Comparator[K], m map[K]V) (*TreeMap[K, V], error)

func (*TreeMap[K, V]) Del

func (tm *TreeMap[K, V]) Del(key K) (V, bool)

func (*TreeMap[K, V]) Get

func (tm *TreeMap[K, V]) Get(key K) (V, bool)

func (*TreeMap[K, V]) Iter

func (tm *TreeMap[K, V]) Iter(visitFunc func(key K, val V) bool)

func (*TreeMap[K, V]) KeyVals

func (tm *TreeMap[K, V]) KeyVals() (keys []K, vals []V)

func (*TreeMap[K, V]) Keys

func (tm *TreeMap[K, V]) Keys() []K

func (*TreeMap[K, V]) Put

func (tm *TreeMap[K, V]) Put(key K, val V) error

func (*TreeMap[K, V]) Size

func (tm *TreeMap[K, V]) Size() int64

func (*TreeMap[K, V]) Vals

func (tm *TreeMap[K, V]) Vals() []V

Jump to

Keyboard shortcuts

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