treemap

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package treemap implements a tree map to store key-value pairs in sorted key order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmp

type Cmp func(k1, k2 interface{}) int

Cmp represents the compare function for two keys. Return -1 if k1 < k2, 1 if k1 > k2, 0 if k1 == k2.

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map implements a map (backed by a red-black tree) that stores key-value pairs in sorted key order. It supports arbitrary types as keys and values as long as a compare function for keys is provided. Methods of the map are not thread-safe.

func New

func New(cmp Cmp) *Map

New creates a Map with cmp as the compare function.

func (*Map) Get

func (m *Map) Get(key interface{}) (value interface{}, found bool)

Get returns the value associated with key, or nil if key is not found. The second return value found is set to true if key is found, and false otherwise.

func (*Map) Keys

func (m *Map) Keys() []interface{}

Keys returns a copy of all keys in the map in ascending order.

func (*Map) Put

func (m *Map) Put(key interface{}, value interface{})

Put adds a key-value pair to the map. If key exists, the associated value is updated to the new value. Otherwise, a new key-value pair is added.

func (*Map) Size

func (m *Map) Size() int

Size returns the number of key-value pairs in the map.

func (*Map) String

func (m *Map) String() string

String returns a string representation of the map.

func (*Map) Values

func (m *Map) Values() []interface{}

Values returns a copy of all values in the map in ascending key order.

Jump to

Keyboard shortcuts

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