omap

package
v0.0.0-...-91aa13a Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package omap 通过红黑树实现了高效率的有序map。

Keys 与 values 可以是任意类型,但key必须要有支持的less比较 方法。 在通过调用New方法的时候,需要提供该方法。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

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

Map 是一个key有序map。 The zero value is an invalid map! 通过包中提供的构造函数,比如New()等,创建特殊“键-值”类别的map。

func New

func New(less func(interface{}, interface{}) bool) *Map

New 返回一个空的有序Map,其比较函数func(interface{}, interface{}) bool,需要用户自己识别。 比如:

type Point { X, Y int }
pointMap := omap.New(func(a, b interface{}) bool {
        α, β := a.(Point), b.(Point)
        if α.X != β.X {
            return α.X < β.X
        }
        return α.Y < β.Y
    })

func NewCaseFoldedKeyed

func NewCaseFoldedKeyed() *Map

NewCaseFoldedKeyed 返回一个初始化完成的空有序Map,其key是大小写不敏感的string。

func NewFloat64Keyed

func NewFloat64Keyed() *Map

NewFloat64Keyed 返回一个初始化的空有序Map,其key按照按照float64类型识别。

func NewInt64Keyed

func NewInt64Keyed() *Map

NewInt64Keyed 返回一个初始化的空有序Map,其key按照int64类型识别。

func NewIntKeyed

func NewIntKeyed() *Map

NewIntKeyed 返回一个初始化的空有序Map,其key按照int类型识别。

func NewStringKeyed

func NewStringKeyed() *Map

NewStringKeyed 返回一个初始化完成的空有序Map,其key是大小写敏感的string。

func (*Map) Delete

func (m *Map) Delete(key interface{}) (deleted bool)

Delete deletes the key-value with the given key from the Map and returns true, or does nothing and returns false if there is no key-value with the given key. For example:

deleted := myMap.Delete(key).

func (*Map) Do

func (m *Map) Do(function func(interface{}, interface{}))

Do 调用给定的func,有序将key-value作为输入参数执行。

func (*Map) Find

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

Find returns the value and true if the key is in the Map or nil and false otherwise. For example:

value, found := myMap.Find(key).

func (*Map) First

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

First 返回有序Map中,最左上角叶子节点的KV组。

func (*Map) Insert

func (m *Map) Insert(key, value interface{}) (inserted bool)

Insert inserts a new key-value into the Map and returns true; or replaces an existing key-value pair's value if the keys are equal and returns false. For example:

inserted := myMap.Insert(key, value).

func (*Map) Latest

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

Latest 返回有序Map中,最右上角叶子节点的KV组。

func (*Map) Len

func (m *Map) Len() int

Len 返回map中的键值对数量

Jump to

Keyboard shortcuts

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