Documentation ¶
Overview ¶
Package omap 通过红黑树实现了高效率的有序map。
Keys 与 values 可以是任意类型,但key必须要有支持的less比较 方法。 在通过调用New方法的时候,需要提供该方法。
Index ¶
- type Map
- func (m *Map) Delete(key interface{}) (deleted bool)
- func (m *Map) Do(function func(interface{}, interface{}))
- func (m *Map) Find(key interface{}) (value interface{}, found bool)
- func (m *Map) First() (key, value interface{}, found bool)
- func (m *Map) Insert(key, value interface{}) (inserted bool)
- func (m *Map) Latest() (key, value interface{}, found bool)
- func (m *Map) Len() int
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 ¶
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 (*Map) Delete ¶
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 ¶
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) Insert ¶
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).