sortedmap

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package sortedmap provides a sorted map implementation. It is kindly taken from https://github.com/gobs/sortedmap under the MIT license.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyValuePair

type KeyValuePair[K constraints.Ordered, T any] struct {
	Key   K
	Value T
}

KeyValuePair describes an entry in SortedMap

func (KeyValuePair[K, T]) String

func (e KeyValuePair[K, T]) String() string

String implements the Stringer interface for KeyValuePair

type SortedMap

type SortedMap[K constraints.Ordered, T any] []KeyValuePair[K, T]

SortedMap is a structure that can sort a map[string]type by key

func AsSortedMap

func AsSortedMap[K constraints.Ordered, T any](m map[K]T) SortedMap[K, T]

AsSortedMap return a SortedMap from a map[string]type. Note that this will panic if the input object is not a map

func (SortedMap[K, T]) Add

func (s SortedMap[K, T]) Add(key K, value T) SortedMap[K, T]

Add adds an entry to a SortedMap (this requires re-sorting the SortedMap when ready to display). Note that a SortedMap is internally a slice, so you need to do something like:

s := NewSortedMap()
s = s.Add(key1, value1)
s = s.Add(key2, value2)

func (SortedMap[K, T]) Keys

func (s SortedMap[K, T]) Keys() []K

Keys returns the list of keys for the entries in this SortedMap

func (SortedMap[K, T]) Len

func (s SortedMap[K, T]) Len() int

func (SortedMap[K, T]) Less

func (s SortedMap[K, T]) Less(i, j int) bool

func (SortedMap[K, T]) Sort

func (s SortedMap[K, T]) Sort()

Sort sorts a SortedMap

func (SortedMap[K, T]) Swap

func (s SortedMap[K, T]) Swap(i, j int)

func (SortedMap[K, T]) Values

func (s SortedMap[K, T]) Values() []T

Values returns the list of values for the entries in this SortedMap

Jump to

Keyboard shortcuts

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